From 368fdac2427984cc613c65b23d8110388ad6290c Mon Sep 17 00:00:00 2001 From: mahmood19227 Date: Sat, 13 May 2023 16:26:47 +0330 Subject: [PATCH] In the middle of adding configuration ds --- CSharp/BasicInputs/CMudProperties.f90 | 237 -- .../BasicInputs/CMudPropertiesVariables.f90 | 82 +- CSharp/Common/CCommon.f90 | 57 +- CSharp/Common/CCommonVariables.f90 | 5 +- .../EventHandlers/CBoolEventHandler.f90 | 44 - .../CBoolEventHandlerCollection.f90 | 103 - .../EventHandlers/CDoubleEventHandler.f90 | 43 - .../CDoubleEventHandlerCollection.f90 | 103 - .../CIntegerArrayEventHandler.f90 | 44 - .../CIntegerArrayEventHandlerCollection.f90 | 103 - .../EventHandlers/CIntegerEventHandler.f90 | 44 - .../CIntegerEventHandlerCollection.f90 | 103 - .../EventHandlers/CRealEventHandler.f90 | 44 - .../CRealEventHandlerCollection.f90 | 103 - .../EventHandlers/CVoidEventHandler.f90 | 44 - .../CVoidEventHandlerCollection.f90 | 102 - CSharp/DownHole/CDownHoleVariables.f90 | 3 + .../CDataDisplayConsoleVariables.f90 | 6 +- .../CDrillingConsoleVariables.f90 | 12 +- .../ControlPanels/CHookVariables.f90 | 6 +- .../Equipments/MudPathFinding/CManifolds.f90 | 16 +- .../Common/COperationScenariosVariables.f90 | 8 +- .../CElevatorConnectionEnumVariables.f90 | 2 +- .../Enums/CKellyConnectionEnumVariables.f90 | 6 +- .../CTdsConnectionModesEnumVariables.f90 | 6 +- .../Enums/CTdsElevatorModesEnumVariables.f90 | 6 +- .../Notifications/CTongNotification.f90 | 22 +- .../Notifications/CUnlatchLedNotification.f90 | 29 +- .../Notifications/NotificationVariables.f90 | 66 +- .../Permissions/PermissionsVariables.f90 | 42 +- .../SoftwareInputsVariables.f90 | 38 +- .../CStringUpdateVariables.f90 | 2 +- .../OperationScenarios/Unity/CUnityInputs.f90 | 34 +- .../Unity/CUnityOutputs.f90 | 2 +- .../UnitySignals/CBucketEnumVariables.f90 | 4 +- .../UnitySignals/CElevatorEnumVariables.f90 | 4 +- .../CFlowKellyDisconnectEnumVariables.f90 | 4 +- .../CFlowPipeDisconnectEnumVariables.f90 | 4 +- .../UnitySignals/CHeadEnumVariables.f90 | 4 +- .../UnitySignals/CIbopEnumVariables.f90 | 4 +- .../UnitySignals/CKellyEnumVariables.f90 | 4 +- .../UnitySignals/CMouseHoleEnumVariables.f90 | 4 +- .../COperationConditionEnumVariables.f90 | 6 +- .../CSafetyValveEnumVariables.f90 | 4 +- .../UnitySignals/CSlipsEnumVariables.f90 | 4 +- .../UnitySignals/CSwingEnumVariables.f90 | 4 +- .../UnitySignals/CTdsBackupClampVariables.f90 | 4 +- .../UnitySignals/CTdsSpineEnumVariables.f90 | 4 +- .../UnitySignals/CTdsSwingEnumVariables.f90 | 4 +- .../UnitySignals/CTdsTongEnumVariables.f90 | 4 +- .../UnitySignals/CTongEnumVariables.f90 | 4 +- .../UnitySignals/UnitySignalsVariables.f90 | 68 +- CSharp/Problems/CBitProblemsVariables.f90 | 12 +- CSharp/Problems/CChokeProblemsVariables.f90 | 24 +- CSharp/Problems/CGaugesProblemsVariables.f90 | 12 +- .../CStudentStationVariables.f90 | 10 +- CSimulationVariables.f90 | 1211 ------ Equipments/BopStack/ANNULAR.f90 | 8 +- Equipments/ChokeControl/ChokeStartup.f90 | 11 - .../MudSystem-old/Circulation_Code_Select.f90 | 148 + .../Deallocate_Normal_Circulation.f90 | 186 + .../MudSystem-old/Disconnecting_Pipe.f90 | 108 + .../MudSystem-old/Elements_Creation.f90 | 274 ++ .../FillingWell_By_BellNipple.f90 | 215 ++ .../Kick_Expansion_and_Contraction.f90 | 234 ++ Equipments/MudSystem-old/Kick_Influx.f90 | 215 ++ Equipments/MudSystem-old/Kick_Migration.f90 | 1176 ++++++ Equipments/MudSystem-old/MudSystem.f90 | 3295 +++++++++++++++++ Equipments/MudSystem-old/MudSystemMain.f90 | 85 + Equipments/MudSystem-old/MudSystemStartup.f90 | 501 +++ .../MudSystem-old/MudSystem_Variables.f90 | 193 + .../MudSystem-old/Plot_Final_Mud_Elements.f90 | 410 ++ Equipments/MudSystem-old/Pump_and_Trip_In.f90 | 1627 ++++++++ Equipments/MudSystem-old/Trip_Out_andPump.f90 | 1364 +++++++ .../MudSystem-old/Utube1_and_Trip_In.f90 | 532 +++ .../MudSystem-old/Utube2_and_Trip_In.f90 | 517 +++ .../MudSystem/Circulation_Code_Select.f90 | 13 +- Equipments/MudSystem/Disconnecting_Pipe.f90 | 2 +- Equipments/MudSystem/Elements_Creation.f90 | 4 +- .../MudSystem/FillingWell_By_BellNipple.f90 | 2 +- .../Kick_Expansion_and_Contraction.f90 | 4 +- Equipments/MudSystem/Kick_Influx.f90 | 16 +- Equipments/MudSystem/Kick_Migration.f90 | 6 +- Equipments/MudSystem/MudSystem.f90 | 83 +- Equipments/MudSystem/MudSystemStartup.f90 | 8 +- .../MudSystem/Plot_Final_Mud_Elements.f90 | 10 +- Equipments/MudSystem/Pump_and_Trip_In.f90 | 12 +- Equipments/MudSystem/Trip_Out_andPump.f90 | 4 +- Equipments/MudSystem/Utube1_and_Trip_In.f90 | 8 +- Equipments/MudSystem/Utube2_and_Trip_In.f90 | 10 +- FluidFlow-old/Annulus_Property_Calculator.f90 | 45 + ...lus_and_Openhole_Pressure_Distribution.f90 | 337 ++ FluidFlow-old/Flow_Startup.f90 | 118 + FluidFlow-old/Flow_Startup_VARIABLES.f90 | 64 + FluidFlow-old/FluidFlowMain.f90 | 147 + FluidFlow-old/Fluid_Flow_Solver.f90 | 58 + FluidFlow-old/Frictional_Press_Drop_Calc.f90 | 230 ++ ...ontal_and_String_Pressure_Distribution.f90 | 799 ++++ FluidFlow-old/Pressure_Display_VARIABLES.f90 | 32 + .../Pressure_Distribution_VARIABLES.f90 | 178 + FluidFlow-old/String_Property_Calculator.f90 | 31 + FluidFlow-old/Utube.f90 | 117 + FluidFlow-old/Well_Pressure_Data_Transfer.f90 | 775 ++++ .../fricpressdropvars.mod | Bin FluidFlow-old/kick/Formation_Information.f90 | 125 + FluidFlow-old/kick/Gas_Kick_Calculator.f90 | 566 +++ FluidFlow-old/kick/Kick_VARIABLES.f90 | 95 + ...lus_and_Openhole_Pressure_Distribution.f90 | 278 ++ FluidFlow/Annulus_Property_Calculator.f90 | 12 +- ...lus_and_Openhole_Pressure_Distribution.f90 | 227 +- FluidFlow/Flow_Startup.f90 | 92 +- FluidFlow/Fluid_Flow_Solver.f90 | 18 +- FluidFlow/Frictional_Press_Drop_Calc.f90 | 6 +- ...ontal_and_String_Pressure_Distribution.f90 | 501 +-- FluidFlow/Pressure_Display_VARIABLES.f90 | 18 +- FluidFlow/Pressure_Distribution_VARIABLES.f90 | 156 +- FluidFlow/String_Property_Calculator.f90 | 6 +- FluidFlow/Utube.f90 | 83 +- FluidFlow/Well_Pressure_Data_Transfer.f90 | 365 +- FluidFlow/kick/Formation_Information.f90 | 73 +- FluidFlow/kick/Gas_Kick_Calculator.f90 | 401 +- FluidFlow/kick/Kick_VARIABLES.f90 | 144 +- Rop/ROP_MainCalculation.f90 | 6 +- SimulationCore2.vfproj | 14 - TorqueDrag/TD_MainCalculations.f90 | 2 +- .../TD_MudPropertiesReadData.f90 | 2 +- 126 files changed, 16368 insertions(+), 4008 deletions(-) delete mode 100644 CSharp/BasicInputs/CMudProperties.f90 delete mode 100644 CSharp/Common/EventHandlers/CBoolEventHandler.f90 delete mode 100644 CSharp/Common/EventHandlers/CBoolEventHandlerCollection.f90 delete mode 100644 CSharp/Common/EventHandlers/CDoubleEventHandler.f90 delete mode 100644 CSharp/Common/EventHandlers/CDoubleEventHandlerCollection.f90 delete mode 100644 CSharp/Common/EventHandlers/CIntegerArrayEventHandler.f90 delete mode 100644 CSharp/Common/EventHandlers/CIntegerArrayEventHandlerCollection.f90 delete mode 100644 CSharp/Common/EventHandlers/CIntegerEventHandler.f90 delete mode 100644 CSharp/Common/EventHandlers/CIntegerEventHandlerCollection.f90 delete mode 100644 CSharp/Common/EventHandlers/CRealEventHandler.f90 delete mode 100644 CSharp/Common/EventHandlers/CRealEventHandlerCollection.f90 delete mode 100644 CSharp/Common/EventHandlers/CVoidEventHandler.f90 delete mode 100644 CSharp/Common/EventHandlers/CVoidEventHandlerCollection.f90 delete mode 100644 CSimulationVariables.f90 create mode 100644 Equipments/MudSystem-old/Circulation_Code_Select.f90 create mode 100644 Equipments/MudSystem-old/Deallocate_Normal_Circulation.f90 create mode 100644 Equipments/MudSystem-old/Disconnecting_Pipe.f90 create mode 100644 Equipments/MudSystem-old/Elements_Creation.f90 create mode 100644 Equipments/MudSystem-old/FillingWell_By_BellNipple.f90 create mode 100644 Equipments/MudSystem-old/Kick_Expansion_and_Contraction.f90 create mode 100644 Equipments/MudSystem-old/Kick_Influx.f90 create mode 100644 Equipments/MudSystem-old/Kick_Migration.f90 create mode 100644 Equipments/MudSystem-old/MudSystem.f90 create mode 100644 Equipments/MudSystem-old/MudSystemMain.f90 create mode 100644 Equipments/MudSystem-old/MudSystemStartup.f90 create mode 100644 Equipments/MudSystem-old/MudSystem_Variables.f90 create mode 100644 Equipments/MudSystem-old/Plot_Final_Mud_Elements.f90 create mode 100644 Equipments/MudSystem-old/Pump_and_Trip_In.f90 create mode 100644 Equipments/MudSystem-old/Trip_Out_andPump.f90 create mode 100644 Equipments/MudSystem-old/Utube1_and_Trip_In.f90 create mode 100644 Equipments/MudSystem-old/Utube2_and_Trip_In.f90 create mode 100644 FluidFlow-old/Annulus_Property_Calculator.f90 create mode 100644 FluidFlow-old/Annulus_and_Openhole_Pressure_Distribution.f90 create mode 100644 FluidFlow-old/Flow_Startup.f90 create mode 100644 FluidFlow-old/Flow_Startup_VARIABLES.f90 create mode 100644 FluidFlow-old/FluidFlowMain.f90 create mode 100644 FluidFlow-old/Fluid_Flow_Solver.f90 create mode 100644 FluidFlow-old/Frictional_Press_Drop_Calc.f90 create mode 100644 FluidFlow-old/Horizontal_and_String_Pressure_Distribution.f90 create mode 100644 FluidFlow-old/Pressure_Display_VARIABLES.f90 create mode 100644 FluidFlow-old/Pressure_Distribution_VARIABLES.f90 create mode 100644 FluidFlow-old/String_Property_Calculator.f90 create mode 100644 FluidFlow-old/Utube.f90 create mode 100644 FluidFlow-old/Well_Pressure_Data_Transfer.f90 rename {FluidFlow => FluidFlow-old}/fricpressdropvars.mod (100%) create mode 100644 FluidFlow-old/kick/Formation_Information.f90 create mode 100644 FluidFlow-old/kick/Gas_Kick_Calculator.f90 create mode 100644 FluidFlow-old/kick/Kick_VARIABLES.f90 create mode 100644 FluidFlow-sh/Annulus_and_Openhole_Pressure_Distribution.f90 diff --git a/CSharp/BasicInputs/CMudProperties.f90 b/CSharp/BasicInputs/CMudProperties.f90 deleted file mode 100644 index 10b2cc5..0000000 --- a/CSharp/BasicInputs/CMudProperties.f90 +++ /dev/null @@ -1,237 +0,0 @@ -module CMudProperties - use CMudPropertiesVariables - use CLog4 - implicit none - public - contains - subroutine SetActiveMudType(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveMudType - !DEC$ ATTRIBUTES ALIAS: 'SetActiveMudType' :: SetActiveMudType - implicit none - integer, intent(in) :: v - MudProperties%ActiveMudType = v - end subroutine - - subroutine SetActiveRheologyModel(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveRheologyModel - !DEC$ ATTRIBUTES ALIAS: 'SetActiveRheologyModel' :: SetActiveRheologyModel - implicit none - integer, intent(in) :: v - MudProperties%ActiveRheologyModel = v -#ifdef deb - call Log_4( '=====ActiveRheologyModel=', MudProperties%ActiveRheologyModel) -#endif - end subroutine - - subroutine SetActiveMudVolume(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveMudVolume - !DEC$ ATTRIBUTES ALIAS: 'SetActiveMudVolume' :: SetActiveMudVolume - implicit none - real*8, intent(in) :: v - MudProperties%ActiveMudVolume = v - !call Log_5('ActiveDensity=', ActiveDensity) -#ifdef deb - print*, 'ActiveMudVolume=', MudProperties%ActiveMudVolume -#endif - MudProperties%ActiveMudVolumeGal = v * 42.0 - call OnActiveMudVolumeChange%RunAll(v * 42.0d0) - end subroutine - - subroutine SetActiveDensity(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveDensity - !DEC$ ATTRIBUTES ALIAS: 'SetActiveDensity' :: SetActiveDensity - implicit none - real*8, intent(in) :: v - MudProperties%ActiveDensity = v - !call Log_5('ActiveDensity=', ActiveDensity) -#ifdef deb - print*, 'ActiveDensity=', MudProperties%ActiveDensity -#endif - call OnActiveDensityChange%RunAll(v) - end subroutine - - subroutine SetActiveThetaThreeHundred(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveThetaThreeHundred - !DEC$ ATTRIBUTES ALIAS: 'SetActiveThetaThreeHundred' :: SetActiveThetaThreeHundred - implicit none - real*8, intent(in) :: v - MudProperties%ActiveThetaThreeHundred = v - end subroutine - - subroutine SetActiveThetaSixHundred(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveThetaSixHundred - !DEC$ ATTRIBUTES ALIAS: 'SetActiveThetaSixHundred' :: SetActiveThetaSixHundred - implicit none - real*8, intent(in) :: v - MudProperties%ActiveThetaSixHundred = v - end subroutine - - - subroutine SetReserveMudType(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetReserveMudType - !DEC$ ATTRIBUTES ALIAS: 'SetReserveMudType' :: SetReserveMudType - implicit none - integer, intent(in) :: v - MudProperties%ReserveMudType = v - end subroutine - - subroutine SetReserveMudVolume(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetReserveMudVolume - !DEC$ ATTRIBUTES ALIAS: 'SetReserveMudVolume' :: SetReserveMudVolume - implicit none - real*8, intent(in) :: v - MudProperties%ReserveMudVolume = v - !call Log_5('ReserveMudVolume=', ReserveMudVolume) -#ifdef deb - print*, 'ReserveMudVolume=', MudProperties%ReserveMudVolume -#endif - - MudProperties%ReserveMudVolumeGal = v * 42.0 - call OnReserveMudVolumeChange%RunAll(v * 42.0d0) - end subroutine - - subroutine SetReserveDensity(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetReserveDensity - !DEC$ ATTRIBUTES ALIAS: 'SetReserveDensity' :: SetReserveDensity - implicit none - real*8, intent(in) :: v - MudProperties%ReserveDensity = v - !call Log_5('ReserveDensity=', ReserveDensity) -#ifdef deb - print*, 'ReserveDensity=', MudProperties%ReserveDensity -#endif - call OnReserveDensityChange%RunAll(v) - end subroutine - - subroutine SetReserveThetaThreeHundred(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetReserveThetaThreeHundred - !DEC$ ATTRIBUTES ALIAS: 'SetReserveThetaThreeHundred' :: SetReserveThetaThreeHundred - implicit none - real*8, intent(in) :: v - MudProperties%ReserveThetaThreeHundred = v - end subroutine - - subroutine SetReserveThetaSixHundred(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetReserveThetaSixHundred - !DEC$ ATTRIBUTES ALIAS: 'SetReserveThetaSixHundred' :: SetReserveThetaSixHundred - implicit none - real*8, intent(in) :: v - MudProperties%ReserveThetaSixHundred = v - end subroutine - - - subroutine SetActiveTotalTankCapacity(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveTotalTankCapacity - !DEC$ ATTRIBUTES ALIAS: 'SetActiveTotalTankCapacity' :: SetActiveTotalTankCapacity - implicit none - real*8, intent(in) :: v - MudProperties%ActiveTotalTankCapacity = v - MudProperties%ActiveTotalTankCapacityGal = v * 42.0 -#ifdef deb - print*, 'ActiveTotalTankCapacity=', MudProperties%ActiveTotalTankCapacity -#endif - end subroutine - - subroutine SetActiveSettledContents(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveSettledContents - !DEC$ ATTRIBUTES ALIAS: 'SetActiveSettledContents' :: SetActiveSettledContents - implicit none - real*8, intent(in) :: v - MudProperties%ActiveSettledContents = v - MudProperties%ActiveSettledContentsGal = v * 42.0 -#ifdef deb - print*, 'ActiveSettledContents=', MudProperties%ActiveSettledContents -#endif - end subroutine - - subroutine SetActiveTotalContents(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveTotalContents - !DEC$ ATTRIBUTES ALIAS: 'SetActiveTotalContents' :: SetActiveTotalContents - implicit none - real*8, intent(in) :: v - MudProperties%ActiveTotalContents = v - MudProperties%ActiveTotalContentsGal = v * 42.0 -#ifdef deb - print*, 'ActiveTotalContents=', MudProperties%ActiveTotalContents -#endif - end subroutine - - subroutine SetActivePlasticViscosity(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActivePlasticViscosity - !DEC$ ATTRIBUTES ALIAS: 'SetActivePlasticViscosity' :: SetActivePlasticViscosity - implicit none - real*8, intent(in) :: v - MudProperties%ActivePlasticViscosity = v -#ifdef deb - print*, 'ActivePlasticViscosity=', MudProperties%ActivePlasticViscosity -#endif - end subroutine - - subroutine SetActiveYieldPoint(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveYieldPoint - !DEC$ ATTRIBUTES ALIAS: 'SetActiveYieldPoint' :: SetActiveYieldPoint - implicit none - real*8, intent(in) :: v - MudProperties%ActiveYieldPoint = v -#ifdef deb - print*, 'ActiveYieldPoint=', MudProperties%ActiveYieldPoint -#endif - end subroutine - - subroutine SetActiveAutoDensity(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetActiveAutoDensity - !DEC$ ATTRIBUTES ALIAS: 'SetActiveAutoDensity' :: SetActiveAutoDensity - implicit none - logical, intent(in) :: v - MudProperties%ActiveAutoDensity = v -#ifdef deb - print*, 'ActiveAutoDensity=', MudProperties%ActiveAutoDensity -#endif - end subroutine - - subroutine SetReservePlasticViscosity(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetReservePlasticViscosity - !DEC$ ATTRIBUTES ALIAS: 'SetReservePlasticViscosity' :: SetReservePlasticViscosity - implicit none - real*8, intent(in) :: v - MudProperties%ReservePlasticViscosity = v -#ifdef deb - print*, 'ReservePlasticViscosity=', MudProperties%ReservePlasticViscosity -#endif - end subroutine - - subroutine SetReserveYieldPoint(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetReserveYieldPoint - !DEC$ ATTRIBUTES ALIAS: 'SetReserveYieldPoint' :: SetReserveYieldPoint - implicit none - real*8, intent(in) :: v - MudProperties%ReserveYieldPoint = v -#ifdef deb - print*, 'ReserveYieldPoint=', MudProperties%ReserveYieldPoint -#endif - end subroutine - - subroutine SetInitialTripTankMudVolume(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetInitialTripTankMudVolume - !DEC$ ATTRIBUTES ALIAS: 'SetInitialTripTankMudVolume' :: SetInitialTripTankMudVolume - implicit none - real*8, intent(in) :: v - MudProperties%InitialTripTankMudVolume = v - MudProperties%InitialTripTankMudVolumeGal = v * 42.0 -#ifdef deb - print*, 'InitialTripTankMudVolume=', MudProperties%InitialTripTankMudVolume -#endif - end subroutine - - subroutine SetPedalFlowMeter(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetPedalFlowMeter - !DEC$ ATTRIBUTES ALIAS: 'SetPedalFlowMeter' :: SetPedalFlowMeter - implicit none - real*8, intent(in) :: v - MudProperties%PedalFlowMeter = v -#ifdef deb - print*, 'PedalFlowMeter=', MudProperties%PedalFlowMeter -#endif - end subroutine - -end module CMudProperties \ No newline at end of file diff --git a/CSharp/BasicInputs/CMudPropertiesVariables.f90 b/CSharp/BasicInputs/CMudPropertiesVariables.f90 index 5605d61..2e13af7 100644 --- a/CSharp/BasicInputs/CMudPropertiesVariables.f90 +++ b/CSharp/BasicInputs/CMudPropertiesVariables.f90 @@ -1,19 +1,19 @@ module CMudPropertiesVariables use CIActionReference - use CDoubleEventHandlerCollection + !**use CDoubleEventHandlerCollection implicit none public !pointers - procedure (ActionDouble), pointer :: ActiveMudVolumePtr - procedure (ActionDouble), pointer :: ActiveDensityPtr - procedure (ActionDouble), pointer :: ReserveMudVolumePtr - procedure (ActionDouble), pointer :: ReserveDensityPtr + ! procedure (ActionDouble), pointer :: ActiveMudVolumePtr + ! procedure (ActionDouble), pointer :: ActiveDensityPtr + ! procedure (ActionDouble), pointer :: ReserveMudVolumePtr + ! procedure (ActionDouble), pointer :: ReserveDensityPtr - type(DoubleEventHandlerCollection) :: OnActiveMudVolumeChange - type(DoubleEventHandlerCollection) :: OnActiveDensityChange - type(DoubleEventHandlerCollection) :: OnReserveMudVolumeChange - type(DoubleEventHandlerCollection) :: OnReserveDensityChange + !**type(DoubleEventHandlerCollection) :: OnActiveMudVolumeChange + !**type(DoubleEventHandlerCollection) :: OnActiveDensityChange + !**type(DoubleEventHandlerCollection) :: OnReserveMudVolumeChange + !**type(DoubleEventHandlerCollection) :: OnReserveDensityChange !constants integer, parameter :: WaterBase_MudType = 0 @@ -73,7 +73,7 @@ module CMudPropertiesVariables if(MudProperties%ActiveMudVolume == v) return #endif MudProperties%ActiveMudVolume = v - if(associated(ActiveMudVolumePtr)) call ActiveMudVolumePtr(MudProperties%ActiveMudVolume) + ! if(associated(ActiveMudVolumePtr)) call ActiveMudVolumePtr(MudProperties%ActiveMudVolume) end subroutine subroutine Set_ActiveDensity_StudentStation(v) @@ -83,7 +83,7 @@ module CMudPropertiesVariables if(MudProperties%ActiveDensity == v) return #endif MudProperties%ActiveDensity = v - if(associated(ActiveDensityPtr)) call ActiveDensityPtr(MudProperties%ActiveDensity) + ! if(associated(ActiveDensityPtr)) call ActiveDensityPtr(MudProperties%ActiveDensity) end subroutine subroutine Set_ReserveMudVolume_StudentStation(v) @@ -93,7 +93,7 @@ module CMudPropertiesVariables if(MudProperties%ReserveMudVolume == v) return #endif MudProperties%ReserveMudVolume = v - if(associated(ReserveMudVolumePtr)) call ReserveMudVolumePtr(MudProperties%ReserveMudVolume) + ! if(associated(ReserveMudVolumePtr)) call ReserveMudVolumePtr(MudProperties%ReserveMudVolume) end subroutine subroutine Set_ReserveDensity_StudentStation(v) @@ -103,41 +103,41 @@ module CMudPropertiesVariables if(MudProperties%ReserveDensity == v) return #endif MudProperties%ReserveDensity = v - if(associated(ReserveDensityPtr)) call ReserveDensityPtr(MudProperties%ReserveDensity) + ! if(associated(ReserveDensityPtr)) call ReserveDensityPtr(MudProperties%ReserveDensity) end subroutine - subroutine SubscribeActiveMudVolume(a) - !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeActiveMudVolume - !DEC$ ATTRIBUTES ALIAS: 'SubscribeActiveMudVolume' :: SubscribeActiveMudVolume - implicit none - procedure (ActionDouble) :: a - ActiveMudVolumePtr => a - end subroutine + ! subroutine SubscribeActiveMudVolume(a) + ! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeActiveMudVolume + ! !DEC$ ATTRIBUTES ALIAS: 'SubscribeActiveMudVolume' :: SubscribeActiveMudVolume + ! implicit none + ! procedure (ActionDouble) :: a + ! ActiveMudVolumePtr => a + ! end subroutine - subroutine SubscribeActiveDensity(a) - !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeActiveDensity - !DEC$ ATTRIBUTES ALIAS: 'SubscribeActiveDensity' :: SubscribeActiveDensity - implicit none - procedure (ActionDouble) :: a - ActiveDensityPtr => a - end subroutine + ! subroutine SubscribeActiveDensity(a) + ! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeActiveDensity + ! !DEC$ ATTRIBUTES ALIAS: 'SubscribeActiveDensity' :: SubscribeActiveDensity + ! implicit none + ! procedure (ActionDouble) :: a + ! ActiveDensityPtr => a + ! end subroutine - subroutine SubscribeReserveMudVolume(a) - !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeReserveMudVolume - !DEC$ ATTRIBUTES ALIAS: 'SubscribeReserveMudVolume' :: SubscribeReserveMudVolume - implicit none - procedure (ActionDouble) :: a - ReserveMudVolumePtr => a - end subroutine + ! subroutine SubscribeReserveMudVolume(a) + ! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeReserveMudVolume + ! !DEC$ ATTRIBUTES ALIAS: 'SubscribeReserveMudVolume' :: SubscribeReserveMudVolume + ! implicit none + ! procedure (ActionDouble) :: a + ! ReserveMudVolumePtr => a + ! end subroutine - subroutine SubscribeReserveDensity(a) - !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeReserveDensity - !DEC$ ATTRIBUTES ALIAS: 'SubscribeReserveDensity' :: SubscribeReserveDensity - implicit none - procedure (ActionDouble) :: a - ReserveDensityPtr => a - end subroutine + ! subroutine SubscribeReserveDensity(a) + ! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeReserveDensity + ! !DEC$ ATTRIBUTES ALIAS: 'SubscribeReserveDensity' :: SubscribeReserveDensity + ! implicit none + ! procedure (ActionDouble) :: a + ! ReserveDensityPtr => a + ! end subroutine end module CMudPropertiesVariables \ No newline at end of file diff --git a/CSharp/Common/CCommon.f90 b/CSharp/Common/CCommon.f90 index 3c29b9d..0743cbc 100644 --- a/CSharp/Common/CCommon.f90 +++ b/CSharp/Common/CCommon.f90 @@ -2,50 +2,47 @@ module CCommon use CCommonVariables implicit none public - contains - + contains ! Input routines subroutine SetStandRack(v) implicit none integer, intent(in) :: v if(Common%StandRack == v) return Common%StandRack = v - call Common%OnStandRackChange%Run(v) -#ifdef deb - print*, 'StandRack=', Common%StandRack -#endif + ! call Common%OnStandRackChange%Run(v) end subroutine + + integer function GetStandRack() + implicit none + GetStandRack = Common%StandRack + end function - subroutine SetStandRack_WN(v) - !DEC$ ATTRIBUTES DLLEXPORT :: SetStandRack_WN - !DEC$ ATTRIBUTES ALIAS: 'SetStandRack_WN' :: SetStandRack_WN - implicit none - integer, intent(in) :: v - call SetStandRack(v) - end subroutine + ! subroutine SetStandRack_WN(v) + ! !DEC$ ATTRIBUTES DLLEXPORT :: SetStandRack_WN + ! !DEC$ ATTRIBUTES ALIAS: 'SetStandRack_WN' :: SetStandRack_WN + ! implicit none + ! integer, intent(in) :: v + ! call SetStandRack(v) + ! end subroutine - ! Output routines - logical function GetDrillWatchOperationMode() - !DEC$ ATTRIBUTES DLLEXPORT :: GetDrillWatchOperationMode - !DEC$ ATTRIBUTES ALIAS: 'GetDrillWatchOperationMode' :: GetDrillWatchOperationMode - implicit none - GetDrillWatchOperationMode = Common%DrillWatchOperationMode - end function + ! ! Output routines + ! logical function GetDrillWatchOperationMode() + ! !DEC$ ATTRIBUTES DLLEXPORT :: GetDrillWatchOperationMode + ! !DEC$ ATTRIBUTES ALIAS: 'GetDrillWatchOperationMode' :: GetDrillWatchOperationMode + ! implicit none + ! GetDrillWatchOperationMode = Common%DrillWatchOperationMode + ! end function - integer function GetStandRack() - implicit none - GetStandRack = Common%StandRack - end function - integer function GetStandRack_WN() - !DEC$ ATTRIBUTES DLLEXPORT :: GetStandRack_WN - !DEC$ ATTRIBUTES ALIAS: 'GetStandRack_WN' :: GetStandRack_WN - implicit none - GetStandRack_WN = Common%StandRack - end function + ! integer function GetStandRack_WN() + ! !DEC$ ATTRIBUTES DLLEXPORT :: GetStandRack_WN + ! !DEC$ ATTRIBUTES ALIAS: 'GetStandRack_WN' :: GetStandRack_WN + ! implicit none + ! GetStandRack_WN = Common%StandRack + ! end function diff --git a/CSharp/Common/CCommonVariables.f90 b/CSharp/Common/CCommonVariables.f90 index b99a751..1bc6a53 100644 --- a/CSharp/Common/CCommonVariables.f90 +++ b/CSharp/Common/CCommonVariables.f90 @@ -1,15 +1,16 @@ module CCommonVariables - use CIntegerEventHandler + !**use CIntegerEventHandler implicit none public type :: CommonType ! Input vars integer :: StandRack - type(IntegerEventHandler) :: OnStandRackChange + ! type(IntegerEventHandler) :: OnStandRackChange ! Output vars logical :: DrillWatchOperationMode end type type(CommonType):: Common contains + end module CCommonVariables \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CBoolEventHandler.f90 b/CSharp/Common/EventHandlers/CBoolEventHandler.f90 deleted file mode 100644 index cdd2b1a..0000000 --- a/CSharp/Common/EventHandlers/CBoolEventHandler.f90 +++ /dev/null @@ -1,44 +0,0 @@ -module CBoolEventHandler - use CIActionReference - implicit none - public - - type :: BoolEventHandler - procedure(ActionBool), pointer, nopass :: Delegate => null() - contains - procedure :: AssignTo => AssignTo - procedure :: MakeNull => MakeNull - procedure :: IsNull => IsNull - procedure :: Run => Run - end type BoolEventHandler - - contains - - subroutine AssignTo(this, proc) - implicit none - class(BoolEventHandler), intent(inout) :: this - procedure (ActionBool), pointer, intent(in) :: proc - this%Delegate => proc - end subroutine - - subroutine MakeNull(this) - implicit none - class(BoolEventHandler), intent(inout) :: this - this%Delegate => null() - end subroutine - - logical function IsNull(this) - implicit none - class(BoolEventHandler), intent(in) :: this - IsNull = .not.associated(this%Delegate) - end function - - subroutine Run(this, arg) - implicit none - class(BoolEventHandler), intent(inout) :: this - logical, intent(in) :: arg - !if(.not.this%IsNull()) - call this%Delegate(arg) - end subroutine - -end module CBoolEventHandler \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CBoolEventHandlerCollection.f90 b/CSharp/Common/EventHandlers/CBoolEventHandlerCollection.f90 deleted file mode 100644 index 92e0b14..0000000 --- a/CSharp/Common/EventHandlers/CBoolEventHandlerCollection.f90 +++ /dev/null @@ -1,103 +0,0 @@ -module CBoolEventHandlerCollection - use CBoolEventHandler - implicit none - public - type, public :: BoolEventHandlerCollection - type(BoolEventHandler), allocatable :: Delegates(:) - contains - procedure :: Length => Length - procedure :: Add => Add - procedure :: Remove => Remove - procedure :: Empty => Empty - procedure :: IsEmpty => IsEmpty - procedure :: RunAll => RunAll - end type BoolEventHandlerCollection - - contains - - integer function Length(this) - implicit none - class(BoolEventHandlerCollection), intent(in) :: this - if(allocated(this%Delegates)) then - Length = size(this%Delegates) - return - end if - Length = 0 - end function - - subroutine Add(this, proc) - implicit none - class(BoolEventHandlerCollection), intent(inout) :: this - type(BoolEventHandler), allocatable :: tempArr(:) - procedure (ActionBool), pointer, intent(in) :: proc - integer :: i, isize - - if(allocated(this%Delegates)) then - isize = size(this%Delegates) - allocate(tempArr(isize+1)) - do i=1,isize - tempArr(i) = this%Delegates(i) - end do - call tempArr(isize+1)%MakeNull() - call tempArr(isize+1)%AssignTo(proc) - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - else - allocate(this%Delegates(1)) - call this%Delegates(1)%MakeNull() - call this%Delegates(1)%AssignTo(proc) - end if - - end subroutine - - subroutine Remove(this, index) - implicit none - class(BoolEventHandlerCollection), intent(inout) :: this - integer, intent(in) :: index - type(BoolEventHandler), allocatable :: tempArr(:) - integer :: i - logical :: found - - if(index <= 0 .or. index > size(this%Delegates)) return - if(.not.allocated(this%Delegates))return - allocate(tempArr(size(this%Delegates)-1)) - found = .false. - do i=1, size(this%Delegates) - if(i==index) then - found = .true. - cycle - end if - if(found) then - tempArr(i-1) = this%Delegates(i) - else - tempArr(i) = this%Delegates(i) - endif - end do - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - end subroutine - - - subroutine Empty(this) - implicit none - class(BoolEventHandlerCollection), intent(inout) :: this - if(allocated(this%Delegates)) deallocate(this%Delegates) - end subroutine - - logical function IsEmpty(this) - implicit none - class(BoolEventHandlerCollection), intent(in) :: this - IsEmpty = .not.allocated(this%Delegates) - end function - - subroutine RunAll(this, arg) - implicit none - class(BoolEventHandlerCollection), intent(inout) :: this - logical, intent(in) :: arg - integer :: i - do i=1, size(this%Delegates) - call this%Delegates(i)%Run(arg) - end do - end subroutine - -end module CBoolEventHandlerCollection \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CDoubleEventHandler.f90 b/CSharp/Common/EventHandlers/CDoubleEventHandler.f90 deleted file mode 100644 index 620e2a8..0000000 --- a/CSharp/Common/EventHandlers/CDoubleEventHandler.f90 +++ /dev/null @@ -1,43 +0,0 @@ -module CDoubleEventHandler - use CIActionReference - implicit none - public - - type :: DoubleEventHandler - procedure(ActionDouble), pointer, nopass :: Delegate => null() - contains - procedure :: AssignTo => AssignTo - procedure :: MakeNull => MakeNull - procedure :: IsNull => IsNull - procedure :: Run => Run - end type DoubleEventHandler - - contains - - subroutine AssignTo(this, proc) - implicit none - class(DoubleEventHandler), intent(inout) :: this - procedure (ActionDouble), pointer, intent(in) :: proc - this%Delegate => proc - end subroutine - - subroutine MakeNull(this) - implicit none - class(DoubleEventHandler), intent(inout) :: this - this%Delegate => null() - end subroutine - - logical function IsNull(this) - implicit none - class(DoubleEventHandler), intent(in) :: this - IsNull = .not.associated(this%Delegate) - end function - - subroutine Run(this, arg) - implicit none - class(DoubleEventHandler), intent(inout) :: this - real(8), intent(in) :: arg - if(.not.this%IsNull()) call this%Delegate(arg) - end subroutine - -end module CDoubleEventHandler \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CDoubleEventHandlerCollection.f90 b/CSharp/Common/EventHandlers/CDoubleEventHandlerCollection.f90 deleted file mode 100644 index c9fb123..0000000 --- a/CSharp/Common/EventHandlers/CDoubleEventHandlerCollection.f90 +++ /dev/null @@ -1,103 +0,0 @@ -module CDoubleEventHandlerCollection - use CDoubleEventHandler - implicit none - public - type, public :: DoubleEventHandlerCollection - type(DoubleEventHandler), allocatable :: Delegates(:) - contains - procedure :: Length => Length - procedure :: Add => Add - procedure :: Remove => Remove - procedure :: Empty => Empty - procedure :: IsEmpty => IsEmpty - procedure :: RunAll => RunAll - end type DoubleEventHandlerCollection - - contains - - integer function Length(this) - implicit none - class(DoubleEventHandlerCollection), intent(in) :: this - if(allocated(this%Delegates)) then - Length = size(this%Delegates) - return - end if - Length = 0 - end function - - subroutine Add(this, proc) - implicit none - class(DoubleEventHandlerCollection), intent(inout) :: this - type(DoubleEventHandler), allocatable :: tempArr(:) - procedure (ActionDouble), pointer, intent(in) :: proc - integer :: i, isize - - if(allocated(this%Delegates)) then - isize = size(this%Delegates) - allocate(tempArr(isize+1)) - do i=1,isize - tempArr(i) = this%Delegates(i) - end do - call tempArr(isize+1)%MakeNull() - call tempArr(isize+1)%AssignTo(proc) - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - else - allocate(this%Delegates(1)) - call this%Delegates(1)%MakeNull() - call this%Delegates(1)%AssignTo(proc) - end if - - end subroutine - - subroutine Remove(this, index) - implicit none - class(DoubleEventHandlerCollection), intent(inout) :: this - integer, intent(in) :: index - type(DoubleEventHandler), allocatable :: tempArr(:) - integer :: i - logical :: found - - if(index <= 0 .or. index > size(this%Delegates)) return - if(.not.allocated(this%Delegates))return - allocate(tempArr(size(this%Delegates)-1)) - found = .false. - do i=1, size(this%Delegates) - if(i==index) then - found = .true. - cycle - end if - if(found) then - tempArr(i-1) = this%Delegates(i) - else - tempArr(i) = this%Delegates(i) - endif - end do - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - end subroutine - - - subroutine Empty(this) - implicit none - class(DoubleEventHandlerCollection), intent(inout) :: this - if(allocated(this%Delegates)) deallocate(this%Delegates) - end subroutine - - logical function IsEmpty(this) - implicit none - class(DoubleEventHandlerCollection), intent(in) :: this - IsEmpty = .not.allocated(this%Delegates) - end function - - subroutine RunAll(this, arg) - implicit none - class(DoubleEventHandlerCollection), intent(inout) :: this - real(8), intent(in) :: arg - integer :: i - do i=1, size(this%Delegates) - call this%Delegates(i)%Run(arg) - end do - end subroutine - -end module CDoubleEventHandlerCollection \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CIntegerArrayEventHandler.f90 b/CSharp/Common/EventHandlers/CIntegerArrayEventHandler.f90 deleted file mode 100644 index f300bc1..0000000 --- a/CSharp/Common/EventHandlers/CIntegerArrayEventHandler.f90 +++ /dev/null @@ -1,44 +0,0 @@ -module CIntegerArrayEventHandler - use CIActionReference - implicit none - public - - type :: IntegerArrayEventHandler - procedure(ActionIntegerArray), pointer, nopass :: Delegate => null() - contains - procedure :: AssignTo => AssignTo - procedure :: MakeNull => MakeNull - procedure :: IsNull => IsNull - procedure :: Run => Run - end type IntegerArrayEventHandler - - contains - - subroutine AssignTo(this, proc) - implicit none - class(IntegerArrayEventHandler), intent(inout) :: this - procedure (ActionIntegerArray), pointer, intent(in) :: proc - this%Delegate => proc - end subroutine - - subroutine MakeNull(this) - implicit none - class(IntegerArrayEventHandler), intent(inout) :: this - this%Delegate => null() - end subroutine - - logical function IsNull(this) - implicit none - class(IntegerArrayEventHandler), intent(in) :: this - IsNull = .not.associated(this%Delegate) - end function - - subroutine Run(this, arg) - implicit none - class(IntegerArrayEventHandler), intent(inout) :: this - integer, allocatable, intent (in) :: arg(:) - !if(.not.this%IsNull()) - call this%Delegate(arg) - end subroutine - -end module CIntegerArrayEventHandler \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CIntegerArrayEventHandlerCollection.f90 b/CSharp/Common/EventHandlers/CIntegerArrayEventHandlerCollection.f90 deleted file mode 100644 index 952aaf2..0000000 --- a/CSharp/Common/EventHandlers/CIntegerArrayEventHandlerCollection.f90 +++ /dev/null @@ -1,103 +0,0 @@ -module CIntegerArrayEventHandlerCollection - use CIntegerArrayEventHandler - implicit none - public - type, public :: IntegerArrayEventHandlerCollection - type(IntegerArrayEventHandler), allocatable :: Delegates(:) - contains - procedure :: Length => Length - procedure :: Add => Add - procedure :: Remove => Remove - procedure :: Empty => Empty - procedure :: IsEmpty => IsEmpty - procedure :: RunAll => RunAll_ - end type IntegerArrayEventHandlerCollection - - contains - - integer function Length(this) - implicit none - class(IntegerArrayEventHandlerCollection), intent(in) :: this - if(allocated(this%Delegates)) then - Length = size(this%Delegates) - return - end if - Length = 0 - end function - - subroutine Add(this, proc) - implicit none - class(IntegerArrayEventHandlerCollection), intent(inout) :: this - type(IntegerArrayEventHandler), allocatable :: tempArr(:) - procedure (ActionIntegerArray), pointer, intent(in) :: proc - integer :: i, isize - - if(allocated(this%Delegates)) then - isize = size(this%Delegates) - allocate(tempArr(isize+1)) - do i=1,isize - tempArr(i) = this%Delegates(i) - end do - call tempArr(isize+1)%MakeNull() - call tempArr(isize+1)%AssignTo(proc) - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - else - allocate(this%Delegates(1)) - call this%Delegates(1)%MakeNull() - call this%Delegates(1)%AssignTo(proc) - end if - - end subroutine - - subroutine Remove(this, index) - implicit none - class(IntegerArrayEventHandlerCollection), intent(inout) :: this - integer, intent(in) :: index - type(IntegerArrayEventHandler), allocatable :: tempArr(:) - integer :: i - logical :: found - - if(index <= 0 .or. index > size(this%Delegates)) return - if(.not.allocated(this%Delegates))return - allocate(tempArr(size(this%Delegates)-1)) - found = .false. - do i=1, size(this%Delegates) - if(i==index) then - found = .true. - cycle - end if - if(found) then - tempArr(i-1) = this%Delegates(i) - else - tempArr(i) = this%Delegates(i) - endif - end do - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - end subroutine - - - subroutine Empty(this) - implicit none - class(IntegerArrayEventHandlerCollection), intent(inout) :: this - if(allocated(this%Delegates)) deallocate(this%Delegates) - end subroutine - - logical function IsEmpty(this) - implicit none - class(IntegerArrayEventHandlerCollection), intent(in) :: this - IsEmpty = .not.allocated(this%Delegates) - end function - - subroutine RunAll_(this, arg) - implicit none - class(IntegerArrayEventHandlerCollection), intent(inout) :: this - integer, allocatable, intent (in) :: arg(:) - integer :: i - do i=1, size(this%Delegates) - call this%Delegates(i)%Run(arg) - end do - end subroutine - -end module CIntegerArrayEventHandlerCollection \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CIntegerEventHandler.f90 b/CSharp/Common/EventHandlers/CIntegerEventHandler.f90 deleted file mode 100644 index bfe607d..0000000 --- a/CSharp/Common/EventHandlers/CIntegerEventHandler.f90 +++ /dev/null @@ -1,44 +0,0 @@ -module CIntegerEventHandler - use CIActionReference - implicit none - public - - type :: IntegerEventHandler - procedure(ActionInteger), pointer, nopass :: Delegate => null() - contains - procedure :: AssignTo => AssignTo - procedure :: MakeNull => MakeNull - procedure :: IsNull => IsNull - procedure :: Run => Run - end type IntegerEventHandler - - contains - - subroutine AssignTo(this, proc) - implicit none - class(IntegerEventHandler), intent(inout) :: this - procedure (ActionInteger), pointer, intent(in) :: proc - this%Delegate => proc - end subroutine - - subroutine MakeNull(this) - implicit none - class(IntegerEventHandler), intent(inout) :: this - this%Delegate => null() - end subroutine - - logical function IsNull(this) - implicit none - class(IntegerEventHandler), intent(in) :: this - IsNull = .not.associated(this%Delegate) - end function - - subroutine Run(this, arg) - implicit none - class(IntegerEventHandler), intent(inout) :: this - integer, intent(in) :: arg - !if(.not.this%IsNull()) - call this%Delegate(arg) - end subroutine - -end module CIntegerEventHandler \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CIntegerEventHandlerCollection.f90 b/CSharp/Common/EventHandlers/CIntegerEventHandlerCollection.f90 deleted file mode 100644 index 7444525..0000000 --- a/CSharp/Common/EventHandlers/CIntegerEventHandlerCollection.f90 +++ /dev/null @@ -1,103 +0,0 @@ -module CIntegerEventHandlerCollection - use CIntegerEventHandler - implicit none - public - type, public :: IntegerEventHandlerCollection - type(IntegerEventHandler), allocatable :: Delegates(:) - contains - procedure :: Length => Length - procedure :: Add => Add - procedure :: Remove => Remove - procedure :: Empty => Empty - procedure :: IsEmpty => IsEmpty - procedure :: RunAll => RunAll - end type IntegerEventHandlerCollection - - contains - - integer function Length(this) - implicit none - class(IntegerEventHandlerCollection), intent(in) :: this - if(allocated(this%Delegates)) then - Length = size(this%Delegates) - return - end if - Length = 0 - end function - - subroutine Add(this, proc) - implicit none - class(IntegerEventHandlerCollection), intent(inout) :: this - type(IntegerEventHandler), allocatable :: tempArr(:) - procedure (ActionInteger), pointer, intent(in) :: proc - integer :: i, isize - - if(allocated(this%Delegates)) then - isize = size(this%Delegates) - allocate(tempArr(isize+1)) - do i=1,isize - tempArr(i) = this%Delegates(i) - end do - call tempArr(isize+1)%MakeNull() - call tempArr(isize+1)%AssignTo(proc) - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - else - allocate(this%Delegates(1)) - call this%Delegates(1)%MakeNull() - call this%Delegates(1)%AssignTo(proc) - end if - - end subroutine - - subroutine Remove(this, index) - implicit none - class(IntegerEventHandlerCollection), intent(inout) :: this - integer, intent(in) :: index - type(IntegerEventHandler), allocatable :: tempArr(:) - integer :: i - logical :: found - - if(index <= 0 .or. index > size(this%Delegates)) return - if(.not.allocated(this%Delegates))return - allocate(tempArr(size(this%Delegates)-1)) - found = .false. - do i=1, size(this%Delegates) - if(i==index) then - found = .true. - cycle - end if - if(found) then - tempArr(i-1) = this%Delegates(i) - else - tempArr(i) = this%Delegates(i) - endif - end do - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - end subroutine - - - subroutine Empty(this) - implicit none - class(IntegerEventHandlerCollection), intent(inout) :: this - if(allocated(this%Delegates)) deallocate(this%Delegates) - end subroutine - - logical function IsEmpty(this) - implicit none - class(IntegerEventHandlerCollection), intent(in) :: this - IsEmpty = .not.allocated(this%Delegates) - end function - - subroutine RunAll(this, arg) - implicit none - class(IntegerEventHandlerCollection), intent(inout) :: this - integer, intent(in) :: arg - integer :: i - do i=1, size(this%Delegates) - call this%Delegates(i)%Run(arg) - end do - end subroutine - -end module CIntegerEventHandlerCollection \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CRealEventHandler.f90 b/CSharp/Common/EventHandlers/CRealEventHandler.f90 deleted file mode 100644 index b9625cd..0000000 --- a/CSharp/Common/EventHandlers/CRealEventHandler.f90 +++ /dev/null @@ -1,44 +0,0 @@ -module CRealEventHandler - use CIActionReference - implicit none - public - - type :: RealEventHandler - procedure(ActionReal), pointer, nopass :: Delegate => null() - contains - procedure :: AssignTo => AssignTo - procedure :: MakeNull => MakeNull - procedure :: IsNull => IsNull - procedure :: Run => Run - end type RealEventHandler - - contains - - subroutine AssignTo(this, proc) - implicit none - class(RealEventHandler), intent(inout) :: this - procedure (ActionReal), pointer, intent(in) :: proc - this%Delegate => proc - end subroutine - - subroutine MakeNull(this) - implicit none - class(RealEventHandler), intent(inout) :: this - this%Delegate => null() - end subroutine - - logical function IsNull(this) - implicit none - class(RealEventHandler), intent(in) :: this - IsNull = .not.associated(this%Delegate) - end function - - subroutine Run(this, arg) - implicit none - class(RealEventHandler), intent(inout) :: this - real, intent(in) :: arg - !if(.not.this%IsNull()) - call this%Delegate(arg) - end subroutine - -end module CRealEventHandler \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CRealEventHandlerCollection.f90 b/CSharp/Common/EventHandlers/CRealEventHandlerCollection.f90 deleted file mode 100644 index 2e19aa6..0000000 --- a/CSharp/Common/EventHandlers/CRealEventHandlerCollection.f90 +++ /dev/null @@ -1,103 +0,0 @@ -module CRealEventHandlerCollection - use CRealEventHandler - implicit none - public - type, public :: RealEventHandlerCollection - type(RealEventHandler), allocatable :: Delegates(:) - contains - procedure :: Length => Length - procedure :: Add => Add - procedure :: Remove => Remove - procedure :: Empty => Empty - procedure :: IsEmpty => IsEmpty - procedure :: RunAll => RunAll - end type RealEventHandlerCollection - - contains - - integer function Length(this) - implicit none - class(RealEventHandlerCollection), intent(in) :: this - if(allocated(this%Delegates)) then - Length = size(this%Delegates) - return - end if - Length = 0 - end function - - subroutine Add(this, proc) - implicit none - class(RealEventHandlerCollection), intent(inout) :: this - type(RealEventHandler), allocatable :: tempArr(:) - procedure (ActionReal), pointer, intent(in) :: proc - integer :: i, isize - - if(allocated(this%Delegates)) then - isize = size(this%Delegates) - allocate(tempArr(isize+1)) - do i=1,isize - tempArr(i) = this%Delegates(i) - end do - call tempArr(isize+1)%MakeNull() - call tempArr(isize+1)%AssignTo(proc) - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - else - allocate(this%Delegates(1)) - call this%Delegates(1)%MakeNull() - call this%Delegates(1)%AssignTo(proc) - end if - - end subroutine - - subroutine Remove(this, index) - implicit none - class(RealEventHandlerCollection), intent(inout) :: this - integer, intent(in) :: index - type(RealEventHandler), allocatable :: tempArr(:) - integer :: i - logical :: found - - if(index <= 0 .or. index > size(this%Delegates)) return - if(.not.allocated(this%Delegates))return - allocate(tempArr(size(this%Delegates)-1)) - found = .false. - do i=1, size(this%Delegates) - if(i==index) then - found = .true. - cycle - end if - if(found) then - tempArr(i-1) = this%Delegates(i) - else - tempArr(i) = this%Delegates(i) - endif - end do - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - end subroutine - - - subroutine Empty(this) - implicit none - class(RealEventHandlerCollection), intent(inout) :: this - if(allocated(this%Delegates)) deallocate(this%Delegates) - end subroutine - - logical function IsEmpty(this) - implicit none - class(RealEventHandlerCollection), intent(in) :: this - IsEmpty = .not.allocated(this%Delegates) - end function - - subroutine RunAll(this, arg) - implicit none - class(RealEventHandlerCollection), intent(inout) :: this - real, intent(in) :: arg - integer :: i - do i=1, size(this%Delegates) - call this%Delegates(i)%Run(arg) - end do - end subroutine - -end module CRealEventHandlerCollection \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CVoidEventHandler.f90 b/CSharp/Common/EventHandlers/CVoidEventHandler.f90 deleted file mode 100644 index cbe829b..0000000 --- a/CSharp/Common/EventHandlers/CVoidEventHandler.f90 +++ /dev/null @@ -1,44 +0,0 @@ -module CVoidEventHandler - use CIActionReference - implicit none - public - - type :: VoidEventHandler - procedure(ActionVoid), pointer, nopass :: Delegate => null() - contains - procedure :: AssignTo => AssignTo - procedure :: MakeNull => MakeNull - procedure :: IsNull => IsNull - procedure :: Run => Run - end type VoidEventHandler - - contains - - subroutine AssignTo(this, proc) - implicit none - class(VoidEventHandler), intent(inout) :: this - procedure (ActionVoid), pointer, intent(in) :: proc - this%Delegate => proc - end subroutine - - subroutine MakeNull(this) - implicit none - class(VoidEventHandler), intent(inout) :: this - this%Delegate => null() - end subroutine - - logical function IsNull(this) - implicit none - class(VoidEventHandler), intent(in) :: this - IsNull = .not.associated(this%Delegate) - end function - - subroutine Run(this) - implicit none - class(VoidEventHandler), intent(inout) :: this - !if(.not.this%IsNull()) then - call this%Delegate() - !endif - end subroutine - -end module CVoidEventHandler \ No newline at end of file diff --git a/CSharp/Common/EventHandlers/CVoidEventHandlerCollection.f90 b/CSharp/Common/EventHandlers/CVoidEventHandlerCollection.f90 deleted file mode 100644 index 8cee66d..0000000 --- a/CSharp/Common/EventHandlers/CVoidEventHandlerCollection.f90 +++ /dev/null @@ -1,102 +0,0 @@ -module CVoidEventHandlerCollection - use CVoidEventHandler - implicit none - public - type, public :: VoidEventHandlerCollection - type(VoidEventHandler), allocatable :: Delegates(:) - contains - procedure :: Length => Length - procedure :: Add => Add - procedure :: Remove => Remove - procedure :: Empty => Empty - procedure :: IsEmpty => IsEmpty - procedure :: RunAll => RunAll - end type VoidEventHandlerCollection - - contains - - integer function Length(this) - implicit none - class(VoidEventHandlerCollection), intent(in) :: this - if(allocated(this%Delegates)) then - Length = size(this%Delegates) - return - end if - Length = 0 - end function - - subroutine Add(this, proc) - implicit none - class(VoidEventHandlerCollection), intent(inout) :: this - type(VoidEventHandler), allocatable :: tempArr(:) - procedure (ActionVoid), pointer, intent(in) :: proc - integer :: i, isize - - if(allocated(this%Delegates)) then - isize = size(this%Delegates) - allocate(tempArr(isize+1)) - do i=1,isize - tempArr(i) = this%Delegates(i) - end do - call tempArr(isize+1)%MakeNull() - call tempArr(isize+1)%AssignTo(proc) - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - else - allocate(this%Delegates(1)) - call this%Delegates(1)%MakeNull() - call this%Delegates(1)%AssignTo(proc) - end if - - end subroutine - - subroutine Remove(this, index) - implicit none - class(VoidEventHandlerCollection), intent(inout) :: this - integer, intent(in) :: index - type(VoidEventHandler), allocatable :: tempArr(:) - integer :: i - logical :: found - - if(index <= 0 .or. index > size(this%Delegates)) return - if(.not.allocated(this%Delegates))return - allocate(tempArr(size(this%Delegates)-1)) - found = .false. - do i=1, size(this%Delegates) - if(i==index) then - found = .true. - cycle - end if - if(found) then - tempArr(i-1) = this%Delegates(i) - else - tempArr(i) = this%Delegates(i) - endif - end do - deallocate(this%Delegates) - call move_alloc(tempArr, this%Delegates) - end subroutine - - - subroutine Empty(this) - implicit none - class(VoidEventHandlerCollection), intent(inout) :: this - if(allocated(this%Delegates)) deallocate(this%Delegates) - end subroutine - - logical function IsEmpty(this) - implicit none - class(VoidEventHandlerCollection), intent(in) :: this - IsEmpty = .not.allocated(this%Delegates) - end function - - subroutine RunAll(this) - implicit none - class(VoidEventHandlerCollection), intent(inout) :: this - integer :: i - do i=1, size(this%Delegates) - call this%Delegates(i)%Run() - end do - end subroutine - -end module CVoidEventHandlerCollection \ No newline at end of file diff --git a/CSharp/DownHole/CDownHoleVariables.f90 b/CSharp/DownHole/CDownHoleVariables.f90 index 88adc06..3c17817 100644 --- a/CSharp/DownHole/CDownHoleVariables.f90 +++ b/CSharp/DownHole/CDownHoleVariables.f90 @@ -5,6 +5,9 @@ module CDownHoleVariables use CLog4 implicit none public + !!!!!!!!!!!!!!!!!!!!! + ! Outputs to user interface + !!!!!!!!!!!!!!!!!!!!! type :: DownHoleType logical :: AnnDrillMud logical :: AnnCirculateMud diff --git a/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.f90 b/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.f90 index 38a6042..65c04db 100644 --- a/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.f90 +++ b/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.f90 @@ -1,6 +1,6 @@ module CDataDisplayConsoleVariables use CIActionReference - use CDoubleEventHandlerCollection + ! !**use CDoubleEventHandlerCollection implicit none public @@ -66,7 +66,7 @@ module CDataDisplayConsoleVariables real(8) :: ReturnLineTempGauge real(8) :: RotaryTorqueGauge real(8) :: RotaryRPMGauge - type(DoubleEventHandlerCollection) :: OnRotaryRpmChange + ! !**type(DoubleEventHandlerCollection) :: OnRotaryRpmChange integer :: AcidGasDetectionLED real(8) :: TotalStrokeCounter !real(8) :: TotalStrokeCounter_temp @@ -221,7 +221,7 @@ module CDataDisplayConsoleVariables DataDisplayConsole%RotaryRPMGauge = v DrillingWatch%RPM = v DataDisplayConsole%RTRPM = v - call DataDisplayConsole%OnRotaryRpmChange%RunAll(v) + ! call DataDisplayConsole%OnRotaryRpmChange%RunAll(v) end subroutine diff --git a/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.f90 b/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.f90 index 9392128..bd5ff8d 100644 --- a/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.f90 +++ b/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.f90 @@ -1,6 +1,6 @@ module CDrillingConsoleVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none public @@ -33,9 +33,9 @@ module CDrillingConsoleVariables real(8) :: DWPowerLever real(8) :: TongLever - ! type(VoidEventHandlerCollection) :: OnBreakoutLeverPress - ! type(VoidEventHandlerCollection) :: OnMakeupLeverPress - ! type(VoidEventHandlerCollection) :: OnTongNeutralPress + ! ! type(VoidEventHandlerCollection) :: OnBreakoutLeverPress + ! ! type(VoidEventHandlerCollection) :: OnMakeupLeverPress + ! ! type(VoidEventHandlerCollection) :: OnTongNeutralPress real(8) :: RTTransmissionLever real(8) :: DWClutchLever @@ -47,11 +47,11 @@ module CDrillingConsoleVariables logical :: GEN4 logical :: Permission_OpenKellyCock = .false. logical :: OpenKellyCock - ! type(VoidEventHandlerCollection) :: OnOpenKellyCockPress + ! ! type(VoidEventHandlerCollection) :: OnOpenKellyCockPress logical :: Permission_CloseKellyCock = .false. logical :: CloseKellyCock - ! type(VoidEventHandlerCollection) :: OnCloseKellyCockPress + ! ! type(VoidEventHandlerCollection) :: OnCloseKellyCockPress logical :: Permission_OpenSafetyValve = .false. logical :: OpenSafetyValve diff --git a/CSharp/Equipments/ControlPanels/CHookVariables.f90 b/CSharp/Equipments/ControlPanels/CHookVariables.f90 index 8b84fc0..df3d7fb 100644 --- a/CSharp/Equipments/ControlPanels/CHookVariables.f90 +++ b/CSharp/Equipments/ControlPanels/CHookVariables.f90 @@ -1,11 +1,11 @@ module CHookVariables - use CRealEventHandlerCollection + !**use CRealEventHandlerCollection ! use CHookActions implicit none Type :: HookType real :: HookHeight_S = 0.0 real :: HookHeight - type(RealEventHandlerCollection) :: OnHookHeightChange + !**type(RealEventHandlerCollection) :: OnHookHeightChange end type HookType Type(HookType)::Hook @@ -29,7 +29,7 @@ module CHookVariables print*, 'HookHeight=', Hook%HookHeight #endif - call Hook%OnHookHeightChange%RunAll(Hook%HookHeight) + !**call Hook%OnHookHeightChange%RunAll(Hook%HookHeight) end subroutine diff --git a/CSharp/Equipments/MudPathFinding/CManifolds.f90 b/CSharp/Equipments/MudPathFinding/CManifolds.f90 index b4c8068..8060975 100644 --- a/CSharp/Equipments/MudPathFinding/CManifolds.f90 +++ b/CSharp/Equipments/MudPathFinding/CManifolds.f90 @@ -1,7 +1,7 @@ module CManifolds use CStack use CArrangement - use CPathChangeEvents + ! use CPathChangeEvents use CDrillingConsoleVariables!, only: DrillingConsole%IRSafetyValveLed, DrillingConsole%IRIBopLed, DrillingConsole%OpenKellyCockLed, DrillingConsole%CloseKellyCockLed, DrillingConsole%OpenSafetyValveLed, DrillingConsole%CloseSafetyValveLed implicit none @@ -44,9 +44,9 @@ module CManifolds call Setup() !call OnSimulationInitialization%Add(PathFinding_Init) !call OnSimulationStop%Add(PathFinding_Init) - !call OnPathFindingStep%Add(PathFinding_Step) - !call OnPathFindingOutput%Add(PathFinding_Output) - ! call OnPathFindingMain%Add(PathFindingMainBody) + !!**call OnpPathFindingStep%Add(PathFinding_Step) + !!**call OnpPathFindingOutput%Add(PathFinding_Output) + ! !**call OnpPathFindingMain%Add(PathFindingMainBody) end subroutine subroutine PathFinding_Init @@ -86,7 +86,7 @@ end subroutine PathFinding_Step integer, dimension(8) :: StartTime,EndTime !TODO: clean up call DATE_AND_TIME(values=StartTime) !TODO: clean up - call BeforeTraverse%RunAll() + !**call BeforeTraverse%RunAll() if(allocated(Manifold%OpenPaths)) deallocate(Manifold%OpenPaths) @@ -99,7 +99,7 @@ end subroutine PathFinding_Step call PostProcess(Manifold%OpenPaths) - call AfterTraverse%RunAll() + !**call AfterTraverse%RunAll() Manifold%IsTraverse = .true. @@ -189,7 +189,7 @@ end subroutine PathFinding_Step if(p%IsNull()) return if(p%Length()<=1) return - call OnPathOpen%RunAll(p%Valves) + !**call OnpPathOpen%RunAll(p%Valves) if(allocated(pathArr)) then isize = size(pathArr) @@ -253,7 +253,7 @@ end subroutine PathFinding_Step end if if(found) then tempArr(i-1) = pathArr(i) - !call OnPathClose%RunAll(pathArr(i)%Valves) + !!**call OnpPathClose%RunAll(pathArr(i)%Valves) else tempArr(i) = pathArr(i) endif diff --git a/CSharp/OperationScenarios/Common/COperationScenariosVariables.f90 b/CSharp/OperationScenarios/Common/COperationScenariosVariables.f90 index 7fba184..df277ed 100644 --- a/CSharp/OperationScenarios/Common/COperationScenariosVariables.f90 +++ b/CSharp/OperationScenarios/Common/COperationScenariosVariables.f90 @@ -102,11 +102,11 @@ module COperationScenariosVariables !moved from enum/CElevatorConnectionEnum integer :: ElevatorConnection = 0 - type(VoidEventHandlerCollection) :: OnElevatorConnectionChange + ! type(VoidEventHandlerCollection) :: OnElevatorConnectionChange !moved from SoftwareOutputs/CStringUpdateVariables integer :: StringUpdate = 0 - type(IntegerEventHandlerCollection) :: OnStringUpdateChange + !**type(IntegerEventHandlerCollection) :: OnStringUpdateChange end type OperationScenarioType @@ -130,7 +130,7 @@ module COperationScenariosVariables if(OperationScenario%StringUpdate == v) return #endif OperationScenario%StringUpdate = v - call OperationScenario%OnStringUpdateChange%RunAll(v) + !**call OperationScenario%OnStringUpdateChange%RunAll(v) end subroutine integer function Get_StringUpdate() @@ -166,7 +166,7 @@ module COperationScenariosVariables #ifdef deb print*, 'OperationScenario%ElevatorConnection=', OperationScenario%ElevatorConnection #endif - call OperationScenario%OnElevatorConnectionChange%RunAll() + !**call OperationScenario%OnElevatorConnectionChange%RunAll() end subroutine integer function Get_ElevatorConnection() diff --git a/CSharp/OperationScenarios/Enums/CElevatorConnectionEnumVariables.f90 b/CSharp/OperationScenarios/Enums/CElevatorConnectionEnumVariables.f90 index 657144e..5fbc451 100644 --- a/CSharp/OperationScenarios/Enums/CElevatorConnectionEnumVariables.f90 +++ b/CSharp/OperationScenarios/Enums/CElevatorConnectionEnumVariables.f90 @@ -3,7 +3,7 @@ module CElevatorConnectionEnumVariables implicit none ! Mahmood: this variable moved to operationscenariocommon ! integer :: OperationScenario%ElevatorConnection = 0 - ! type(VoidEventHandlerCollection) :: OnElevatorConnectionChange + ! ! type(VoidEventHandlerCollection) :: OnElevatorConnectionChange public diff --git a/CSharp/OperationScenarios/Enums/CKellyConnectionEnumVariables.f90 b/CSharp/OperationScenarios/Enums/CKellyConnectionEnumVariables.f90 index d15d461..0ce9cd6 100644 --- a/CSharp/OperationScenarios/Enums/CKellyConnectionEnumVariables.f90 +++ b/CSharp/OperationScenarios/Enums/CKellyConnectionEnumVariables.f90 @@ -1,9 +1,9 @@ module CKellyConnectionEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none type::KellyConnectionEnumType integer :: KellyConnection = 0 - type(VoidEventHandlerCollection) :: OnKellyConnectionChange + ! type(VoidEventHandlerCollection) :: OnKellyConnectionChange end type KellyConnectionEnumType type(KellyConnectionEnumType)::KellyConnectionEnum ! public @@ -37,7 +37,7 @@ module CKellyConnectionEnumVariables #ifdef deb print*, 'KellyConnectionEnum%KellyConnection=', KellyConnectionEnum%KellyConnection #endif - call KellyConnectionEnum%OnKellyConnectionChange%RunAll() + !**call KellyConnectionEnum%OnKellyConnectionChange%RunAll() end subroutine integer function Get_KellyConnection() diff --git a/CSharp/OperationScenarios/Enums/CTdsConnectionModesEnumVariables.f90 b/CSharp/OperationScenarios/Enums/CTdsConnectionModesEnumVariables.f90 index 012637d..14af54d 100644 --- a/CSharp/OperationScenarios/Enums/CTdsConnectionModesEnumVariables.f90 +++ b/CSharp/OperationScenarios/Enums/CTdsConnectionModesEnumVariables.f90 @@ -1,9 +1,9 @@ module CTdsConnectionModesEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none type:: TdsConnectionModesEnumType integer :: TdsConnectionModes = 0 - type(VoidEventHandlerCollection) :: OnTdsConnectionModesChange + ! type(VoidEventHandlerCollection) :: OnTdsConnectionModesChange end type TdsConnectionModesEnumType type(TdsConnectionModesEnumType)::TdsConnectionModesEnum enum, bind(c) @@ -33,7 +33,7 @@ module CTdsConnectionModesEnumVariables #ifdef deb print*, 'TdsConnectionModesEnum%TdsConnectionModes=', TdsConnectionModesEnum%TdsConnectionModes #endif - call TdsConnectionModesEnum%OnTdsConnectionModesChange%RunAll() + !**call TdsConnectionModesEnum%OnTdsConnectionModesChange%RunAll() end subroutine integer function Get_TdsConnectionModes() diff --git a/CSharp/OperationScenarios/Enums/CTdsElevatorModesEnumVariables.f90 b/CSharp/OperationScenarios/Enums/CTdsElevatorModesEnumVariables.f90 index 6136aa2..9064fea 100644 --- a/CSharp/OperationScenarios/Enums/CTdsElevatorModesEnumVariables.f90 +++ b/CSharp/OperationScenarios/Enums/CTdsElevatorModesEnumVariables.f90 @@ -1,9 +1,9 @@ module CTdsElevatorModesEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none type:: TdsElevatorModesEnumType integer :: TdsElevatorModes = 0 - type(VoidEventHandlerCollection) :: OnTdsElevatorModesChange + ! type(VoidEventHandlerCollection) :: OnTdsElevatorModesChange end type TdsElevatorModesEnumType type(TdsElevatorModesEnumType)::TdsElevatorModesEnum enum, bind(c) @@ -26,7 +26,7 @@ module CTdsElevatorModesEnumVariables if(TdsElevatorModesEnum%TdsElevatorModes == v) return #endif TdsElevatorModesEnum%TdsElevatorModes = v - call TdsElevatorModesEnum%OnTdsElevatorModesChange%RunAll() + !**call TdsElevatorModesEnum%OnTdsElevatorModesChange%RunAll() end subroutine integer function Get_TdsElevatorModes() diff --git a/CSharp/OperationScenarios/Notifications/CTongNotification.f90 b/CSharp/OperationScenarios/Notifications/CTongNotification.f90 index f2f59ab..e32d23b 100644 --- a/CSharp/OperationScenarios/Notifications/CTongNotification.f90 +++ b/CSharp/OperationScenarios/Notifications/CTongNotification.f90 @@ -268,19 +268,19 @@ module CTongNotification end subroutine - subroutine Subscribe_TongNotification() - implicit none + ! subroutine Subscribe_TongNotification() + ! implicit none - call UnitySignals%OnOperationConditionChange%Add(Evaluate_TongNotification) - call SoftwareInputs%OnHookHeightChange%Add(Evaluate_TongNotification) - call UnityInputs%OnJointConnectionPossibleChange%Add(Evaluate_TongNotification) - call UnityInputs%OnSingleSetInMouseHoleChange%Add(Evaluate_TongNotification) - call OperationScenario%OnElevatorConnectionChange%Add(Evaluate_TongNotification) - call KellyConnectionEnum%OnKellyConnectionChange%Add(Evaluate_TongNotification) - call UnitySignals%OnSwingChange%Add(Evaluate_TongNotification) - call UnitySignals%OnSlipsChange%Add(Evaluate_TongNotification) + ! call UnitySignals%OnOperationConditionChange%Add(Evaluate_TongNotification) + ! ! call softwareInputs%OnHookHeightChange%Add(Evaluate_TongNotification) + ! call UnityInputs%OnJointConnectionPossibleChange%Add(Evaluate_TongNotification) + ! call UnityInputs%OnSingleSetInMouseHoleChange%Add(Evaluate_TongNotification) + ! call OperationScenario%OnElevatorConnectionChange%Add(Evaluate_TongNotification) + ! call KellyConnectionEnum%OnKellyConnectionChange%Add(Evaluate_TongNotification) + ! call UnitySignals%OnSwingChange%Add(Evaluate_TongNotification) + ! call UnitySignals%OnSlipsChange%Add(Evaluate_TongNotification) - end subroutine + ! end subroutine diff --git a/CSharp/OperationScenarios/Notifications/CUnlatchLedNotification.f90 b/CSharp/OperationScenarios/Notifications/CUnlatchLedNotification.f90 index d74a16a..7862fd1 100644 --- a/CSharp/OperationScenarios/Notifications/CUnlatchLedNotification.f90 +++ b/CSharp/OperationScenarios/Notifications/CUnlatchLedNotification.f90 @@ -198,24 +198,19 @@ module CUnlatchLedNotification call Set_UnlatchLed(.false.) endif - - - - - end subroutine - subroutine Subscribe_UnlatchLed() - implicit none - - call UnitySignals%OnOperationConditionChange%Add(Evaluate_UnlatchLed) - call SoftwareInputs%OnHookHeightChange%Add(Evaluate_UnlatchLed) - call SoftwareInputs%OnStandRackChanged%Add(Evaluate_UnlatchLed) - call OperationScenario%OnElevatorConnectionChange%Add(Evaluate_UnlatchLed) - call UnitySignals%OnSwingChange%Add(Evaluate_UnlatchLed) - call UnitySignals%OnSlipsChange%Add(Evaluate_UnlatchLed) - call Notifications%OnLatchLedChange%Add(Evaluate_UnlatchLed) - call Notifications%OnFillMouseHoleLedChange%Add(Evaluate_UnlatchLed) - end subroutine + ! subroutine Subscribe_UnlatchLed() + ! implicit none + + ! !**call UnitySignals%OnOperationConditionChange%Add(Evaluate_UnlatchLed) + ! ! call softwareInputs%OnHookHeightChange%Add(Evaluate_UnlatchLed) + ! ! call softwareInputs%OnStandRackChanged%Add(Evaluate_UnlatchLed) + ! call OperationScenario%OnElevatorConnectionChange%Add(Evaluate_UnlatchLed) + ! !**call UnitySignals%OnSwingChange%Add(Evaluate_UnlatchLed) + ! !**call UnitySignals%OnSlipsChange%Add(Evaluate_UnlatchLed) + ! !**call Notifications%OnLatchLedChange%Add(Evaluate_UnlatchLed) + ! !**call Notifications%OnFillMouseHoleLedChange%Add(Evaluate_UnlatchLed) + ! end subroutine end module CUnlatchLedNotification \ No newline at end of file diff --git a/CSharp/OperationScenarios/Notifications/NotificationVariables.f90 b/CSharp/OperationScenarios/Notifications/NotificationVariables.f90 index e71dae3..5825289 100644 --- a/CSharp/OperationScenarios/Notifications/NotificationVariables.f90 +++ b/CSharp/OperationScenarios/Notifications/NotificationVariables.f90 @@ -1,57 +1,57 @@ module NotificationVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none type::NotificationType logical :: CloseKellyCockLed = .false. - type(VoidEventHandlerCollection) :: OnCloseKellyCockLedChange + ! type(VoidEventHandlerCollection) :: OnCloseKellyCockLedChange logical :: CloseSafetyValveLed = .false. integer :: operation_CloseSafetyValveLed = 0 - type(VoidEventHandlerCollection) :: OnCloseSafetyValveLedChange + ! type(VoidEventHandlerCollection) :: OnCloseSafetyValveLedChange logical :: FillMouseHoleLed = .false. - type(VoidEventHandlerCollection) :: OnFillMouseHoleLedChange + ! type(VoidEventHandlerCollection) :: OnFillMouseHoleLedChange logical :: IrIBopLed = .false. - type(VoidEventHandlerCollection) :: OnIrIBopLedChange + ! type(VoidEventHandlerCollection) :: OnIrIBopLedChange logical :: IrSafetyValveLed = .false. integer :: operation_IrSafetyValveLed = 0 - type(VoidEventHandlerCollection) :: OnIrSafetyValveLedChange + ! type(VoidEventHandlerCollection) :: OnIrSafetyValveLedChange logical :: LatchLed = .false. - type(VoidEventHandlerCollection) :: OnLatchLedChange + ! type(VoidEventHandlerCollection) :: OnLatchLedChange logical :: OpenKellyCockLed = .false. - type(VoidEventHandlerCollection) :: OnOpenKellyCockLedChange + ! type(VoidEventHandlerCollection) :: OnOpenKellyCockLedChange logical :: OpenSafetyValveLed = .false. integer :: operation_OpenSafetyValveLed = 0 - type(VoidEventHandlerCollection) :: OnOpenSafetyValveLedChange + ! type(VoidEventHandlerCollection) :: OnOpenSafetyValveLedChange logical :: SlipsNotification = .false. ! procedure (ActionBool), pointer :: SlipsNotificationPtr - type(VoidEventHandlerCollection) :: OnSlipsNotificationChange + ! type(VoidEventHandlerCollection) :: OnSlipsNotificationChange logical :: SwingLed = .false. - type(VoidEventHandlerCollection) :: OnSwingLedChange + ! type(VoidEventHandlerCollection) :: OnSwingLedChange logical :: IbopLed = .false. - type(VoidEventHandlerCollection) :: OnIbopLedChange + ! type(VoidEventHandlerCollection) :: OnIbopLedChange logical :: PowerLed = .false. - type(VoidEventHandlerCollection) :: OnPowerLedChange + ! type(VoidEventHandlerCollection) :: OnPowerLedChange integer :: TorqueWrenchLed = 0 - type(VoidEventHandlerCollection) :: OnTorqueWrenchLedChange + ! type(VoidEventHandlerCollection) :: OnTorqueWrenchLedChange logical :: TongNotification = .false. ! procedure (ActionBool), pointer :: TongNotificationPtr - type(VoidEventHandlerCollection) :: OnTongNotificationChange + ! type(VoidEventHandlerCollection) :: OnTongNotificationChange logical :: UnlatchLed = .false. - type(VoidEventHandlerCollection) :: OnUnlatchLedChange + ! type(VoidEventHandlerCollection) :: OnUnlatchLedChange end type NotificationType type(NotificationType)::notifications @@ -74,7 +74,7 @@ module NotificationVariables DrillingConsole%UnlatchPipeLED = 0 endif - call notifications%OnUnlatchLedChange%RunAll() + !**call notifications%OnUnlatchLedChange%RunAll() end subroutine logical function Get_UnlatchLed() @@ -89,11 +89,11 @@ module NotificationVariables if(notifications%TongNotification == v) return #endif notifications%TongNotification = v - ! if(associated(notifications%TongNotificationPtr)) call notifications%TongNotificationPtr(notifications%TongNotification) + ! if(associated(notifications%TongNotificationPtr)) !**call notifications%TongNotificationPtr(notifications%TongNotification) #ifdef deb print*, 'notifications%TongNotification=', notifications%TongNotification #endif - call notifications%OnTongNotificationChange%RunAll() + !**call notifications%OnTongNotificationChange%RunAll() end subroutine logical function Get_TongNotification() @@ -111,7 +111,7 @@ module NotificationVariables #endif notifications%TorqueWrenchLed = v TopDrivePanel%TopDriveTorqueWrenchLed = v - call notifications%OnTorqueWrenchLedChange%RunAll() + !**call notifications%OnTorqueWrenchLedChange%RunAll() end subroutine logical function Get_TorqueWrenchLed() @@ -136,7 +136,7 @@ module NotificationVariables TopDrivePanel%TopDriveTdsPowerLed = 0 endif - call notifications%OnPowerLedChange%RunAll() + !**call notifications%OnPowerLedChange%RunAll() end subroutine logical function Get_PowerLed() @@ -163,7 +163,7 @@ module NotificationVariables call OpenTopDriveIBop() endif - call notifications%OnIbopLedChange%RunAll() + !**call notifications%OnIbopLedChange%RunAll() end subroutine logical function Get_IbopLed() @@ -185,7 +185,7 @@ module NotificationVariables else DrillingConsole%SwingLed = 0 endif - call notifications%OnSwingLedChange%RunAll() + !**call notifications%OnSwingLedChange%RunAll() end subroutine logical function Get_SwingLed() @@ -200,11 +200,11 @@ module NotificationVariables if(notifications%SlipsNotification == v) return #endif notifications%SlipsNotification = v - ! if(associated(notifications%SlipsNotificationPtr)) call notifications%SlipsNotificationPtr(notifications%SlipsNotification) + ! if(associated(notifications%SlipsNotificationPtr)) !**call notifications%SlipsNotificationPtr(notifications%SlipsNotification) #ifdef deb print*, 'notifications%SlipsNotification=', notifications%SlipsNotification #endif - call notifications%OnSlipsNotificationChange%RunAll() + !**call notifications%OnSlipsNotificationChange%RunAll() end subroutine logical function Get_SlipsNotification() @@ -230,7 +230,7 @@ module NotificationVariables if(Hoisting%DriveType == Kelly_DriveType .and. notifications%operation_OpenSafetyValveLed == 1) call OpenSafetyValve_TripMode() endif - call notifications%OnOpenSafetyValveLedChange%RunAll() + !**call notifications%OnOpenSafetyValveLedChange%RunAll() end subroutine logical function Get_OpenSafetyValveLed() @@ -260,7 +260,7 @@ module NotificationVariables ! OpenKellyCockLedHw = 0 !endif - call notifications%OnOpenKellyCockLedChange%RunAll() + !**call notifications%OnOpenKellyCockLedChange%RunAll() end subroutine logical function Get_OpenKellyCockLed() @@ -283,7 +283,7 @@ module NotificationVariables else DrillingConsole%LatchPipeLED = 0 endif - call notifications%OnLatchLedChange%RunAll() + !**call notifications%OnLatchLedChange%RunAll() end subroutine logical function Get_LatchLed() @@ -327,7 +327,7 @@ module NotificationVariables call Set_SafetyValve_Remove() endif - call notifications%OnIrSafetyValveLedChange%RunAll() + !**call notifications%OnIrSafetyValveLedChange%RunAll() end subroutine logical function Get_IrSafetyValveLed() @@ -354,7 +354,7 @@ module NotificationVariables call RemoveIBop() call Set_Ibop_Remove() endif - call notifications%OnIrIBopLedChange%RunAll() + !**call notifications%OnIrIBopLedChange%RunAll() end subroutine logical function Get_IrIBopLed() @@ -379,7 +379,7 @@ module NotificationVariables DrillingConsole%FillMouseHoleLed = 0 !call Set_MouseHole(MOUSE_HOLE_EMPTY) endif - call notifications%OnFillMouseHoleLedChange%RunAll() + !**call notifications%OnFillMouseHoleLedChange%RunAll() end subroutine logical function Get_FillMouseHoleLed() @@ -399,7 +399,7 @@ module NotificationVariables if(notifications%CloseKellyCockLed) then call CloseKellyCock() endif - call notifications%OnCloseKellyCockLedChange%RunAll() + !**call notifications%OnCloseKellyCockLedChange%RunAll() end subroutine logical function Get_CloseKellyCockLed() @@ -423,7 +423,7 @@ module NotificationVariables if(Hoisting%DriveType == Kelly_DriveType .and. notifications%operation_CloseSafetyValveLed == 0) call CloseSafetyValve_KellyMode() if(Hoisting%DriveType == Kelly_DriveType .and. notifications%operation_CloseSafetyValveLed == 1) call CloseSafetyValve_TripMode() endif - call notifications%OnCloseSafetyValveLedChange%RunAll() + !**call notifications%OnCloseSafetyValveLedChange%RunAll() end subroutine logical function Get_CloseSafetyValveLed() diff --git a/CSharp/OperationScenarios/Permissions/PermissionsVariables.f90 b/CSharp/OperationScenarios/Permissions/PermissionsVariables.f90 index ebd1ce9..a9d8b98 100644 --- a/CSharp/OperationScenarios/Permissions/PermissionsVariables.f90 +++ b/CSharp/OperationScenarios/Permissions/PermissionsVariables.f90 @@ -1,26 +1,26 @@ module PermissionsVariables -use CVoidEventHandlerCollection +! use CVoidEventHandlerCollection type::PermissionsType logical :: FillupHeadPermission = .false. - type(VoidEventHandlerCollection) :: OnFillupHeadPermissionChange + ! type(VoidEventHandlerCollection) :: OnFillupHeadPermissionChange logical :: InstallFillupHeadPermission = .false. - type(VoidEventHandlerCollection) :: OnInstallFillupHeadPermissionChange + ! type(VoidEventHandlerCollection) :: OnInstallFillupHeadPermissionChange logical :: InstallMudBucketPermission = .false. - type(VoidEventHandlerCollection) :: OnInstallMudBucketPermissionChange + ! type(VoidEventHandlerCollection) :: OnInstallMudBucketPermissionChange logical :: IrIbopPermission = .false. - type(VoidEventHandlerCollection) :: OnIrIbopPermissionChange + ! type(VoidEventHandlerCollection) :: OnIrIbopPermissionChange logical :: IrSafetyValvePermission = .false. - type(VoidEventHandlerCollection) :: OnIrSafetyValvePermissionChange + ! type(VoidEventHandlerCollection) :: OnIrSafetyValvePermissionChange logical :: RemoveFillupHeadPermission = .false. - type(VoidEventHandlerCollection) :: OnRemoveFillupHeadPermissionChange + ! type(VoidEventHandlerCollection) :: OnRemoveFillupHeadPermissionChange logical :: RemoveMudBucketPermission = .false. - type(VoidEventHandlerCollection) :: OnRemoveMudBucketPermissionChange + ! type(VoidEventHandlerCollection) :: OnRemoveMudBucketPermissionChange logical :: SwingDrillPermission = .false. - type(VoidEventHandlerCollection) :: OnSwingDrillPermissionChange + ! type(VoidEventHandlerCollection) :: OnSwingDrillPermissionChange logical :: SwingOffPermission = .false. - type(VoidEventHandlerCollection) :: OnSwingOffPermissionChange + ! type(VoidEventHandlerCollection) :: OnSwingOffPermissionChange logical :: SwingTiltPermission = .false. - type(VoidEventHandlerCollection) :: OnSwingTiltPermissionChange + ! type(VoidEventHandlerCollection) :: OnSwingTiltPermissionChange end type PermissionsType type(PermissionsType):: permissions @@ -37,7 +37,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'permissions%SwingTiltPermission=', permissions%SwingTiltPermission #endif - call permissions%OnSwingTiltPermissionChange%RunAll() + !**call permissions%OnSwingTiltPermissionChange%RunAll() end subroutine logical function Get_SwingTiltPermission() @@ -55,7 +55,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'permissions%SwingOffPermission=', permissions%SwingOffPermission #endif - call permissions%OnSwingOffPermissionChange%RunAll() + !**call permissions%OnSwingOffPermissionChange%RunAll() end subroutine logical function Get_SwingOffPermission() @@ -73,7 +73,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'permissions%SwingDrillPermission=', permissions%SwingDrillPermission #endif - call permissions%OnSwingDrillPermissionChange%RunAll() + !**call permissions%OnSwingDrillPermissionChange%RunAll() end subroutine logical function Get_SwingDrillPermission() @@ -91,7 +91,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'permissions%RemoveMudBucketPermission=', permissions%RemoveMudBucketPermission #endif - call permissions%OnRemoveMudBucketPermissionChange%RunAll() + !**call permissions%OnRemoveMudBucketPermissionChange%RunAll() end subroutine logical function Get_RemoveMudBucketPermission() @@ -110,7 +110,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'permissions%RemoveFillupHeadPermission=', permissions%RemoveFillupHeadPermission #endif - call permissions%OnRemoveFillupHeadPermissionChange%RunAll() + !**call permissions%OnRemoveFillupHeadPermissionChange%RunAll() end subroutine logical function Get_RemoveFillupHeadPermission() @@ -128,7 +128,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'permissions%IrSafetyValvePermission=', permissions%IrSafetyValvePermission #endif - call permissions%OnIrSafetyValvePermissionChange%RunAll() + !**call permissions%OnIrSafetyValvePermissionChange%RunAll() end subroutine logical function Get_IrSafetyValvePermission() @@ -146,7 +146,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'permissions%IrIbopPermission=', permissions%IrIbopPermission #endif - call permissions%OnIrIbopPermissionChange%RunAll() + !**call permissions%OnIrIbopPermissionChange%RunAll() end subroutine logical function Get_IrIbopPermission() @@ -165,7 +165,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'permissions%InstallMudBucketPermission=', permissions%InstallMudBucketPermission #endif - call permissions%OnInstallMudBucketPermissionChange%RunAll() + !**call permissions%OnInstallMudBucketPermissionChange%RunAll() end subroutine logical function Get_InstallMudBucketPermission() @@ -183,7 +183,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'InstallFillupHeadPermission=', permissions%InstallFillupHeadPermission #endif - call permissions%OnInstallFillupHeadPermissionChange%RunAll() + !**call permissions%OnInstallFillupHeadPermissionChange%RunAll() end subroutine logical function Get_InstallFillupHeadPermission() @@ -201,7 +201,7 @@ use CVoidEventHandlerCollection #ifdef deb print*, 'FillupHeadPermission=', permissions%FillupHeadPermission #endif - call permissions%OnFillupHeadPermissionChange%RunAll() + !**call permissions%OnFillupHeadPermissionChange%RunAll() end subroutine logical function Get_FillupHeadPermission() diff --git a/CSharp/OperationScenarios/SoftwareInputsVariables.f90 b/CSharp/OperationScenarios/SoftwareInputsVariables.f90 index a25e5e1..5c2ff64 100644 --- a/CSharp/OperationScenarios/SoftwareInputsVariables.f90 +++ b/CSharp/OperationScenarios/SoftwareInputsVariables.f90 @@ -1,24 +1,24 @@ module SoftwareInputsVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection type:: SoftwareInputsType real :: HookHeight = 0 - type(VoidEventHandlerCollection) :: OnHookHeightChange + ! type(VoidEventHandlerCollection) :: OnHookHeightChange real :: IbopHeight = 0 - type(VoidEventHandlerCollection) :: OnIbopHeightChange + ! type(VoidEventHandlerCollection) :: OnIbopHeightChange real :: NearFloorConnection = 0 - type(VoidEventHandlerCollection) :: OnNearFloorConnectionChange + ! type(VoidEventHandlerCollection) :: OnNearFloorConnectionChange real :: SafetyValveHeight = 0 - type(VoidEventHandlerCollection) :: OnSafetyValveHeightChange + ! type(VoidEventHandlerCollection) :: OnSafetyValveHeightChange logical :: SlackOff = .false. - type(VoidEventHandlerCollection) :: OnSlackOffChange + ! type(VoidEventHandlerCollection) :: OnSlackOffChange integer :: StandRack = 0 - type(VoidEventHandlerCollection) :: OnStandRackChanged + ! type(VoidEventHandlerCollection) :: OnStandRackChanged real :: StringPressure = 0 - type(VoidEventHandlerCollection) :: OnStringPressureChange + ! type(VoidEventHandlerCollection) :: OnStringPressureChange real :: TdsStemJointHeight = 0 - type(VoidEventHandlerCollection) :: OnTdsStemJointHeightChange + ! type(VoidEventHandlerCollection) :: OnTdsStemJointHeightChange logical :: ZeroStringSpeed = .false. - type(VoidEventHandlerCollection) :: OnZeroStringSpeedChange + ! type(VoidEventHandlerCollection) :: OnZeroStringSpeedChange end type SoftwareInputsType type(SoftwareInputsType):: softwareInputs @@ -34,7 +34,7 @@ module SoftwareInputsVariables #ifdef deb print*, 'ZeroStringSpeed=', softwareInputs%ZeroStringSpeed #endif - call softwareInputs%OnZeroStringSpeedChange%RunAll() + ! call softwareInputs%OnZeroStringSpeedChange%RunAll() end subroutine logical function Get_ZeroStringSpeed() @@ -53,7 +53,7 @@ module SoftwareInputsVariables #ifdef deb print*, 'TdsStemJointHeight=', softwareInputs%TdsStemJointHeight #endif - call softwareInputs%OnTdsStemJointHeightChange%RunAll() + ! call softwareInputs%OnTdsStemJointHeightChange%RunAll() end subroutine real function Get_TdsStemJointHeight() @@ -72,7 +72,7 @@ module SoftwareInputsVariables #ifdef deb print*, 'StringPressure=', softwareInputs%StringPressure #endif - call softwareInputs%OnStringPressureChange%RunAll() + ! call softwareInputs%OnStringPressureChange%RunAll() end subroutine real function Get_StringPressure() @@ -90,7 +90,7 @@ module SoftwareInputsVariables #ifdef deb print*, 'StandRack=', softwareInputs%StandRack #endif - call softwareInputs%OnStandRackChanged%RunAll() + ! call softwareInputs%OnStandRackChanged%RunAll() end subroutine integer function Get_StandRack() @@ -108,7 +108,7 @@ module SoftwareInputsVariables #ifdef deb print*, 'SlackOff=', softwareInputs%SlackOff #endif - call softwareInputs%OnSlackOffChange%RunAll() + ! call softwareInputs%OnSlackOffChange%RunAll() end subroutine logical function Get_SlackOff() @@ -126,7 +126,7 @@ module SoftwareInputsVariables #ifdef deb print*, 'SafetyValveHeight=', softwareInputs%SafetyValveHeight #endif - call softwareInputs%OnSafetyValveHeightChange%RunAll() + ! call softwareInputs%OnSafetyValveHeightChange%RunAll() end subroutine real function Get_SafetyValveHeight() @@ -146,7 +146,7 @@ module SoftwareInputsVariables #ifdef deb print*, 'NearFloorConnection=', softwareInputs%NearFloorConnection #endif - call softwareInputs%OnNearFloorConnectionChange%RunAll() + ! call softwareInputs%OnNearFloorConnectionChange%RunAll() end subroutine real function Get_NearFloorConnection() @@ -165,7 +165,7 @@ module SoftwareInputsVariables #ifdef deb print*, 'IbopHeight=', softwareInputs%IbopHeight #endif - call softwareInputs%OnIbopHeightChange%RunAll() + ! call softwareInputs%OnIbopHeightChange%RunAll() end subroutine real function Get_IbopHeight() @@ -184,7 +184,7 @@ module SoftwareInputsVariables #ifdef deb print*, 'HookHeight=', softwareInputs%HookHeight #endif - call softwareInputs%OnHookHeightChange%RunAll() + ! call softwareInputs%OnHookHeightChange%RunAll() end subroutine real function Get_HookHeight() diff --git a/CSharp/OperationScenarios/SoftwareOutputs/CStringUpdateVariables.f90 b/CSharp/OperationScenarios/SoftwareOutputs/CStringUpdateVariables.f90 index 2b90ef5..fa14bd7 100644 --- a/CSharp/OperationScenarios/SoftwareOutputs/CStringUpdateVariables.f90 +++ b/CSharp/OperationScenarios/SoftwareOutputs/CStringUpdateVariables.f90 @@ -5,7 +5,7 @@ module CStringUpdateVariables public - type(IntegerEventHandlerCollection) :: OnStringUpdateChange + !**type(IntegerEventHandlerCollection) :: OnStringUpdateChange enum, bind(c) enumerator STRING_UPDATE_NEUTRAL diff --git a/CSharp/OperationScenarios/Unity/CUnityInputs.f90 b/CSharp/OperationScenarios/Unity/CUnityInputs.f90 index 852f50e..0c6b232 100644 --- a/CSharp/OperationScenarios/Unity/CUnityInputs.f90 +++ b/CSharp/OperationScenarios/Unity/CUnityInputs.f90 @@ -1,5 +1,5 @@ module CUnityInputs - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none type :: UnityInputsType logical :: ElevatorConnectionPossible @@ -22,15 +22,15 @@ module CUnityInputs ! public - type(VoidEventHandlerCollection) :: OnElevatorConnectionPossibleChange - type(VoidEventHandlerCollection) :: OnJointConnectionPossibleChange - type(VoidEventHandlerCollection) :: OnIsKellyBushingSetInTableChange - type(VoidEventHandlerCollection) :: OnElevatorPickupChange - type(VoidEventHandlerCollection) :: OnNearFloorPositionChange - type(VoidEventHandlerCollection) :: OnSingleSetInMouseHoleChange + ! type(VoidEventHandlerCollection) :: OnElevatorConnectionPossibleChange + ! type(VoidEventHandlerCollection) :: OnJointConnectionPossibleChange + ! type(VoidEventHandlerCollection) :: OnIsKellyBushingSetInTableChange + ! type(VoidEventHandlerCollection) :: OnElevatorPickupChange + ! type(VoidEventHandlerCollection) :: OnNearFloorPositionChange + ! type(VoidEventHandlerCollection) :: OnSingleSetInMouseHoleChange - type(VoidEventHandlerCollection) :: OnTdsConnectionPossibleChange - type(VoidEventHandlerCollection) :: OnTdsStemInChange + ! type(VoidEventHandlerCollection) :: OnTdsConnectionPossibleChange + ! type(VoidEventHandlerCollection) :: OnTdsStemInChange end type UnityInputsType type(UnityInputsType)::UnityInputs @@ -306,7 +306,7 @@ module CUnityInputs ! if(UnityInputs%ElevatorConnectionPossible == v) return ! #endif ! UnityInputs%ElevatorConnectionPossible = v -! call UnityInputs%OnElevatorConnectionPossibleChange%RunAll() +! !**call UnityInputs%OnElevatorConnectionPossibleChange%RunAll() ! #ifdef deb ! print*, 'ElevatorConnectionPossible=', UnityInputs%ElevatorConnectionPossible ! #endif @@ -341,7 +341,7 @@ module CUnityInputs ! if(UnityInputs%JointConnectionPossible == v) return ! #endif ! UnityInputs%JointConnectionPossible = v -! call UnityInputs%OnJointConnectionPossibleChange%RunAll() +! !**call UnityInputs%OnJointConnectionPossibleChange%RunAll() ! #ifdef deb ! print*, 'JointConnectionPossible=', UnityInputs%JointConnectionPossible ! #endif @@ -373,7 +373,7 @@ module CUnityInputs ! if(UnityInputs%IsKellyBushingSetInTable == v) return ! #endif ! UnityInputs%IsKellyBushingSetInTable = v -! call UnityInputs%OnIsKellyBushingSetInTableChange%RunAll() +! !**call UnityInputs%OnIsKellyBushingSetInTableChange%RunAll() ! #ifdef deb ! print*, 'IsKellyBushingSetInTable=', UnityInputs%IsKellyBushingSetInTable ! #endif @@ -406,7 +406,7 @@ module CUnityInputs ! if(UnityInputs%ElevatorPickup == v) return ! #endif ! UnityInputs%ElevatorPickup = v -! call UnityInputs%OnElevatorPickupChange%RunAll() +! !**call UnityInputs%OnElevatorPickupChange%RunAll() ! #ifdef deb ! print*, 'ElevatorPickup =', UnityInputs%ElevatorPickup ! #endif @@ -438,7 +438,7 @@ module CUnityInputs if(UnityInputs%NearFloorPosition == v) return #endif UnityInputs%NearFloorPosition = v - call UnityInputs%OnNearFloorPositionChange%RunAll() + !**call UnityInputs%OnNearFloorPositionChange%RunAll() #ifdef deb print*, 'NearFloorPosition =', UnityInputs%NearFloorPosition #endif @@ -482,7 +482,7 @@ module CUnityInputs ! if(UnityInputs%SingleSetInMouseHole == v) return ! #endif ! UnityInputs%SingleSetInMouseHole = v -! call UnityInputs%OnSingleSetInMouseHoleChange%RunAll() +! !**call UnityInputs%OnSingleSetInMouseHoleChange%RunAll() ! #ifdef deb ! print*, 'singleSetInMouseHole=', UnityInputs%SingleSetInMouseHole ! #endif @@ -551,7 +551,7 @@ module CUnityInputs ! if(UnityInputs%TdsConnectionPossible == v) return ! #endif ! UnityInputs%TdsConnectionPossible = v -! call UnityInputs%OnTdsConnectionPossibleChange%RunAll() +! !**call UnityInputs%OnTdsConnectionPossibleChange%RunAll() ! #ifdef deb ! print*, 'TdsConnectionPossible=', UnityInputs%TdsConnectionPossible ! #endif @@ -581,7 +581,7 @@ module CUnityInputs ! if(UnityInputs%TdsStemIn == v) return ! #endif ! UnityInputs%TdsStemIn = v -! call UnityInputs%OnTdsStemInChange%RunAll() +! !**call UnityInputs%OnTdsStemInChange%RunAll() ! #ifdef deb ! print*, 'TdsStemIn=', UnityInputs%TdsStemIn ! #endif diff --git a/CSharp/OperationScenarios/Unity/CUnityOutputs.f90 b/CSharp/OperationScenarios/Unity/CUnityOutputs.f90 index 56ce23e..e580124 100644 --- a/CSharp/OperationScenarios/Unity/CUnityOutputs.f90 +++ b/CSharp/OperationScenarios/Unity/CUnityOutputs.f90 @@ -22,7 +22,7 @@ module CUnityOutputs use CDataDisplayConsoleVariables implicit none PumpsSpmChanges => Calc_KellyHoseVibrationRate - call DataDisplayConsole%OnRotaryRpmChange%Add(Set_RotaryRpm) + ! call DataDisplayConsole%OnRotaryRpmChange%Add(Set_RotaryRpm) end subroutine diff --git a/CSharp/OperationScenarios/UnitySignals/CBucketEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CBucketEnumVariables.f90 index 7b3e5be..503a176 100644 --- a/CSharp/OperationScenarios/UnitySignals/CBucketEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CBucketEnumVariables.f90 @@ -1,11 +1,11 @@ module CBucketEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: MudBucket = 0 public - type(VoidEventHandlerCollection) :: OnMudBucketChange + ! type(VoidEventHandlerCollection) :: OnMudBucketChange enum, bind(c) !enumerator MUD_BUCKET_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CElevatorEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CElevatorEnumVariables.f90 index c42bcc6..0ddaedb 100644 --- a/CSharp/OperationScenarios/UnitySignals/CElevatorEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CElevatorEnumVariables.f90 @@ -1,11 +1,11 @@ module CElevatorEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: Elevator = 0 public - type(VoidEventHandlerCollection) :: OnElevatorChange + ! type(VoidEventHandlerCollection) :: OnElevatorChange enum, bind(c) enumerator ELEVATOR_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CFlowKellyDisconnectEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CFlowKellyDisconnectEnumVariables.f90 index 15a5f46..4805ad9 100644 --- a/CSharp/OperationScenarios/UnitySignals/CFlowKellyDisconnectEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CFlowKellyDisconnectEnumVariables.f90 @@ -1,11 +1,11 @@ module CFlowKellyDisconnectEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none ! integer :: FlowKellyDisconnect = 0 ! ! public ! -! type(VoidEventHandlerCollection) :: OnFlowKellyDisconnectChange +! ! type(VoidEventHandlerCollection) :: OnFlowKellyDisconnectChange ! ! enum, bind(c) ! enumerator FLOW_KELLY_DISCONNECT_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CFlowPipeDisconnectEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CFlowPipeDisconnectEnumVariables.f90 index e022c90..45ed9ef 100644 --- a/CSharp/OperationScenarios/UnitySignals/CFlowPipeDisconnectEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CFlowPipeDisconnectEnumVariables.f90 @@ -1,11 +1,11 @@ module CFlowPipeDisconnectEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none ! integer :: FlowPipeDisconnect = 0 ! ! public ! -! type(VoidEventHandlerCollection) :: OnFlowPipeDisconnectChange +! ! type(VoidEventHandlerCollection) :: OnFlowPipeDisconnectChange ! ! enum, bind(c) ! enumerator FLOW_PIPE_DISCONNECT_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CHeadEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CHeadEnumVariables.f90 index 280a6d8..d39d9d1 100644 --- a/CSharp/OperationScenarios/UnitySignals/CHeadEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CHeadEnumVariables.f90 @@ -1,11 +1,11 @@ module CHeadEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: FillupHead = 0 public - type(VoidEventHandlerCollection) :: OnFillupHeadChange + ! type(VoidEventHandlerCollection) :: OnFillupHeadChange enum, bind(c) !enumerator FILLUP_HEAD_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CIbopEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CIbopEnumVariables.f90 index 89449d2..ac189fd 100644 --- a/CSharp/OperationScenarios/UnitySignals/CIbopEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CIbopEnumVariables.f90 @@ -1,11 +1,11 @@ module CIbopEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: Ibop = 0 public - type(VoidEventHandlerCollection) :: OnIbopChange + ! type(VoidEventHandlerCollection) :: OnIbopChange enum, bind(c) !enumerator IBOP_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CKellyEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CKellyEnumVariables.f90 index 2391a50..b50b2e3 100644 --- a/CSharp/OperationScenarios/UnitySignals/CKellyEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CKellyEnumVariables.f90 @@ -1,12 +1,12 @@ module CKellyEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: Kelly = 0 integer :: Kelly_S = 0 public - type(VoidEventHandlerCollection) :: OnKellyChange + ! type(VoidEventHandlerCollection) :: OnKellyChange enum, bind(c) enumerator KELLY_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CMouseHoleEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CMouseHoleEnumVariables.f90 index 8cc5539..0763680 100644 --- a/CSharp/OperationScenarios/UnitySignals/CMouseHoleEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CMouseHoleEnumVariables.f90 @@ -1,12 +1,12 @@ module CMouseHoleEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: MouseHole = 0 integer :: MouseHole_S = 0 public - type(VoidEventHandlerCollection) :: OnMouseHoleChange + ! type(VoidEventHandlerCollection) :: OnMouseHoleChange enum, bind(c) enumerator MOUSE_HOLE_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/COperationConditionEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/COperationConditionEnumVariables.f90 index f6b8f71..87c1d68 100644 --- a/CSharp/OperationScenarios/UnitySignals/COperationConditionEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/COperationConditionEnumVariables.f90 @@ -1,13 +1,13 @@ module COperationConditionEnumVariables use CIntegerEventHandlerCollection - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: OperationCondition = 0 public - type(VoidEventHandlerCollection) :: OnOperationConditionChange - type(IntegerEventHandlerCollection) :: OnOperationConditionChangeInt + ! type(VoidEventHandlerCollection) :: OnOperationConditionChange + !**type(IntegerEventHandlerCollection) :: OnOperationConditionChangeInt enum, bind(c) enumerator OPERATION_DRILL diff --git a/CSharp/OperationScenarios/UnitySignals/CSafetyValveEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CSafetyValveEnumVariables.f90 index 7902e9c..fd89f0c 100644 --- a/CSharp/OperationScenarios/UnitySignals/CSafetyValveEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CSafetyValveEnumVariables.f90 @@ -1,12 +1,12 @@ module CSafetyValveEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: SafetyValve = 0 integer :: operation = 0 public - type(VoidEventHandlerCollection) :: OnSafetyValveChange + ! type(VoidEventHandlerCollection) :: OnSafetyValveChange enum, bind(c) enumerator SAFETY_VALVE_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CSlipsEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CSlipsEnumVariables.f90 index 2c5fc71..9af122e 100644 --- a/CSharp/OperationScenarios/UnitySignals/CSlipsEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CSlipsEnumVariables.f90 @@ -1,12 +1,12 @@ module CSlipsEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: Slips = 0 integer :: Slips_S = 0 public - type(VoidEventHandlerCollection) :: OnSlipsChange + ! type(VoidEventHandlerCollection) :: OnSlipsChange enum, bind(c) enumerator SLIPS_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CSwingEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CSwingEnumVariables.f90 index 27ca75c..548fb34 100644 --- a/CSharp/OperationScenarios/UnitySignals/CSwingEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CSwingEnumVariables.f90 @@ -1,5 +1,5 @@ module CSwingEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection use CLog4 implicit none integer :: Swing = 0 @@ -7,7 +7,7 @@ module CSwingEnumVariables public - type(VoidEventHandlerCollection) :: OnSwingChange + ! type(VoidEventHandlerCollection) :: OnSwingChange enum, bind(c) enumerator SWING_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsBackupClampVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CTdsBackupClampVariables.f90 index f8ed662..bf30119 100644 --- a/CSharp/OperationScenarios/UnitySignals/CTdsBackupClampVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CTdsBackupClampVariables.f90 @@ -1,11 +1,11 @@ module CTdsBackupClampVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: TdsBackupClamp = 0 public - type(VoidEventHandlerCollection) :: OnTdsBackupClampChange + ! type(VoidEventHandlerCollection) :: OnTdsBackupClampChange enum, bind(c) enumerator BACKUP_CLAMP_OFF_END diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnumVariables.f90 index 0d67708..f1e21ce 100644 --- a/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnumVariables.f90 @@ -1,12 +1,12 @@ module CTdsSpineEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection use CLog4 implicit none integer :: TdsSpine = 0 public - type(VoidEventHandlerCollection) :: OnTdsSpineChange + ! type(VoidEventHandlerCollection) :: OnTdsSpineChange enum, bind(c) enumerator TDS_SPINE_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnumVariables.f90 index c931f63..bcfeb62 100644 --- a/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnumVariables.f90 @@ -1,12 +1,12 @@ module CTdsSwingEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection use CLog4 implicit none integer :: TdsSwing = 0 public - type(VoidEventHandlerCollection) :: OnTdsSwingChange + ! type(VoidEventHandlerCollection) :: OnTdsSwingChange enum, bind(c) enumerator TDS_SWING_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsTongEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CTdsTongEnumVariables.f90 index b814a21..f2a0e4e 100644 --- a/CSharp/OperationScenarios/UnitySignals/CTdsTongEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CTdsTongEnumVariables.f90 @@ -1,11 +1,11 @@ module CTdsTongEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none integer :: TdsTong = 0 public - type(VoidEventHandlerCollection) :: OnTdsTongChange + ! type(VoidEventHandlerCollection) :: OnTdsTongChange enum, bind(c) enumerator TDS_TONG_BREAKOUT_END diff --git a/CSharp/OperationScenarios/UnitySignals/CTongEnumVariables.f90 b/CSharp/OperationScenarios/UnitySignals/CTongEnumVariables.f90 index a3ec977..267d4eb 100644 --- a/CSharp/OperationScenarios/UnitySignals/CTongEnumVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CTongEnumVariables.f90 @@ -1,5 +1,5 @@ module CTongEnumVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection use CLog4 implicit none integer :: Tong = 0 @@ -7,7 +7,7 @@ module CTongEnumVariables public - type(VoidEventHandlerCollection) :: OnTongChange + ! type(VoidEventHandlerCollection) :: OnTongChange enum, bind(c) enumerator TONG_NEUTRAL diff --git a/CSharp/OperationScenarios/UnitySignals/UnitySignalsVariables.f90 b/CSharp/OperationScenarios/UnitySignals/UnitySignalsVariables.f90 index 97287dd..124d36c 100644 --- a/CSharp/OperationScenarios/UnitySignals/UnitySignalsVariables.f90 +++ b/CSharp/OperationScenarios/UnitySignals/UnitySignalsVariables.f90 @@ -1,43 +1,43 @@ module UnitySignalVariables - use CVoidEventHandlerCollection - use CIntegerEventHandlerCollection + ! use CVoidEventHandlerCollection + ! use CIntegerEventHandlerCollection type:: UnitySignalsType integer :: MudBucket = 0 - type(VoidEventHandlerCollection) :: OnMudBucketChange + ! type(VoidEventHandlerCollection) :: OnMudBucketChange integer :: Elevator = 0 - type(VoidEventHandlerCollection) :: OnElevatorChange + ! type(VoidEventHandlerCollection) :: OnElevatorChange integer :: FillupHead = 0 - type(VoidEventHandlerCollection) :: OnFillupHeadChange + ! type(VoidEventHandlerCollection) :: OnFillupHeadChange integer :: Ibop = 0 - type(VoidEventHandlerCollection) :: OnIbopChange + ! type(VoidEventHandlerCollection) :: OnIbopChange integer :: Kelly = 0 - type(VoidEventHandlerCollection) :: OnKellyChange + ! type(VoidEventHandlerCollection) :: OnKellyChange integer :: MouseHole = 0 - type(VoidEventHandlerCollection) :: OnMouseHoleChange + ! type(VoidEventHandlerCollection) :: OnMouseHoleChange integer :: OperationCondition = 0 - type(VoidEventHandlerCollection) :: OnOperationConditionChange - type(IntegerEventHandlerCollection) :: OnOperationConditionChangeInt + ! type(VoidEventHandlerCollection) :: OnOperationConditionChange + ! !**type(IntegerEventHandlerCollection) :: OnOperationConditionChangeInt integer :: SafetyValve = 0 - type(VoidEventHandlerCollection) :: OnSafetyValveChange + ! type(VoidEventHandlerCollection) :: OnSafetyValveChange integer :: operation = 0 integer :: Slips = 0 integer :: Slips_S = 0 - type(VoidEventHandlerCollection) :: OnSlipsChange + ! type(VoidEventHandlerCollection) :: OnSlipsChange integer :: Swing = 0 integer :: Swing_S = 0 - type(VoidEventHandlerCollection) :: OnSwingChange + ! type(VoidEventHandlerCollection) :: OnSwingChange integer :: TdsBackupClamp = 0 - type(VoidEventHandlerCollection) :: OnTdsBackupClampChange + ! type(VoidEventHandlerCollection) :: OnTdsBackupClampChange integer :: TdsSpine = 0 - type(VoidEventHandlerCollection) :: OnTdsSpineChange + ! type(VoidEventHandlerCollection) :: OnTdsSpineChange integer :: TdsSwing = 0 - type(VoidEventHandlerCollection) :: OnTdsSwingChange + ! type(VoidEventHandlerCollection) :: OnTdsSwingChange integer :: TdsTong = 0 - type(VoidEventHandlerCollection) :: OnTdsTongChange + ! type(VoidEventHandlerCollection) :: OnTdsTongChange integer :: Tong = 0 integer :: Tong_S = 0 - type(VoidEventHandlerCollection) :: OnTongChange + ! type(VoidEventHandlerCollection) :: OnTongChange end type UnitySignalsType type(UnitySignalsType):: unitySignals @@ -160,7 +160,7 @@ module UnitySignalVariables #ifdef deb print*, 'Tong=', UnitySignals%Tong #endif - call UnitySignals%OnTongChange%RunAll() + !**call UnitySignals%OnTongChange%RunAll() end subroutine integer function Get_Tong() @@ -179,7 +179,7 @@ module UnitySignalVariables #ifdef deb print*, 'TdsTong=', UnitySignals%TdsTong #endif - call UnitySignals%OnTdsTongChange%RunAll() + !**call UnitySignals%OnTdsTongChange%RunAll() end subroutine integer function Get_TdsTong() @@ -198,7 +198,7 @@ module UnitySignalVariables #ifdef deb print*, 'TdsSwing=', UnitySignals%TdsSwing #endif - call UnitySignals%OnTdsSwingChange%RunAll() + !**call UnitySignals%OnTdsSwingChange%RunAll() end subroutine integer function Get_TdsSwing() @@ -217,7 +217,7 @@ module UnitySignalVariables #ifdef deb print*, 'TdsSpine=', UnitySignals%TdsSpine #endif - call UnitySignals%OnTdsSpineChange%RunAll() + !**call UnitySignals%OnTdsSpineChange%RunAll() end subroutine integer function Get_TdsSpine() @@ -236,7 +236,7 @@ module UnitySignalVariables #ifdef deb print*, 'TdsBackupClamp=', UnitySignals%TdsBackupClamp #endif - call UnitySignals%OnTdsBackupClampChange%RunAll() + !**call UnitySignals%OnTdsBackupClampChange%RunAll() end subroutine integer function Get_TdsBackupClamp() @@ -255,7 +255,7 @@ module UnitySignalVariables #ifdef deb print*, 'Swing=', UnitySignals%Swing #endif - call UnitySignals%OnSwingChange%RunAll() + !**call UnitySignals%OnSwingChange%RunAll() end subroutine integer function Get_Swing() @@ -274,7 +274,7 @@ module UnitySignalVariables #ifdef deb print*, 'Slips=', UnitySignals%Slips #endif - call UnitySignals%OnSlipsChange%RunAll() + !**call UnitySignals%OnSlipsChange%RunAll() end subroutine integer function Get_Slips() @@ -304,7 +304,7 @@ module UnitySignalVariables print*, 'SafetyValve=SAFETY_VALVE_REMOVE' endif #endif - call UnitySignals%OnSafetyValveChange%RunAll() + !**call UnitySignals%OnSafetyValveChange%RunAll() end subroutine integer function Get_SafetyValve() @@ -334,8 +334,8 @@ module UnitySignalVariables #ifdef deb print*, 'OperationCondition=', UnitySignals%OperationCondition #endif - call UnitySignals%OnOperationConditionChange%RunAll() - call UnitySignals%OnOperationConditionChangeInt%RunAll(UnitySignals%OperationCondition) + !**call UnitySignals%OnOperationConditionChange%RunAll() + !**call UnitySignals%OnOperationConditionChangeInt%RunAll(UnitySignals%OperationCondition) end subroutine integer function Get_OperationCondition() @@ -355,7 +355,7 @@ module UnitySignalVariables #ifdef deb print*, 'MouseHole=', UnitySignals%MouseHole #endif - call UnitySignals%OnMouseHoleChange%RunAll() + !**call UnitySignals%OnMouseHoleChange%RunAll() end subroutine integer function Get_MouseHole() @@ -375,7 +375,7 @@ module UnitySignalVariables #ifdef deb print*, 'Kelly=', UnitySignals%Kelly #endif - call UnitySignals%OnKellyChange%RunAll() + !**call UnitySignals%OnKellyChange%RunAll() end subroutine integer function Get_Kelly() @@ -394,7 +394,7 @@ module UnitySignalVariables #ifdef deb print*, 'Ibop=', UnitySignals%Ibop #endif - call UnitySignals%OnIbopChange%RunAll() + !**call UnitySignals%OnIbopChange%RunAll() end subroutine integer function Get_Ibop() @@ -421,7 +421,7 @@ module UnitySignalVariables #ifdef deb print*, 'FillupHead=', UnitySignals%FillupHead #endif - call UnitySignals%OnFillupHeadChange%RunAll() + !**call UnitySignals%OnFillupHeadChange%RunAll() end subroutine integer function Get_FillupHead() @@ -440,7 +440,7 @@ module UnitySignalVariables #ifdef deb print*, 'Elevator=', UnitySignals%Elevator #endif - call UnitySignals%OnElevatorChange%RunAll() + !**call UnitySignals%OnElevatorChange%RunAll() end subroutine integer function Get_Elevator() @@ -466,7 +466,7 @@ module UnitySignalVariables #ifdef deb print*, 'MudBucket=', UnitySignals%MudBucket #endif - call UnitySignals%OnMudBucketChange%RunAll() + !**call UnitySignals%OnMudBucketChange%RunAll() end subroutine integer function Get_MudBucket() diff --git a/CSharp/Problems/CBitProblemsVariables.f90 b/CSharp/Problems/CBitProblemsVariables.f90 index cc08cef..96a3b04 100644 --- a/CSharp/Problems/CBitProblemsVariables.f90 +++ b/CSharp/Problems/CBitProblemsVariables.f90 @@ -54,21 +54,21 @@ module CBitProblemsVariables end subroutine subroutine ChangePlugJets(status) - USE FricPressDropVars + USE FricPressDropVarsModule implicit none integer, intent (in) :: status ! if(associated(BitProblems%PlugJetsPtr)) call BitProblems%PlugJetsPtr(status) - if(status == Clear_StatusType) BitJetsPlugged = 0 - if(status == Executed_StatusType) BitJetsPlugged = 1 + if(status == Clear_StatusType) FricPressDropVars%BitJetsPlugged = 0 + if(status == Executed_StatusType) FricPressDropVars%BitJetsPlugged = 1 endsubroutine subroutine ChangeJetWashout(status) - USE FricPressDropVars + USE FricPressDropVarsModule implicit none integer, intent (in) :: status ! if(associated(BitProblems%JetWashoutPtr)) call BitProblems%JetWashoutPtr(status) - if(status == Clear_StatusType) BitJetsWashedOut = 0 - if(status == Executed_StatusType) BitJetsWashedOut = 1 + if(status == Clear_StatusType) FricPressDropVars%BitJetsWashedOut = 0 + if(status == Executed_StatusType) FricPressDropVars%BitJetsWashedOut = 1 endsubroutine diff --git a/CSharp/Problems/CChokeProblemsVariables.f90 b/CSharp/Problems/CChokeProblemsVariables.f90 index bf1ffc7..1145b48 100644 --- a/CSharp/Problems/CChokeProblemsVariables.f90 +++ b/CSharp/Problems/CChokeProblemsVariables.f90 @@ -179,12 +179,12 @@ module CChokeProblemsVariables endsubroutine subroutine ChangeManualChoke1Plugged(status) - USE FricPressDropVars + USE FricPressDropVarsModule implicit none integer, intent (in) :: status ! if(associated(ManualChoke1PluggedPtr)) call ManualChoke1PluggedPtr(status) - if(status == Clear_StatusType) ManChoke1Plug = 0 - if(status == Executed_StatusType) ManChoke1Plug = 1 + if(status == Clear_StatusType) FricPressDropVars%ManChoke1Plug = 0 + if(status == Executed_StatusType) FricPressDropVars%ManChoke1Plug = 1 endsubroutine subroutine ChangeManualChoke1Fail(status) @@ -196,25 +196,25 @@ module CChokeProblemsVariables endsubroutine subroutine ChangeManualChoke1Washout(status) - USE FricPressDropVars + USE FricPressDropVarsModule use CChokeManifoldVariables implicit none integer, intent (in) :: status ! if(associated(ManualChoke1WashoutPtr)) call ManualChoke1WashoutPtr(status) - if(status == Clear_StatusType) ManChoke1Washout = 0 - if(status == Executed_StatusType) ManChoke1Washout = 1 + if(status == Clear_StatusType) FricPressDropVars%ManChoke1Washout = 0 + if(status == Executed_StatusType) FricPressDropVars%ManChoke1Washout = 1 if(status == Clear_StatusType) ChokeManifold%LeftManChokeOnProblem = .false. if(status == Executed_StatusType) ChokeManifold%LeftManChokeOnProblem = .true. endsubroutine subroutine ChangeManualChoke2Plugged(status) - USE FricPressDropVars + USE FricPressDropVarsModule implicit none integer, intent (in) :: status ! if(associated(ManualChoke2PluggedPtr)) call ManualChoke2PluggedPtr(status) - if(status == Clear_StatusType) ManChoke2Plug = 0 - if(status == Executed_StatusType) ManChoke2Plug = 1 + if(status == Clear_StatusType) FricPressDropVars%ManChoke2Plug = 0 + if(status == Executed_StatusType) FricPressDropVars%ManChoke2Plug = 1 endsubroutine subroutine ChangeManualChoke2Fail(status) @@ -226,13 +226,13 @@ module CChokeProblemsVariables endsubroutine subroutine ChangeManualChoke2Washout(status) - USE FricPressDropVars + USE FricPressDropVarsModule use CChokeManifoldVariables implicit none integer, intent (in) :: status ! if(associated(ManualChoke2WashoutPtr)) call ManualChoke2WashoutPtr(status) - if(status == Clear_StatusType) ManChoke2Washout = 0 - if(status == Executed_StatusType) ManChoke2Washout = 1 + if(status == Clear_StatusType) FricPressDropVars%ManChoke2Washout = 0 + if(status == Executed_StatusType) FricPressDropVars%ManChoke2Washout = 1 if(status == Clear_StatusType) ChokeManifold%RightManChokeOnProblem = .false. if(status == Executed_StatusType) ChokeManifold%RightManChokeOnProblem = .true. diff --git a/CSharp/Problems/CGaugesProblemsVariables.f90 b/CSharp/Problems/CGaugesProblemsVariables.f90 index c49a2bb..bdcb5b8 100644 --- a/CSharp/Problems/CGaugesProblemsVariables.f90 +++ b/CSharp/Problems/CGaugesProblemsVariables.f90 @@ -215,12 +215,12 @@ module CGaugesProblemsVariables endsubroutine subroutine ChangeCasingPressure(status) - USE FricPressDropVars + USE FricPressDropVarsModule implicit none integer, intent (in) :: status ! if(associated(CasingPressurePtr)) call CasingPressurePtr(status) - if(status == Clear_StatusType) CasingPressure_DataDisplayMalF = 0 - if(status == Executed_StatusType) CasingPressure_DataDisplayMalF = 1 + if(status == Clear_StatusType) FricPressDropVars%CasingPressure_DataDisplayMalF = 0 + if(status == Executed_StatusType) FricPressDropVars%CasingPressure_DataDisplayMalF = 1 endsubroutine subroutine ChangePump1Strokes(status) @@ -373,12 +373,12 @@ module CGaugesProblemsVariables endsubroutine subroutine ChangeCasingPressure2(status) - use FricPressDropVars + USE FricPressDropVarsModule implicit none integer, intent (in) :: status ! if(associated(CasingPressure2Ptr)) call CasingPressure2Ptr(status) - if(status == Clear_StatusType) CasingPressure_ChokeMalF = 0 - if(status == Executed_StatusType) CasingPressure_ChokeMalF = 1 + if(status == Clear_StatusType) FricPressDropVars%CasingPressure_ChokeMalF = 0 + if(status == Executed_StatusType) FricPressDropVars%CasingPressure_ChokeMalF = 1 endsubroutine diff --git a/CSharp/StudentStation/CStudentStationVariables.f90 b/CSharp/StudentStation/CStudentStationVariables.f90 index 23ec1e3..21531dc 100644 --- a/CSharp/StudentStation/CStudentStationVariables.f90 +++ b/CSharp/StudentStation/CStudentStationVariables.f90 @@ -1,5 +1,5 @@ module CStudentStationVariables - use CVoidEventHandlerCollection + ! use CVoidEventHandlerCollection implicit none public @@ -11,12 +11,12 @@ module CStudentStationVariables logical :: TapSelector end type StudentStationType type(StudentStationType)::StudentStation - ! type(VoidEventHandlerCollection) :: OnStudentStation%FillupHeadInstallationPress - ! type(VoidEventHandlerCollection) :: OnFillupHeadRemovePress + ! ! type(VoidEventHandlerCollection) :: OnStudentStation%FillupHeadInstallationPress + ! ! type(VoidEventHandlerCollection) :: OnFillupHeadRemovePress - ! type(VoidEventHandlerCollection) :: OnMudBoxInstallationPress - ! type(VoidEventHandlerCollection) :: + ! ! type(VoidEventHandlerCollection) :: OnMudBoxInstallationPress + ! ! type(VoidEventHandlerCollection) :: diff --git a/CSimulationVariables.f90 b/CSimulationVariables.f90 deleted file mode 100644 index a97c8c1..0000000 --- a/CSimulationVariables.f90 +++ /dev/null @@ -1,1211 +0,0 @@ -module CSimulationVariables - use CVoidEventHandlerCollection - ! use CSimulationThreads - use CIActionReference - ! use ifcore - ! use ifmt - ! use CTimer - use CError - use CLog3 - implicit none - public - - integer, parameter :: SimulationState_Stopped = 0; - integer, parameter :: SimulationState_Started = 1; - integer, parameter :: SimulationState_Paused = 2; - - logical :: IsStopped = .false. - logical :: IsSnapshot = .false. - logical :: IsPortable = .false. - integer :: IsPortableInt = 0 - - integer :: SimulationState_old - integer :: SimulationState - integer :: SimulationTime - integer :: SimulationSpeed ! 1, 2, 5, 10 - - integer :: SleepLimit = 0 - - integer :: TotalPumpStrokes - real(8) :: TotalVolumePumped - real(8) :: DistanceDrilled - - type(VoidEventHandlerCollection) :: OnSimulationInitialization - type(VoidEventHandlerCollection) :: OnSimulationStart - type(VoidEventHandlerCollection) :: OnSimulationStop - type(VoidEventHandlerCollection) :: OnSimulationPause - !type(VoidEventHandlerCollection) :: OnSimulationGetOutput - - procedure (ActionVoid), pointer :: ForceRealTimeSpeedPtr - procedure (ActionBool), pointer :: SpeedChangePossibilityPtr - logical :: SpeedChangePossibilityValue - - procedure (ActionInteger), pointer :: TotalStrokesChangedPtr - procedure (ActionInteger), pointer :: TotalStrokesPtr - procedure (ActionDouble), pointer :: TotalVolumePumpedPtr - procedure (ActionDouble), pointer :: DistanceDrilledPtr - - ! modules... - !BopStack - type(VoidEventHandlerCollection) :: OnBopStackStep - type(VoidEventHandlerCollection) :: OnBopStackStart - type(VoidEventHandlerCollection) :: OnBopStackOutput - type(VoidEventHandlerCollection) :: OnBopStackPause - type(VoidEventHandlerCollection) :: OnBopStackMain - logical :: BopStackStarted - - !Pumps - type(VoidEventHandlerCollection) :: OnPump1Step - type(VoidEventHandlerCollection) :: OnPump1Start - type(VoidEventHandlerCollection) :: OnPump1Output - type(VoidEventHandlerCollection) :: OnPump1Pause - type(VoidEventHandlerCollection) :: OnPump1Main - logical :: Pump1Started - - type(VoidEventHandlerCollection) :: OnPump2Step - type(VoidEventHandlerCollection) :: OnPump2Start - type(VoidEventHandlerCollection) :: OnPump2Output - type(VoidEventHandlerCollection) :: OnPump2Pause - type(VoidEventHandlerCollection) :: OnPump2Main - logical :: Pump2Started - - type(VoidEventHandlerCollection) :: OnPump3Step - type(VoidEventHandlerCollection) :: OnPump3Start - type(VoidEventHandlerCollection) :: OnPump3Output - type(VoidEventHandlerCollection) :: OnPump3Pause - type(VoidEventHandlerCollection) :: OnPump3Main - logical :: Pump3Started - - !ChokeControl - type(VoidEventHandlerCollection) :: OnChokeControlStep - type(VoidEventHandlerCollection) :: OnChokeControlStart - type(VoidEventHandlerCollection) :: OnChokeControlOutput - type(VoidEventHandlerCollection) :: OnChokeControlPause - type(VoidEventHandlerCollection) :: OnChokeControlMain - logical :: ChokeControlStarted - - !ROP - type(VoidEventHandlerCollection) :: OnRopStep - type(VoidEventHandlerCollection) :: OnRopStart - type(VoidEventHandlerCollection) :: OnRopOutput - type(VoidEventHandlerCollection) :: OnRopPause - type(VoidEventHandlerCollection) :: OnRopMain - logical :: RopStarted - - !RotaryTable - type(VoidEventHandlerCollection) :: OnRotaryTableStep - type(VoidEventHandlerCollection) :: OnRotaryTableStart - type(VoidEventHandlerCollection) :: OnRotaryTableOutput - type(VoidEventHandlerCollection) :: OnRotaryTablePause - type(VoidEventHandlerCollection) :: OnRotaryTableMain - logical :: RotaryTableStarted - - !Drawworks - type(VoidEventHandlerCollection) :: OnDrawworksStep - type(VoidEventHandlerCollection) :: OnDrawworksStart - type(VoidEventHandlerCollection) :: OnDrawworksOutput - type(VoidEventHandlerCollection) :: OnDrawworksPause - type(VoidEventHandlerCollection) :: OnDrawworksMain - logical :: DrawworksStarted - - !FluidFlow - type(VoidEventHandlerCollection) :: OnFluidFlowStep - type(VoidEventHandlerCollection) :: OnFluidFlowStart - type(VoidEventHandlerCollection) :: OnFluidFlowOutput - type(VoidEventHandlerCollection) :: OnFluidFlowPause - type(VoidEventHandlerCollection) :: OnFluidFlowMain - logical :: FluidFlowStarted - - !TorqueDrag - type(VoidEventHandlerCollection) :: OnTorqueDragStep - type(VoidEventHandlerCollection) :: OnTorqueDragStart - type(VoidEventHandlerCollection) :: OnTorqueDragOutput - type(VoidEventHandlerCollection) :: OnTorqueDragPause - type(VoidEventHandlerCollection) :: OnTorqueDragMain - logical :: TorqueDragStarted - - - !TopDrive - type(VoidEventHandlerCollection) :: OnTopDriveStep - type(VoidEventHandlerCollection) :: OnTopDriveStart - type(VoidEventHandlerCollection) :: OnTopDriveOutput - type(VoidEventHandlerCollection) :: OnTopDrivePause - type(VoidEventHandlerCollection) :: OnTopDriveMain - logical :: TopDriveStarted - - - !MudSystem - type(VoidEventHandlerCollection) :: OnMudSystemStep - type(VoidEventHandlerCollection) :: OnMudSystemStart - type(VoidEventHandlerCollection) :: OnMudSystemOutput - type(VoidEventHandlerCollection) :: OnMudSystemPause - type(VoidEventHandlerCollection) :: OnMudSystemMain - logical :: MudSystemStarted - - !PipeRams1 - type(VoidEventHandlerCollection) :: OnPipeRams1Step - type(VoidEventHandlerCollection) :: OnPipeRams1Start - type(VoidEventHandlerCollection) :: OnPipeRams1Output - type(VoidEventHandlerCollection) :: OnPipeRams1Pause - type(VoidEventHandlerCollection) :: OnPipeRams1Main - logical :: PipeRams1Started - - !PipeRams2 - type(VoidEventHandlerCollection) :: OnPipeRams2Step - type(VoidEventHandlerCollection) :: OnPipeRams2Start - type(VoidEventHandlerCollection) :: OnPipeRams2Output - type(VoidEventHandlerCollection) :: OnPipeRams2Pause - type(VoidEventHandlerCollection) :: OnPipeRams2Main - logical :: PipeRams2Started - - !KillLine - type(VoidEventHandlerCollection) :: OnKillLineStep - type(VoidEventHandlerCollection) :: OnKillLineStart - type(VoidEventHandlerCollection) :: OnKillLineOutput - type(VoidEventHandlerCollection) :: OnKillLinePause - type(VoidEventHandlerCollection) :: OnKillLineMain - logical :: KillLineStarted - - !ChokeLine - type(VoidEventHandlerCollection) :: OnChokeLineStep - type(VoidEventHandlerCollection) :: OnChokeLineStart - type(VoidEventHandlerCollection) :: OnChokeLineOutput - type(VoidEventHandlerCollection) :: OnChokeLinePause - type(VoidEventHandlerCollection) :: OnChokeLineMain - logical :: ChokeLineStarted - - !BlindRams - type(VoidEventHandlerCollection) :: OnBlindRamsStep - type(VoidEventHandlerCollection) :: OnBlindRamsStart - type(VoidEventHandlerCollection) :: OnBlindRamsOutput - type(VoidEventHandlerCollection) :: OnBlindRamsPause - type(VoidEventHandlerCollection) :: OnBlindRamsMain - logical :: BlindRamsStarted - - !Annular - type(VoidEventHandlerCollection) :: OnAnnularStep - type(VoidEventHandlerCollection) :: OnAnnularStart - type(VoidEventHandlerCollection) :: OnAnnularOutput - type(VoidEventHandlerCollection) :: OnAnnularPause - type(VoidEventHandlerCollection) :: OnAnnularMain - logical :: AnnularStarted - - !Geo - type(VoidEventHandlerCollection) :: OnGeoStep - type(VoidEventHandlerCollection) :: OnGeoStart - type(VoidEventHandlerCollection) :: OnGeoOutput - type(VoidEventHandlerCollection) :: OnGeoPause - type(VoidEventHandlerCollection) :: OnGeoMain - logical :: GeoStarted - - - - - - !OperationScenarios - type(VoidEventHandlerCollection) :: OnOperationScenariosStep - type(VoidEventHandlerCollection) :: OnOperationScenariosOutput - type(VoidEventHandlerCollection) :: OnOperationScenariosPause - type(VoidEventHandlerCollection) :: OnOperationScenariosMain - - !PathFinding - type(VoidEventHandlerCollection) :: OnPathFindingStep - type(VoidEventHandlerCollection) :: OnPathFindingOutput - type(VoidEventHandlerCollection) :: OnPathFindingPause - type(VoidEventHandlerCollection) :: OnPathFindingMain - - ! sample - type(VoidEventHandlerCollection) :: OnSampleStep - type(VoidEventHandlerCollection) :: OnSampleStart - type(VoidEventHandlerCollection) :: OnSampleOutput - type(VoidEventHandlerCollection) :: OnSamplePause - type(VoidEventHandlerCollection) :: OnSampleMain - logical :: SampleStarted - - !!MudFlowFillIndicator - !type(VoidEventHandlerCollection) :: OnMudFlowFillIndicatorStep - !type(VoidEventHandlerCollection) :: OnMudFlowFillIndicatorOutput - !type(VoidEventHandlerCollection) :: OnMudFlowFillIndicatorMain - - - - - - - - - - - - - - contains - - ! subroutine Quit() - ! use ifmt - ! call ExitThread(0) - ! end subroutine - - real function GetSimulationSpeedSecond() - implicit none - GetSimulationSpeedSecond = 1.0 / SimulationSpeed - end function GetSimulationSpeedSecond - - integer function GetSimulationSpeedMilisecond() - implicit none - GetSimulationSpeedMilisecond = int(GetSimulationSpeedSecond()* 1000.0) - end function GetSimulationSpeedMilisecond - - subroutine DrillMode_ON() - implicit none - call SpeedChangePossibility(.true.) - end subroutine - - subroutine DrillMode_OFF() - implicit none - call ForceRealTimeSpeed() - call SpeedChangePossibility(.false.) - end subroutine - - subroutine ForceRealTimeSpeed() - implicit none - if(associated(ForceRealTimeSpeedPtr)) call ForceRealTimeSpeedPtr() - end subroutine - - subroutine SpeedChangePossibility(v) - implicit none - logical, intent(in) :: v - SpeedChangePossibilityValue = v - if(associated(SpeedChangePossibilityPtr)) call SpeedChangePossibilityPtr(SpeedChangePossibilityValue) - end subroutine - - subroutine SubscribeSpeedChangePossibility(a) - !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeSpeedChangePossibility - !DEC$ ATTRIBUTES ALIAS: 'SubscribeSpeedChangePossibility' :: SubscribeSpeedChangePossibility - implicit none - procedure (ActionBool) :: a - SpeedChangePossibilityPtr => a - end subroutine - - subroutine SubscribeForceRealTimeSpeed(a) - !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeForceRealTimeSpeed - !DEC$ ATTRIBUTES ALIAS: 'SubscribeForceRealTimeSpeed' :: SubscribeForceRealTimeSpeed - implicit none - procedure (ActionVoid) :: a - ForceRealTimeSpeedPtr => a - end subroutine - - subroutine SubscribeTotalStrokesChanged(a) - !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeTotalStrokesChanged - !DEC$ ATTRIBUTES ALIAS: 'SubscribeTotalStrokesChanged' :: SubscribeTotalStrokesChanged - implicit none - procedure (ActionInteger) :: a - TotalStrokesChangedPtr => a - end subroutine - - subroutine SetTotalStrokes(strokes) - implicit none - integer, intent(in) :: strokes - if (TotalPumpStrokes == strokes) return - TotalPumpStrokes = strokes - if(associated(TotalStrokesChangedPtr)) call TotalStrokesChangedPtr(TotalPumpStrokes) - if(associated(TotalStrokesPtr)) call TotalStrokesPtr(TotalPumpStrokes) - end subroutine - - subroutine SetTotalVolumePumped(volume) - implicit none - real(8), intent(in) :: volume - if (TotalVolumePumped == volume) return - TotalVolumePumped = volume - if(associated(TotalVolumePumpedPtr)) call TotalVolumePumpedPtr(TotalVolumePumped) - end subroutine - - subroutine SetDistanceDrilled(distance) - implicit none - real(8), intent(in) :: distance - if (DistanceDrilled == distance) return - DistanceDrilled = distance - if(associated(DistanceDrilledPtr)) call DistanceDrilledPtr(DistanceDrilled) - end subroutine - -! integer(4) function BopStackThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_bopstackthread" :: BopStackThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_BopStack -! call OnBopStackMain%RunAll() -! #endif -! #ifdef S_BopStack -! if(.not.BopStackStarted) then -! call OnBopStackStart%RunAll() -! BopStackStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnBopStackStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('BOP Stack Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnBopStackOutput%RunAll() -! end do -! call OnBopStackPause%RunAll() -! end do loop -! #endif -! BopStackThread = 0; -! call ExitThread(0) -! end function BopStackThread - -! integer(4) function Pump1Thread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_pump1thread" :: Pump1Thread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_Pump1 -! call OnPump1Main%RunAll() -! #endif -! #ifdef S_Pump1 -! if(.not.Pump1Started) then -! call OnPump1Start%RunAll() -! Pump1Started = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnPump1Step%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Pump 1 Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnPump1Output%RunAll() -! end do -! call OnPump1Pause%RunAll() -! end do loop -! #endif -! Pump1Thread = 0; -! call ExitThread(0) -! end function Pump1Thread - -! integer(4) function Pump2Thread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_pump2thread" :: Pump2Thread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_Pump2 -! call OnPump2Main%RunAll() -! #endif -! #ifdef S_Pump2 -! if(.not.Pump2Started) then -! call OnPump2Start%RunAll() -! Pump2Started = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnPump2Step%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Pump 2 Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnPump2Output%RunAll() -! end do -! call OnPump2Pause%RunAll() -! end do loop -! #endif -! Pump2Thread = 0; -! call ExitThread(0) -! end function Pump2Thread - -! integer(4) function Pump3Thread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_pump3thread" :: Pump3Thread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_Pump3 -! call OnPump3Main%RunAll() -! #endif -! #ifdef S_Pump3 -! if(.not.Pump3Started) then -! call OnPump3Start%RunAll() -! Pump3Started = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnPump3Step%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Pump 3 Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnPump3Output%RunAll() -! end do -! call OnPump3Pause%RunAll() -! end do loop -! #endif -! Pump3Thread = 0; -! call ExitThread(0) -! end function Pump3Thread - -! integer(4) function ChokeControlThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_chokecontrolthread" :: ChokeControlThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_ChokeControl -! call OnChokeControlMain%RunAll() -! #endif -! #ifdef S_ChokeControl -! if(.not.ChokeControlStarted) then -! call OnChokeControlStart%RunAll() -! ChokeControlStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnChokeControlStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Choke Control Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnChokeControlOutput%RunAll() -! end do -! call OnChokeControlPause%RunAll() -! end do loop -! #endif -! ChokeControlThread = 0; -! call ExitThread(0) -! end function ChokeControlThread - -! integer(4) function RopThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_ropthread" :: RopThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_Rop -! call OnRopMain%RunAll() -! #endif -! #ifdef S_Rop -! if(.not.RopStarted) then -! call OnRopStart%RunAll() -! RopStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnRopStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('ROP Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnRopOutput%RunAll() -! end do -! call OnRopPause%RunAll() -! end do loop -! #endif -! RopThread = 0; -! call ExitThread(0) -! end function RopThread - -! integer(4) function RotaryTableThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_rotarytablethread" :: RotaryTableThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_RotaryTable -! call OnRotaryTableMain%RunAll() -! #endif -! #ifdef S_RotaryTable -! if(.not.RotaryTableStarted) then -! call OnRotaryTableStart%RunAll() -! RotaryTableStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnRotaryTableStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Rotary Table Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnRotaryTableOutput%RunAll() -! end do -! call OnRotaryTablePause%RunAll() -! end do loop -! #endif -! RotaryTableThread = 0; -! call ExitThread(0) -! end function RotaryTableThread - -! integer(4) function DrawworksThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_drawworksthread" :: DrawworksThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_Drawworks -! call OnDrawworksMain%RunAll() -! #endif -! #ifdef S_Drawworks -! if(.not.DrawworksStarted) then -! call OnDrawworksStart%RunAll() -! DrawworksStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnDrawworksStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Drawworks Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnDrawworksOutput%RunAll() -! end do -! call OnDrawworksPause%RunAll() -! end do loop -! #endif -! DrawworksThread = 0; -! call ExitThread(0) -! end function DrawworksThread - -! integer(4) function FluidFlowThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_fluidflowthread" :: FluidFlowThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_FluidFlow -! call OnFluidFlowMain%RunAll() -! #endif -! #ifdef S_FluidFlow -! if(.not.FluidFlowStarted) then -! call OnFluidFlowStart%RunAll() -! FluidFlowStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnFluidFlowStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Fluid Flow Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnFluidFlowOutput%RunAll() -! end do -! call OnFluidFlowPause%RunAll() -! end do loop -! #endif -! FluidFlowThread = 0; -! call ExitThread(0) -! end function FluidFlowThread - -! integer(4) function TorqueDragThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_torquedragthread" :: TorqueDragThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_TorqueDrag -! call OnTorqueDragMain%RunAll() -! #endif -! #ifdef S_TorqueDrag -! if(.not.TorqueDragStarted) then -! call OnTorqueDragStart%RunAll() -! TorqueDragStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnTorqueDragStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Torque Drag Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnTorqueDragOutput%RunAll() -! end do -! call OnTorqueDragPause%RunAll() -! end do loop -! #endif -! TorqueDragThread = 0; -! call ExitThread(0) -! end function TorqueDragThread - - -! integer(4) function TopDriveThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_topdrivethread" :: TopDriveThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_TopDrive -! call OnTopDriveMain%RunAll() -! #endif -! #ifdef S_TopDrive -! if(.not.TopDriveStarted) then -! call OnTopDriveStart%RunAll() -! TopDriveStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnTopDriveStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('TopDrive Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnTopDriveOutput%RunAll() -! end do -! call OnTopDrivePause%RunAll() -! end do loop -! #endif -! TopDriveThread = 0; -! call ExitThread(0) -! end function TopDriveThread - - -! integer(4) function MudSystemThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_MudSystemthread" :: MudSystemThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_MudSystem -! call OnMudSystemMain%RunAll() -! #endif -! #ifdef S_MudSystem -! if(.not.MudSystemStarted) then -! call OnMudSystemStart%RunAll() -! MudSystemStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnMudSystemStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Mud System Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnMudSystemOutput%RunAll() -! end do -! call OnMudSystemPause%RunAll() -! end do loop -! #endif -! MudSystemThread = 0; -! call ExitThread(0) -! end function MudSystemThread - -! integer(4) function PipeRams1Thread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_piperams1thread" :: PipeRams1Thread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_PipeRams1 -! call OnPipeRams1Main%RunAll() -! #endif -! #ifdef S_PipeRams1 -! if(.not.PipeRams1Started) then -! call OnPipeRams1Start%RunAll() -! PipeRams1Started = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnPipeRams1Step%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Pipe Rams 1 Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnPipeRams1Output%RunAll() -! end do -! call OnPipeRams1Pause%RunAll() -! end do loop -! #endif -! PipeRams1Thread = 0; -! call ExitThread(0) -! end function PipeRams1Thread - -! integer(4) function PipeRams2Thread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_piperams2thread" :: PipeRams2Thread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_PipeRams2 -! call OnPipeRams2Main%RunAll() -! #endif -! #ifdef S_PipeRams2 -! if(.not.PipeRams2Started) then -! call OnPipeRams2Start%RunAll() -! PipeRams2Started = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnPipeRams2Step%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Pipe Rams 2 Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnPipeRams2Output%RunAll() -! end do -! call OnPipeRams2Pause%RunAll() -! end do loop -! #endif -! PipeRams2Thread = 0; -! call ExitThread(0) -! end function PipeRams2Thread - -! integer(4) function KillLineThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_killlinethread" :: KillLineThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_KillLine -! call OnKillLineMain%RunAll() -! #endif -! #ifdef S_KillLine -! if(.not.KillLineStarted) then -! call OnKillLineStart%RunAll() -! KillLineStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnKillLineStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Kill Line Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnKillLineOutput%RunAll() -! end do -! call OnKillLinePause%RunAll() -! end do loop -! #endif -! KillLineThread = 0; -! call ExitThread(0) -! end function KillLineThread - -! integer(4) function ChokeLineThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_chokelinethread" :: ChokeLineThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_ChokeLine -! call OnChokeLineMain%RunAll() -! #endif -! #ifdef S_ChokeLine -! if(.not.ChokeLineStarted) then -! call OnChokeLineStart%RunAll() -! ChokeLineStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnChokeLineStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Choke Line Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnChokeLineOutput%RunAll() -! end do -! call OnChokeLinePause%RunAll() -! end do loop -! #endif -! ChokeLineThread = 0; -! call ExitThread(0) -! end function ChokeLineThread - -! integer(4) function BlindRamsThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_blindramsthread" :: BlindRamsThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_BlindRams -! call OnBlindRamsMain%RunAll() -! #endif -! #ifdef S_BlindRams -! if(.not.BlindRamsStarted) then -! call OnBlindRamsStart%RunAll() -! BlindRamsStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnBlindRamsStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Blind Rams Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnBlindRamsOutput%RunAll() -! end do -! call OnBlindRamsPause%RunAll() -! end do loop -! #endif -! BlindRamsThread = 0; -! call ExitThread(0) -! end function BlindRamsThread - -! integer(4) function AnnularThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_annularthread" :: AnnularThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_Annular -! call OnAnnularMain%RunAll() -! #endif -! #ifdef S_Annular -! if(.not.AnnularStarted) then -! call OnAnnularStart%RunAll() -! AnnularStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnAnnularStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Annular Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnAnnularOutput%RunAll() -! end do -! call OnAnnularPause%RunAll() -! end do loop -! #endif -! AnnularThread = 0; -! call ExitThread(0) -! end function AnnularThread - -! integer(4) function GeoThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_geothread" :: GeoThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_Geo -! call OnGeoMain%RunAll() -! #endif -! #ifdef S_Geo -! if(.not.GeoStarted) then -! call OnGeoStart%RunAll() -! GeoStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnGeoStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Geo Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnGeoOutput%RunAll() -! end do -! call OnGeoPause%RunAll() -! end do loop -! #endif -! GeoThread = 0; -! call ExitThread(0) -! end function GeoThread - - - -! integer(4) function OperationScenariosThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_operationscenariosthread" :: OperationScenariosThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! call OnOperationScenariosMain%RunAll() -! OperationScenariosThread = 0; -! call ExitThread(0) -! end function OperationScenariosThread - -! integer(4) function PathFindingThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_pathfindingthread" :: PathFindingThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! call OnPathFindingMain%RunAll() -! PathFindingThread = 0; -! call ExitThread(0) -! end function PathFindingThread - - - - - - - - - - - - - - -! integer(4) function SampleThread(arg) -! !DEC$ ATTRIBUTES STDCALL, ALIAS:"_samplethread" :: SampleThread -! use ifport -! use ifmt -! implicit none -! integer(4), pointer :: arg -! integer i, j -! integer elapsed, speed, remaining -! type(Timer) t -! #ifdef M_Sample -! call OnSampleMain%RunAll() -! #endif -! #ifdef S_Sample -! if(.not.SampleStarted) then -! call OnSampleStart%RunAll() -! SampleStarted = .true. -! end if -! loop: do -! if(IsStopped) call ExitThread(0) -! do i=1, 10 -! if(IsStopped) call ExitThread(0) -! call t%Start() -! do j=1, SimulationSpeed -! if(IsStopped) call ExitThread(0) -! call OnSampleStep%RunAll() -! end do -! call t%Finish() -! elapsed = t%ElapsedTimeMs() -! remaining = 100 - elapsed -! #ifdef E_SpeedWatchdog -! if(elapsed > 100) call Error('Sample Module: exceeding more than 100ms interval, the time was ', elapsed) -! #endif -! if(remaining > 0 .and. i < 10) call sleepqq(remaining - SleepLimit) -! call OnSampleOutput%RunAll() -! end do -! call OnSamplePause%RunAll() -! end do loop - -! #endif -! SampleThread = 0; -! call ExitThread(0) -! end function SampleThread - -end module CSimulationVariables \ No newline at end of file diff --git a/Equipments/BopStack/ANNULAR.f90 b/Equipments/BopStack/ANNULAR.f90 index 6ec43f0..f8d63e7 100644 --- a/Equipments/BopStack/ANNULAR.f90 +++ b/Equipments/BopStack/ANNULAR.f90 @@ -1,7 +1,7 @@ SUBROUTINE ANNULAR_SUB1 USE VARIABLES USE CBopControlPanelVariables - USE PressureDisplayVARIABLES + use PressureDisplayVARIABLESModule USE CEquipmentsConstants USE CBopStackVariables @@ -125,7 +125,7 @@ SUBROUTINE ANNULAR_SUB1 if (RAM(1)%FourwayValve == 1 .and. Annular%Pannular_reg>AnnularComputational%AnnularMovingPressure .and. RamLine%P_ACC>BopStackAcc%acc_MinPressure & - .and. (Annular%Annular_closed==0 .or. (Annular%Annular_closed==1 .and.PressureGauges(2) <=100.0) .or. (Annular%Annular_closed==1 .and.PressureGauges(2)>100.0 .and. Annular%Pannular_reg>=AnnularComputational%AnnularSealingPressure))) then ! 1: Open , 0: Close + .and. (Annular%Annular_closed==0 .or. (Annular%Annular_closed==1 .and. PressureDisplayVARIABLES%PressureGauges(2) <=100.0) .or. (Annular%Annular_closed==1 .and. PressureDisplayVARIABLES%PressureGauges(2)>100.0 .and. Annular%Pannular_reg>=AnnularComputational%AnnularSealingPressure))) then ! 1: Open , 0: Close !write(*,*) 'open 2' RAM(1)%FourwayValve = 0 @@ -196,7 +196,7 @@ end if SUBROUTINE ANNULAR_SUB2 USE VARIABLES - USE PressureDisplayVARIABLES + use PressureDisplayVARIABLESModule USE CBopControlPanelVariables USE CEquipmentsConstants USE CBopStackVariables @@ -314,7 +314,7 @@ SUBROUTINE ANNULAR_SUB2 if (RAM(1)%FourwayValve == 1 .and. Annular%Pannular_reg>AnnularComputational%AnnularMovingPressure & - .and. (Annular%Annular_closed==0 .or. (Annular%Annular_closed==1 .and.PressureGauges(2) <=100.0) .or. (Annular%Annular_closed==1 .and.PressureGauges(2)>100.0 .and. Annular%Pannular_reg>=AnnularComputational%AnnularSealingPressure))) then + .and. (Annular%Annular_closed==0 .or. (Annular%Annular_closed==1 .and. PressureDisplayVARIABLES%PressureGauges(2) <=100.0) .or. (Annular%Annular_closed==1 .and. PressureDisplayVARIABLES%PressureGauges(2)>100.0 .and. Annular%Pannular_reg>=AnnularComputational%AnnularSealingPressure))) then !write(*,*) 'open 4' RAM(1)%FourwayValve = 0 diff --git a/Equipments/ChokeControl/ChokeStartup.f90 b/Equipments/ChokeControl/ChokeStartup.f90 index c4d73cb..adfbd39 100644 --- a/Equipments/ChokeControl/ChokeStartup.f90 +++ b/Equipments/ChokeControl/ChokeStartup.f90 @@ -123,15 +123,4 @@ AirPumpLine%alpha_Pdownstrem=AirPumpLine%Pdownstrem AirPumpLine%alpha_diffpair=0 AirPumpLine%alpha_lossesair=0 - - - - - - - - - - - end \ No newline at end of file diff --git a/Equipments/MudSystem-old/Circulation_Code_Select.f90 b/Equipments/MudSystem-old/Circulation_Code_Select.f90 new file mode 100644 index 0000000..b99a9bd --- /dev/null +++ b/Equipments/MudSystem-old/Circulation_Code_Select.f90 @@ -0,0 +1,148 @@ +subroutine CirculationCodeSelect ! is called in subroutine Fluid_Flow_Solver + + use KickVARIABLESModule + Use MudSystemVARIABLES + USE TD_DrillStemComponents + Use CUnityInputs + Use CUnityOutputs + USE CKellyConnectionEnumVariables + use UTUBEVARSModule + use sROP_Variables + use PressureDisplayVARIABLESModule + + + + implicit none + + + Integer i,KickNumber + + !NewInfluxNumber = NoGasPocket + + MudSystem%Flow_timeCounter= MudSystem%Flow_timeCounter+1 + + !if (ChokePanelStrokeResetSwitch == 1) then + ! Flow_timeCounter= 0 + !endif + + + !write(*,*) 'Flow_timeCounter' , Flow_timeCounter + +!===========================Shoe Lost=============================== + + call ShoeLostSub + +!=================================================================== + + + 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.) + + call ElementsCreation + + + + + if (MUD(8)%Q > 0.0) call FillingWell_By_BellNipple ! Filling Well Through BellNipple ( Path j11 ) + !if (MUD(10)%Q > 0.0) call FillingWell_By_Pumps ! Filling Well Through Pumps ( Path j19 ) + + !write(*,*) 'TD_RemoveVolume,Get_JointConnectionPossible=' , TD_RemoveVolume,Get_JointConnectionPossible() + + if (TD_Vol%RemoveVolume > 0.) call DisconnectingPipe !! .and. Get_JointConnectionPossible() == .false.) call DisconnectingPipe + + + IF (KickFlux .AND. NOT(KickOffBottom)) THEN + call Kick_Influx + endif + + + + + IF ( MudSystem%NewInfluxNumber > 0 ) THEN + !write(*,*) 'KickOffBottom , ROP=' , KickOffBottom , ROP_Bit%RateOfPenetration + call Kick_Migration + endif + +! ============================ must be after migration ============================== + + DO KickNumber= MudSystem%NewInfluxNumber-NoGasPocket+1 , MudSystem%NewInfluxNumber + ! FINDING NEW KICK LOCATIONS: + MudSystem%Ann_KickLoc= 0 + MudSystem%Op_KickLoc= 0 + MudSystem%ChokeLine_KickLoc= 0 + + 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, MudSystem%Op_MudOrKick%Length () + if (MudSystem%Op_MudOrKick%Array(i) == KickNumber) then + MudSystem%Op_KickLoc = i + exit + endif + end do + + 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 =========================== + + 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(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 + 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 + + 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 + + + call Choke_GasSound + + !WRITE(*,*) 'CIRCU-Ann_Saved_MudDischarged_Volume' , Ann_Saved_MudDischarged_Volume + + !****Utube is called in Plot Subroutine**** + + Call Instructor_CirculationMud_Edit + + + + call PlotFinalMudElements + + MudSystem%MudChecked= .true. + MudSystem%UtubePossibility= .true. + !WRITE(*,*) '***********************************************************************' + +end subroutine CirculationCodeSelect \ No newline at end of file diff --git a/Equipments/MudSystem-old/Deallocate_Normal_Circulation.f90 b/Equipments/MudSystem-old/Deallocate_Normal_Circulation.f90 new file mode 100644 index 0000000..d865d2b --- /dev/null +++ b/Equipments/MudSystem-old/Deallocate_Normal_Circulation.f90 @@ -0,0 +1,186 @@ +subroutine DEALLOCATE_ARRAYS_NormalCirculation() ! is called in module FluidFlowMain + USE MudSystemVARIABLES + implicit none + + +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 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 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 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 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 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 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 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 + + + +subroutine RemoveAnnulusMudArrays(ilocal) + USE MudSystemVARIABLES + implicit none + + INTEGER :: 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) + + + + end subroutine + + +subroutine RemoveStringMudArrays(ilocal) + USE MudSystemVARIABLES + implicit none + + INTEGER :: 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) + + + + end subroutine + + +subroutine RemoveOpMudArrays(ilocal) + USE MudSystemVARIABLES + implicit none + + INTEGER :: 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) + + + + end subroutine + +subroutine RemoveHzMudArrays(ilocal) + USE MudSystemVARIABLES + implicit none + + INTEGER :: 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) + + + + end subroutine + \ No newline at end of file diff --git a/Equipments/MudSystem-old/Disconnecting_Pipe.f90 b/Equipments/MudSystem-old/Disconnecting_Pipe.f90 new file mode 100644 index 0000000..5dc26fa --- /dev/null +++ b/Equipments/MudSystem-old/Disconnecting_Pipe.f90 @@ -0,0 +1,108 @@ +subroutine DisconnectingPipe ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + use CDrillWatchVariables + ! !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + USE TD_DrillStemComponents + Use CKellyConnectionEnumVariables + Use CUnityOutputs + USE CManifolds + + implicit none + + Real(8) ExcessMudVolume, ExcessMudVolume_Remained + write(*,*) 'DisconnectingPipe' + + !TD_RemoveVolume= TD_RemoveVolume* 7.48051948 ! ft^3 to gal + + ExcessMudVolume= sum(MudSystem%St_MudDischarged_Volume%Array(:)) - sum(MudSystem%PipeSection_VolumeCapacity(2:F_Counts%StringIntervalCounts)) + + + ! ======if(ExcessMudVolume <= 0.) No Modification Needed Because Removed Pipe was Empty===== + + if (Get_KellyConnection() == KELLY_CONNECTION_NOTHING .and. Manifold%Valve(56)%Status == .False.) ExcessMudVolume= 0.d0 !Valve(56)%Status == .False. :: safety valve installed + + if (ExcessMudVolume > 0.) then + + if ( Manifold%Valve(53)%Status == .true. ) then + MudSystem%MudBucketVolume= ExcessMudVolume + else + MudSystem%MudBucketVolume= 0.0 + endif + + + + + +!========================Flow Disconnect Unity Input Signals================= + + !if ( Get_JointConnectionPossible() == .false. ) then + if (Get_KellyConnection() == KELLY_CONNECTION_NOTHING) then + Call Set_FlowKellyDisconnect(.true.) + else + Call Set_FlowPipeDisconnect(.true.) + endif + !endif + + + +!====================Flow Disconnect Unity Input Signals-End================= + + + + +!========================Disconnecting Pipe from the String================= + + ExcessMudVolume_Remained= ExcessMudVolume ! ft^3 to gal + + + imud=1 + + Do + + 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(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 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 + + enddo + + + + +!=================Disconnecting Pipe from the String - End=================== + endif + + + end subroutine DisconnectingPipe \ No newline at end of file diff --git a/Equipments/MudSystem-old/Elements_Creation.f90 b/Equipments/MudSystem-old/Elements_Creation.f90 new file mode 100644 index 0000000..5243cf3 --- /dev/null +++ b/Equipments/MudSystem-old/Elements_Creation.f90 @@ -0,0 +1,274 @@ +subroutine ElementsCreation ! is called in subroutine Fluid_Flow_Solver + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + !USE CHOKEVARIABLES + !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure + !use CManifolds + use CDrillWatchVariables + !use CHOKEVARIABLES + !use CChokeManifoldVariables + ! !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + use CError + + implicit none + + integer jelement, jmud, jsection,ielement,i + integer jopelement,jopmud,jopsection,iisection,isection,OpSection + +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + + 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 (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+F_Counts%AnnulusIntervalCounts),MudSystem%Xend_PipeSection(F_Counts%StringIntervalCounts+F_Counts%AnnulusIntervalCounts) & + ,MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+F_Counts%AnnulusIntervalCounts),MudSystem%Area_PipeSectionFt(F_Counts%StringIntervalCounts+F_Counts%AnnulusIntervalCounts), & + MudSystem%GeoType(F_Counts%StringIntervalCounts+F_Counts%AnnulusIntervalCounts),MudSystem%OD_PipeSectionInch(F_Counts%StringIntervalCounts+F_Counts%AnnulusIntervalCounts),MudSystem%ID_PipeSectionInch(F_Counts%StringIntervalCounts+F_Counts%AnnulusIntervalCounts)) + + +ALLOCATE (MudSystem%Xstart_OpSection(F_Counts%BottomHoleIntervalCounts),MudSystem%Xend_OpSection(F_Counts%BottomHoleIntervalCounts) & + ,MudSystem%OpSection_VolumeCapacity(F_Counts%BottomHoleIntervalCounts),MudSystem%Area_OpSectionFt(F_Counts%BottomHoleIntervalCounts), & + MudSystem%GeoTypeOp(F_Counts%BottomHoleIntervalCounts),MudSystem%OD_OpSectionInch(F_Counts%BottomHoleIntervalCounts),MudSystem%ID_OpSectionInch(F_Counts%BottomHoleIntervalCounts)) + + MudSystem%OpSection=0 + MudSystem%isection=0 + + + DO iisection=1, F_Counts%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 + !write(*,*) 'EndDepth=' , F_Interval(iisection)%EndDepth + !write(*,*) 'OD=' , F_Interval(iisection)%OD + !write(*,*) 'ID=' , F_Interval(iisection)%ID + ELSE + MudSystem%isection= MudSystem%isection+1 + MudSystem%Xstart_PipeSection(MudSystem%isection)= (F_Interval(iisection)%StartDepth) + !write(*,*) 'F_Interval(iisection)%StartDepth=' , F_Interval(iisection)%StartDepth + MudSystem%Xend_PipeSection(MudSystem%isection)= (F_Interval(iisection)%EndDepth) + !write(*,*) 'F_Interval(iisection)%EndDepth=' , F_Interval(iisection)%EndDepth + + 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) + MudSystem%GeoType(MudSystem%isection)= F_Interval(iisection)%GeoType + !Angle_PipeSection(isection)= F_Interval(iisection)%Angle + ENDIF + + ENDDO + + + + call MudSystem%Xstart_MudElement%Empty() + call MudSystem%Xstart_MudElement%Add(MudSystem%Xstart_PipeSection(1)) + + + call MudSystem%Xstart_OpMudElement%Empty() + call MudSystem%Xstart_OpMudElement%Add(MudSystem%Xstart_OpSection(1)) + + + call MudSystem%TVDstart_MudElement%Empty() + call TVD_Calculator(MudSystem%Xstart_PipeSection(1),MudSystem%MudCircVerticalDepth) + call MudSystem%TVDstart_MudElement%Add(MudSystem%MudCircVerticalDepth) + + + call MudSystem%TVDstart_OpMudElement%Empty() + call TVD_Calculator(MudSystem%Xstart_OpSection(1),MudSystem%MudCircVerticalDepth) + call MudSystem%TVDstart_OpMudElement%Add(MudSystem%MudCircVerticalDepth) + + + + MudSystem%NoPipeSections= MudSystem%isection ! sections in string and annulus(GeoType 0 & 2) + + + DO OpSection= 1,F_Counts%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 + 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 (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 MudSystem%St_MudDischarged_Volume%AddToFirst(sum(MudSystem%PipeSection_VolumeCapacity(2:F_Counts%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_Counts%StringIntervalCounts)) + call MudSystem%St_Mud_Forehead_section%AddToFirst (F_Counts%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 MudSystem%Ann_MudDischarged_Volume%AddToFirst(sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections))) + call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Backhead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_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) + + MudSystem%OldPosition= MudSystem%Xend_PipeSection(F_Counts%StringIntervalCounts) + + MudSystem%OldAnnulusCapacity= sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) + + + 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 MudSystem%Op_MudDischarged_Volume%AddToFirst (sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%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_Counts%BottomHoleIntervalCounts)) + call MudSystem%Op_Mud_Forehead_section%AddToFirst (F_Counts%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 + MudSystem%F_StringIntervalCounts_Old= F_Counts%StringIntervalCounts ! is used for adding new pipe to string + + + MudSystem%FirstMudSet= 1 + endif + + +!===================== Trip Detection ================ + + !DeltaVolumeOp > 0 : Trip in + !DeltaVolumeOp < 0 : Trip out + + + MudSystem%DeltaVolumeOp= ((MudSystem%Xend_PipeSection(F_Counts%StringIntervalCounts)-MudSystem%OldPosition)*PII*((MudSystem%OD_PipeSectionInch(F_Counts%StringIntervalCounts+1)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal ! D(in) + MudSystem%DeltaVolumeOp = INT(MudSystem%DeltaVolumeOp * 100000.d0) / 100000.d0 + + MudSystem%DeltaVolumePipe= ((MudSystem%Xend_PipeSection(F_Counts%StringIntervalCounts)-MudSystem%OldPosition)*PII*((MudSystem%ID_PipeSectionInch(F_Counts%StringIntervalCounts+F_Counts%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_Counts%StringIntervalCounts)-OldPosition))*Area_PipeSectionFt(NoPipeSections)* 7.48051948d0! ft^3 to gal + DrillStringSpeed = (MudSystem%Xend_PipeSection(F_Counts%StringIntervalCounts)-MudSystem%OldPosition) / 0.1 + + MudSystem%DeltaVolumeAnnulusCapacity= sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) - MudSystem%OldAnnulusCapacity + + + !write(*,*) 'DeltaVolumeAnnulusCapacity= ' , DeltaVolumeAnnulusCapacity + + !write(*,*) 'DeltaVolumePipe=' , DeltaVolumePipe + !write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp + ! + ! + !write(*,*) 'Bit here=' , Xend_PipeSection(F_Counts%StringIntervalCounts) + + + + + MudSystem%OldAnnulusCapacity= sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) + + MudSystem%OldPosition= MudSystem%Xend_PipeSection(F_Counts%StringIntervalCounts) + + ! Needed for trip in or out: + if (MudSystem%Hz_Mud_Backhead_X%Length() == 0) then + + CALL ErrorStop('Hz_Mud_Backhead_X Length is 0') + endif + + + MudSystem%Hz_Mud_Backhead_X%Array(1)= MudSystem%Xstart_PipeSection(1) + MudSystem%Hz_Mud_Backhead_section%Array(1)= 1 + + MudSystem%AddedElementsToString = F_Counts%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_Counts%StringIntervalCounts+1) + MudSystem%Ann_Mud_Backhead_section%Array(1)= F_Counts%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 + + + MudSystem%F_StringIntervalCounts_Old= F_Counts%StringIntervalCounts +!write(*,*) 'Xstart_PipeSection(2)' , Xstart_PipeSection(2) +!write(*,*) 'Xend_PipeSection(1)' , Xend_PipeSection(1) + + +!=================================================== + + ! + !DeltaWellCap= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) - WellCapOld + !WellCapOld= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) + !write(*,*) 'DeltaWellCap=' , DeltaWellCap + ! + ! + ! + !DeltaAnnCap= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) - AnnCapOld + !AnnCapOld= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + !write(*,*) 'DeltaAnnCap=' , DeltaAnnCap + + end subroutine ElementsCreation + + + + diff --git a/Equipments/MudSystem-old/FillingWell_By_BellNipple.f90 b/Equipments/MudSystem-old/FillingWell_By_BellNipple.f90 new file mode 100644 index 0000000..ed83f05 --- /dev/null +++ b/Equipments/MudSystem-old/FillingWell_By_BellNipple.f90 @@ -0,0 +1,215 @@ +subroutine FillingWell_By_BellNipple ! is called in subroutine CirculationCodeSelect + + ! this subroutine is for lines: 1) BellNippleToWell-NonFullWell : MUD(8)%Q + ! 2) PumpsToWell_KillLine : MUD(10)%Q + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + use CDrillWatchVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + + implicit none + + real(8) deltaV,Xposition,FillingDensity + + integer kloc,SectionPosition + + + + + ! Well Is Not Full + + + + 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' + + !write(*,*) '*Ann_Mud_Forehead_X%Last()=' , Ann_Mud_Forehead_X%Last() + !write(*,*) '*Ann_MudOrKick%Last()=' , Ann_MudOrKick%Last() + + + + FillingDensity= MudSystem%BellNippleDensity + +!**************************** + if ( MudSystem%Ann_MudDischarged_Volume%Last() > (((MUD(8)%Q+MUD(10)%Q)/60.)*MudSystem%DeltaT_Mudline)) then ! air baghi mimune + + kloc= MudSystem%Ann_MudDischarged_Volume%Length()-1 + + + + deltaV= ((MUD(8)%Q+MUD(10)%Q)/60.)*MudSystem%DeltaT_Mudline + + 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(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==================== + + MudSystem%Ann_MudDischarged_Volume%Array(kloc)= MudSystem%Ann_MudDischarged_Volume%Array(kloc)+ deltaV !(gal) + + + + else ! ( Ann_MudDischarged_Volume%Last() <= (((MUD(8)%Q+MUD(10)%Q)/60.)*DeltaT_Mudline)) then ! air baghi namune + + + + + kloc= MudSystem%Ann_MudDischarged_Volume%Length()-1 + + deltaV= MudSystem%Ann_MudDischarged_Volume%Last() + + + + 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 + MudSystem%Ann_RemainedVolume_in_LastSection%Array(kloc)= (0.0) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(kloc)= (0.0) + + 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 + MudSystem%Ann_Density%Array(kloc+1) =FillingDensity + MudSystem%Ann_MudOrKick%Array(kloc+1)= 0 + + endif + + + endif + + ! end condition (Ann_MudOrKick%Last() == 104) ! Last Element is air + +!********************************************************************************************************************************************************** + + + + + else ! (Ann_MudOrKick%Last() == 0) then ! Last Element is NOT air- so we must observe: Ann_Mud_Forehead_X%Last()/=0.0 + + !write(*,*) 'FillingWell_By_BellNipple-Last Element is NOT air' + ! + !write(*,*) '*Ann_Mud_Forehead_X%Last()=' , Ann_Mud_Forehead_X%Last() + !write(*,*) '*Ann_MudOrKick%Last()=' , Ann_MudOrKick%Last() + + + deltaV= ((MUD(8)%Q+MUD(10)%Q)/60.)*MudSystem%DeltaT_Mudline + + kloc= MudSystem%Ann_MudDischarged_Volume%Length() + + + + + +!========================ANNULUS ENTRANCE==================== + + 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==================== + + 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 + 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 + MudSystem%Ann_RemainedVolume_in_LastSection%Array(kloc)= (0.0) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(kloc)= (0.0) + endif + + + + + + + endif + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + end subroutine FillingWell_By_BellNipple \ No newline at end of file diff --git a/Equipments/MudSystem-old/Kick_Expansion_and_Contraction.f90 b/Equipments/MudSystem-old/Kick_Expansion_and_Contraction.f90 new file mode 100644 index 0000000..8852476 --- /dev/null +++ b/Equipments/MudSystem-old/Kick_Expansion_and_Contraction.f90 @@ -0,0 +1,234 @@ +subroutine Kick_Expansion ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + use CDrillWatchVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + USE CReservoirVariables + use KickVARIABLESModule + + + implicit none + real(8) ExpansionVolume + + !write(*,*) 'Kick Expansion' + + ExpansionVolume= GasPocketDeltaVol%Array(MudSystem%NewInfluxNumber - MudSystem%KickNumber + 1) * 7.48 + +IF ( MudSystem%Kickexpansion_DueToMudLost ) ExpansionVolume = ((MudSystem%Qlost/60.0d0)*MudSystem%DeltaT_Mudline) + + +!============================== kick zire mate bashad ============================== + + if (MudSystem%Op_KickLoc > 0 .and. MudSystem%Ann_KickLoc==0) then ! .and. Op_KickLoc /= Op_MudOrKick%Length ()) then + + !write(*,*) 'expansion (1)' + + + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc)+ ExpansionVolume + + + !if (MUD(4)%Q > 0.) then + ! + ! if (abs(ChokeLine_Density%Array(1)-Ann_Density%Last())< DensityMixTol) then + ! ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1) + ExpansionVolume + ! else + ! call ChokeLine_Density%AddToFirst (Ann_Density%Last()) + ! call ChokeLine_MudDischarged_Volume%AddToFirst (ExpansionVolume) ! farz kardam ke hameye hajm ro ba yek density ezafe konim + ! call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + ! call ChokeLine_Mud_Forehead_section%AddToFirst (1) + ! call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + ! call ChokeLine_Mud_Backhead_section%AddToFirst (1) + ! call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! call ChokeLine_MudOrKick%AddToFirst (Ann_MudOrKick%Last()) + ! endif + ! + !endif + + endif +!======================================================================================== + + + +!============================= foreheade dar fazaye annulus bashad =========================== + ! agar kick be entehaye annulus reside bashe, expansion ra emaal nemikonim + 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 + + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc)+ ExpansionVolume + + !if (MUD(4)%Q > 0.) then + ! + ! + ! if (abs(ChokeLine_Density%Array(1)-Ann_Density%Last())< DensityMixTol) then + ! ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1) + ExpansionVolume + ! else + ! call ChokeLine_Density%AddToFirst (Ann_Density%Last()) + ! call ChokeLine_MudDischarged_Volume%AddToFirst (ExpansionVolume) ! farz kardam ke hameye hajm ro ba yek density ezafe konim + ! call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + ! call ChokeLine_Mud_Forehead_section%AddToFirst (1) + ! call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + ! call ChokeLine_Mud_Backhead_section%AddToFirst (1) + ! call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! call ChokeLine_MudOrKick%AddToFirst (Ann_MudOrKick%Last()) + ! endif + ! + !endif + + endif +!======================================================================================== + + + + + +!=============================== foreheade dar choke line bashad ============================= + + if (MudSystem%ChokeLine_KickLoc > 0 .and. MudSystem%Ann_KickLoc==0) then + + MudSystem%ChokeLine_MudDischarged_Volume%Array(MudSystem%ChokeLine_KickLoc)= MudSystem%ChokeLine_MudDischarged_Volume%Array(MudSystem%ChokeLine_KickLoc)+ ExpansionVolume + + endif + + +!======================================================================================== + + !write(*,*) 'Expansion======0' + ! !do imud=1, Ann_MudDischarged_Volume%Length() + ! ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! !enddo + ! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + !write(*,*) '0======expansion' + + + + end subroutine Kick_Expansion + + + + + +subroutine Kick_Contraction ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + use CDrillWatchVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + USE CReservoirVariables + use KickVARIABLESModule + USE CError + + + implicit none + + integer jelement, jmud, jsection,ielement,i + integer jopelement,jopmud,jopsection + real(8) ContractionVolume + + +!********************************************************* + +! contraction is always with pump flow + +!********************************************************* + !write(*,*) 'Kick Contraction' + + !MUD(2)%Q= MPumps%Total_Pump_GPM + MudSystem%StringFlowRate= MUD(2)%Q + MudSystem%AnnulusFlowRate= MUD(2)%Q + + if (MudSystem%NewPipeFilling == 0) then + MudSystem%StringFlowRate= 0. + MudSystem%AnnulusFlowRate= 0. + endif + + + + + + !if (WellHeadIsOpen) then + ContractionVolume= - GasPocketDeltaVol%Array(MudSystem%NewInfluxNumber - MudSystem%KickNumber + 1) * 7.48 + !else + !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 + + +!************************************************************************************************************************************************************************** + + ! pump mud is added in "pump&TripIn" code + + IF (MudSystem%Op_KickLoc > 0 .and. MudSystem%Ann_KickLoc == 0) then ! All of kick is under bit (iloc == 1) + + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc) - ( ContractionVolume ) + + 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) + + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc) - ( ContractionVolume ) + + ELSE IF (MudSystem%Ann_KickLoc == 0 .AND. MudSystem%ChokeLine_KickLoc > 0) THEN ! kick is in chokeline only + + MudSystem%ChokeLine_MudDischarged_Volume%Array(MudSystem%ChokeLine_KickLoc)= MudSystem%ChokeLine_MudDischarged_Volume%Array(MudSystem%ChokeLine_KickLoc) - ( ContractionVolume ) + + ELSE IF (MudSystem%Op_KickLoc > 0 .AND. MudSystem%Ann_KickLoc > 0) THEN ! Kick is around bit (iloc==2) + + if (MudSystem%Ann_MudDischarged_Volume%Array(1) > ContractionVolume ) then + + MudSystem%Ann_MudDischarged_Volume%Array(1)= MudSystem%Ann_MudDischarged_Volume%Array(1) - ( ContractionVolume ) + + + elseif (MudSystem%Op_MudDischarged_Volume%Last() > ContractionVolume ) then + + 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 (MudSystem%Ann_KickLoc > 0 .AND. MudSystem%ChokeLine_KickLoc > 0) THEN + + if (MudSystem%ChokeLine_MudDischarged_Volume%Array(1) > ContractionVolume ) then + + MudSystem%ChokeLine_MudDischarged_Volume%Array(1) = MudSystem%ChokeLine_MudDischarged_Volume%Array(1) - ( ContractionVolume ) + + + elseif (MudSystem%Ann_MudDischarged_Volume%Last() > ContractionVolume ) then + + 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') + endif + + + + endif + + ! write(*,*) 'contract======0' + !! !do imud=1, Ann_MudDischarged_Volume%Length() + !! ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + !! !enddo + !! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + !write(*,*) '0======contract' + +end subroutine Kick_Contraction diff --git a/Equipments/MudSystem-old/Kick_Influx.f90 b/Equipments/MudSystem-old/Kick_Influx.f90 new file mode 100644 index 0000000..9880077 --- /dev/null +++ b/Equipments/MudSystem-old/Kick_Influx.f90 @@ -0,0 +1,215 @@ +subroutine Kick_Influx ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + use CDrillWatchVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + + + implicit none + + +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + + !write(*,*) 'Kick Influx' + + +!=================== Bottom Hole Kick Influx ENTRANCE(due to Kick) =================== + + MudSystem%Kick_Density= 2 + MudSystem%NewInflux_Density= MudSystem%Kick_Density + + + 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 + + + MudSystem%NewInfluxElementCreated= 1 + endif + + + 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) + + + + end subroutine Kick_Influx + + + + + + + + + + + +subroutine Instructor_CirculationMud_Edit ! is called in subroutine CirculationCodeSelect + + use KickVARIABLESModule + Use MudSystemVARIABLES + USE TD_DrillStemComponents + Use CUnityInputs + Use CUnityOutputs + USE CKellyConnectionEnumVariables + use UTUBEVARSModule + use sROP_Variables + use sROP_Other_Variables + use CDownHoleVariables + + + implicit none + + + + + + if ( DownHole%AnnDrillMud == .true. .and. (ROP_Bit%RateOfPenetration>0. .and. MudSystem%DeltaVolumeOp>0.0) ) then + + do imud= 1, MudSystem%Ann_Density%Length() + + if ( MudSystem%Ann_MudOrKick%Array(imud) == 0 ) then + MudSystem%Ann_Density%Array(imud)= (MudSystem%St_Density%Last() * MudSystem%AnnulusFlowRate + 141.4296E-4*ROP_Bit%RateOfPenetration*ROP_Spec%DiameterOfBit**2)/(MudSystem%AnnulusFlowRate+6.7995E-4*ROP_Bit%RateOfPenetration*ROP_Spec%DiameterOfBit**2) + MudSystem%Ann_CuttingMud%Array(imud)= 1 + endif + + enddo + + endif + + + if ( DownHole%AnnCirculateMud == .true. ) then + + do imud= 1, MudSystem%Ann_Density%Length() + + if ( MudSystem%Ann_MudOrKick%Array(imud) == 0 ) then + MudSystem%Ann_Density%Array(imud)= MudSystem%ActiveTankDensity + MudSystem%Ann_CuttingMud%Array(imud)= 0 + endif + + enddo + + do imud= 1, MudSystem%St_Density%Length() + + MudSystem%St_Density%Array(imud)= MudSystem%ActiveTankDensity + + enddo + + endif + + + + + end subroutine Instructor_CirculationMud_Edit + + + +subroutine ShoeLostSub ! is called in subroutine CirculationCodeSelect + + use KickVARIABLESModule + Use MudSystemVARIABLES + USE TD_DrillStemComponents + Use CUnityInputs + Use CUnityOutputs + USE CKellyConnectionEnumVariables + use UTUBEVARSModule + use sROP_Variables + use sROP_Other_Variables + use CDownHoleVariables + use CShoeVariables + use PressureDisplayVARIABLESModule + Use CWarningsVariables + + + implicit none + + MudSystem%ShoeLost= .false. + MudSystem%Kickexpansion_DueToMudLost= .false. + + MudSystem%ShoeMudPressure= PressureGauges(5) + + + MudSystem%UGBOSuccessionCounter = MudSystem%UGBOSuccessionCounter + 1 + !write(*,*) 'check point 1' + + 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 ( MudSystem%UGBOSuccessionCounter /= MudSystem%UGBOSuccessionCounterOld+1 .and. MudSystem%ShoeFractured==.false. ) then + MudSystem%UGBOSuccessionCounter = 0 ! also in starup + MudSystem%UGBOSuccessionCounterOld = 0 ! also in starup + return + else + MudSystem%UGBOSuccessionCounterOld= MudSystem%UGBOSuccessionCounter + endif + + if ( MudSystem%UGBOSuccessionCounter < 10 .and. MudSystem%ShoeFractured==.false.) then + return + endif + + !write(*,*) 'check point 3 ,UGBOSuccessionCounter' , UGBOSuccessionCounter + + + + MudSystem%ShoeFractured= .true. + + MudSystem%ShoeMudViscosity= MAX(MudSystem%ShoeMudViscosity, 12.d0) + !write(*,*) 'ShoeMudDensity , ShoeMudViscosity' , ShoeMudDensity , ShoeMudViscosity + 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 + MudSystem%Qlost = MAX( (MudSystem%ShoeLostCoef * (MudSystem%ShoeMudPressure - (MudSystem%FormationLostPressure/2.0))) , 0.d0 ) + if (MudSystem%Qlost > 0.0) then + MudSystem%ShoeLost= .true. + else + MudSystem%ShoeLost= .false. + endif + + !write(*,*) 'Qlost=' , Qlost, ShoeMudPressure, FormationLostPressure + call Activate_UndergroundBlowout() + + + do imud= 1, MudSystem%Ann_Mud_Forehead_X%Length() + + 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 + + MudSystem%Kickexpansion_DueToMudLost= .true. + write(*,*) 'Kickexpansion_DueToMudLost' + + EXIT + + ENDIF + + + enddo + + + + endif + + if (Warmings%UndergroundBlowout == .false.) MudSystem%ShoeLost= .false. + + + + end subroutine ShoeLostSub + + + + \ No newline at end of file diff --git a/Equipments/MudSystem-old/Kick_Migration.f90 b/Equipments/MudSystem-old/Kick_Migration.f90 new file mode 100644 index 0000000..1d2e833 --- /dev/null +++ b/Equipments/MudSystem-old/Kick_Migration.f90 @@ -0,0 +1,1176 @@ +subroutine Kick_Migration ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + use CDrillWatchVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + USE CReservoirVariables + use KickVARIABLESModule + + + implicit none + + integer jelement, jmud, jsection,ielement,i,kickNumber + integer jopelement,jopmud,jopsection,CuttingValue + + + !MUD(2)%Q= MPumps%Total_Pump_GPM + !MudSystem%StringFlowRate= MUD(2)%Q + !MudSystem%AnnulusFlowRate= MUD(2)%Q + ! + !if (NewPipeFilling == 0) then + ! MudSystem%StringFlowRate= 0. + ! MudSystem%AnnulusFlowRate= 0. + !endif + + !StringFlowRateFinal= MudSystem%StringFlowRate + !AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate + + + + !write(*,*) 'MUD(2)%Q=====' , MUD(2)%Q + !write(*,*) 'Kick Migration,NewInfluxNumber:' , NewInfluxNumber + + + + !FirstSetKickMigration + !write(*,*) 'NewInfluxNumber=' , NewInfluxNumber +DO KickNumber= MudSystem%NewInfluxNumber-NoGasPocket+1 , MudSystem%NewInfluxNumber + !write(*,*) 'KickNumber=' , KickNumber + if (KickFlux .AND. NOT(KickOffBottom) .and. KickNumber == MudSystem%NewInfluxNumber) cycle + if ( KickNumber == MudSystem%Ann_MudOrKick%Last() ) cycle ! when the last element in Annulus is kick, Migration is not called + !write(*,*) 'Migration will be done for,KickNumber=' ,KickNumber + + !=================== Bottom Hole ENTRANCE(due to Kick) =================== + !KickDx= (AutoMigrationRate/60.)*DeltaT_Mudline !3600 (ft/min)= 6 ft set in start up + + + MudSystem%Op_KickLoc= 0 + MudSystem%Ann_KickLoc= 0 + MudSystem%ChokeLine_KickLoc= 0 + + 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, MudSystem%Ann_MudOrKick%Length () + if (MudSystem%Ann_MudOrKick%Array(i) == KickNumber) then + MudSystem%Ann_KickLoc = i + exit + endif + end do + + do i = 1, MudSystem%ChokeLine_MudOrKick%Length () + if (MudSystem%ChokeLine_MudOrKick%Array(i) == KickNumber) then + MudSystem%ChokeLine_KickLoc = i + exit + endif + end do + + !write(*,*) 'Op_KickLoc=' , Op_KickLoc + !write(*,*) 'Ann_KickLoc=' , Ann_KickLoc + !!write(*,*) 'ChokeLine_KickLoc=' , ChokeLine_KickLoc + ! + ! + !write(*,*) 'Op_MudOrKick%Length ()=' , Op_MudOrKick%Length () + ! + ! + + + + +!============================== foreheade kick be mate reside bashad *3 ============================== + +if (MudSystem%Op_KickLoc == MudSystem%Op_MudOrKick%Length () .and. MudSystem%Ann_KickLoc==0 ) then + !write(*,*) '****3' + + MudSystem%iLoc= 2 + + MudSystem%KickDv= MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Forehead_section%Array(MudSystem%Op_KickLoc)) * MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal + + + MudSystem%MinKickDv= min( MudSystem%KickDv,MudSystem%Ann_MudDischarged_Volume%Array (1), MudSystem%Op_MudDischarged_Volume%Last () ) + + MudSystem%NewDensity= MudSystem%Ann_Density%Array (1) + MudSystem%NewVolume= MudSystem%MinKickDv + + if ( MudSystem%MinKickDv == MudSystem%KickDv ) then !eleman bala sari baghi mimund, paeeni(kick) ham baghi mimund + + MudSystem%Ann_MudDischarged_Volume%Array (1)= MudSystem%Ann_MudDischarged_Volume%Array (1) - MudSystem%MinKickDv + + call MudSystem%Ann_Density%AddToFirst (MudSystem%Op_Density%Last()) + call MudSystem%Ann_MudDischarged_Volume%AddToFirst (MudSystem%MinKickDv) + call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Forehead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Backhead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Ann_MudOrKick%AddToFirst (KickNumber) + call MudSystem%Ann_CuttingMud%AddToFirst (0) + + MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc) - MudSystem%MinKickDv + + ! backheade kick zire mate bashad + if (MudSystem%Op_KickLoc > 1) then + !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then + + if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then + + + MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc) + + call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0) + + + else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity + + MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume + + endif + else !if Op_KickLoc == 1 (*****Migration Start*****) *3-1=============================== + !write(*,*) '****3-1' + + + call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + + elseif ( MudSystem%MinKickDv == MudSystem%Ann_MudDischarged_Volume%Array (1) ) then ! eleman bala sari baghi nemimund + + MudSystem%Ann_Density%Array(1)= MudSystem%Op_Density%Last() + MudSystem%Ann_MudOrKick%Array(1)= KickNumber + + MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc) - MudSystem%MinKickDv + + ! backheade kick zire mate bashad + if (MudSystem%Op_KickLoc > 1) then + + !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then + + if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then + + + MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc) + + call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0) + + + else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity + + MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *3-2=============================== + !write(*,*) '****3-2' + + + call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + ! + elseif ( MudSystem%MinKickDv == MudSystem%Op_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick hazf mishod + + MudSystem%Ann_MudDischarged_Volume%Array (1)= MudSystem%Ann_MudDischarged_Volume%Array (1) - MudSystem%MinKickDv + + call MudSystem%Ann_Density%AddToFirst (MudSystem%Op_Density%Last()) + call MudSystem%Ann_MudDischarged_Volume%AddToFirst (MudSystem%MinKickDv) + call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Forehead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Backhead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Ann_MudOrKick%AddToFirst (KickNumber) + call MudSystem%Ann_CuttingMud%AddToFirst (0) + + + MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc) + + call MudSystem%Op_MudDischarged_Volume%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_Mud_Backhead_X%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_Mud_Backhead_section%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_Mud_Forehead_X%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_Mud_Forehead_section%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_Density%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_RemainedVolume_in_LastSection%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_MudOrKick%Remove (MudSystem%Op_KickLoc) + + + ! backheade kick zire mate bashad + if (MudSystem%Op_KickLoc > 1) then + !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then + + if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then + + + + call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0) + + + else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity + + MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *3-3=============================== + !write(*,*) '****3-3' + + call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + + + endif + + + endif + +!======================================================================================== + + +!============================== foreheade kick be mate reside bashad *3 with pump ============================== + +! if (Op_KickLoc == Op_MudOrKick%Length () .and. Ann_KickLoc==0 .and. MudSystem%AnnulusFlowRate /= 0.0 ) then +! write(*,*) '****3 with pump' +! +! KickMigration_2SideBit= .true. +! !iloc= 2 +! +! !KickDv= Area_OpSectionFt(Op_Mud_Forehead_section%Array(Op_KickLoc)) * KickDx * 7.48051948 ! ft^3 to gal +! +!!farz mikonam baraye in yek iteration kick az OP hazf nemishavad va hajme aan bishtar az pump flow ast +! +! KickDv= ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) +! +! call Ann_Density%AddToFirst (Kick_Density) +! call Ann_MudDischarged_Volume%AddToFirst (KickDv) +! call Ann_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) +! call Ann_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts+1) +! call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1)) +! call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1) +! call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call Ann_MudOrKick%AddToFirst (KickNumber) +! call Ann_CuttingMud%AddToFirst (0) +! +! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv +! +! ! +! !if ( ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) >= KickDv ) then ! sorate pump bishtar az kick bashad +! ! +! ! KickDv= ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) +! +! +! +! ! BackHead: +! if ( Op_Density%Array (Op_KickLoc-1) /=MudSystem%St_Density%Last() ) then +! +! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! call Op_Density%AddTo (Op_KickLocMudSystem%St_Density%Last()) +! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,KickDv) +! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) +! call Op_MudOrKick%AddTo (Op_KickLoc,0) +! +! +! else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity +! +! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + KickDv +! +! endif +! +! +! +! +! endif + +!======================================================================================== + + +!============================= tamame kick zire mate bashad *1 ================================ + if ( MudSystem%Op_KickLoc>0 .and. MudSystem%Op_KickLoc < MudSystem%Op_MudOrKick%Length () ) then + !write(*,*) '****1' + !iloc= 1 + + MudSystem%KickDv= MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Forehead_section%Array(MudSystem%Op_KickLoc)) * MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal + + + MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc) + + if ( MudSystem%KickDv < MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc+1) ) then !eleman bala sari baghi mimund + + !write(*,*) 'cond 11111111111111' + + MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc+1)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc+1) - MudSystem%KickDv + + MudSystem%NewDensity= MudSystem%Op_Density%Array (MudSystem%Op_KickLoc+1) + MudSystem%NewVolume= MudSystem%KickDv + + else !KickDv > Op_MudDischarged_Volume%Array (imudKick+1) eleman baghi nemimund + + ! write(*,*) 'cond 22222222222222222' + + + MudSystem%KickDv= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc+1) + + MudSystem%NewVolume= MudSystem%KickDv + MudSystem%NewDensity= MudSystem%Op_Density%Array (MudSystem%Op_KickLoc+1) + + + + + call MudSystem%Op_MudDischarged_Volume%Remove (MudSystem%Op_KickLoc+1) + call MudSystem%Op_Mud_Backhead_X%Remove (MudSystem%Op_KickLoc+1) + call MudSystem%Op_Mud_Backhead_section%Remove (MudSystem%Op_KickLoc+1) + call MudSystem%Op_Mud_Forehead_X%Remove (MudSystem%Op_KickLoc+1) + call MudSystem%Op_Mud_Forehead_section%Remove (MudSystem%Op_KickLoc+1) + call MudSystem%Op_Density%Remove (MudSystem%Op_KickLoc+1) + call MudSystem%Op_RemainedVolume_in_LastSection%Remove (MudSystem%Op_KickLoc+1) + call MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (MudSystem%Op_KickLoc+1) + call MudSystem%Op_MudOrKick%Remove (MudSystem%Op_KickLoc+1) + + endif + + ! backheade kick zire mate bashad + if (MudSystem%Op_KickLoc > 1) then + !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then + + if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then + + + + + call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0) + + else !Op_Density%Array (Op_KickLoc-1) == MudSystem%NewDensity + + MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume + + endif + else !if Op_KickLoc == 1 (*****Migration Start*****) *5-1=============================== + !write(*,*) '****5-1' + + call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + endif + +!======================================================================================== + + !write(*,*) 'a) density and cutting:' , Ann_Density%Length() , Ann_CuttingMud%Length() + + +!=========================== tamame kick balaye mate bashad *2 ================================== + + if ( MudSystem%Ann_KickLoc > 0 .and. MudSystem%Op_KickLoc==0 ) then + !write(*,*) '****2' + + !iloc= 1 + + MudSystem%KickDv= MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%Ann_KickLoc)) * MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal + + MudSystem%NewDensity= MudSystem%Ann_Density%Array (MudSystem%Ann_KickLoc+1) + MudSystem%NewVolume= MudSystem%KickDv + CuttingValue= MudSystem%Ann_CuttingMud%Array (MudSystem%Ann_KickLoc+1) + + if ( MudSystem%KickDv < MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) ) then !eleman bala sari baghi mimund + + MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) - MudSystem%KickDv + + else !KickDv > Ann_MudDischarged_Volume%Array (imudKick+1) eleman baghi nemimund + + MudSystem%KickDv= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) + MudSystem%NewVolume= MudSystem%KickDv + + call MudSystem%Ann_MudDischarged_Volume%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Mud_Backhead_X%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Mud_Backhead_section%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Mud_Forehead_X%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Mud_Forehead_section%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Density%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_RemainedVolume_in_LastSection%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_MudOrKick%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_CuttingMud%Remove (MudSystem%Ann_KickLoc+1) + + endif + + ! backheade kick balaye mate bashad + + if (MudSystem%Ann_KickLoc > 1) then + !if ( Ann_Density%Array (Ann_KickLoc-1) /= MudSystem%NewDensity ) then + + if ( ABS(MudSystem%Ann_Density%Array (MudSystem%Ann_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then + + MudSystem%Old_KickBackHead_X= MudSystem%Ann_Mud_Backhead_X%Array (MudSystem%Ann_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Ann_Mud_Backhead_section%Array (MudSystem%Ann_KickLoc) + + + call MudSystem%Ann_Density%AddTo (MudSystem%Ann_KickLoc,MudSystem%NewDensity) + call MudSystem%Ann_MudDischarged_Volume%AddTo (MudSystem%Ann_KickLoc,MudSystem%NewVolume) + call MudSystem%Ann_Mud_Forehead_X%AddTo (MudSystem%Ann_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Ann_Mud_Forehead_section%AddTo (MudSystem%Ann_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Ann_Mud_Backhead_X%AddTo (MudSystem%Ann_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Ann_Mud_Backhead_section%AddTo (MudSystem%Ann_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (MudSystem%Ann_KickLoc,0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Ann_KickLoc,0.0d0) + call MudSystem%Ann_MudOrKick%AddTo (MudSystem%Ann_KickLoc,0) + call MudSystem%Ann_CuttingMud%AddTo (MudSystem%Ann_KickLoc,0) + + else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity + + MudSystem%Ann_Density%Array(MudSystem%Ann_KickLoc-1)= (MudSystem%Ann_Density%Array(MudSystem%Ann_KickLoc-1)*MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc-1)+MudSystem%NewVolume) + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc-1)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc-1) + MudSystem%NewVolume + + + endif + + else !if Ann_KickLoc == 1 *6 =============================== + !write(*,*) '****6' + + MudSystem%Old_KickBackHead_X= MudSystem%Ann_Mud_Backhead_X%Array (MudSystem%Ann_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Ann_Mud_Backhead_section%Array (MudSystem%Ann_KickLoc) + + + call MudSystem%Ann_Density%AddToFirst (MudSystem%NewDensity) + call MudSystem%Ann_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume) + call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Ann_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Ann_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + 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 (CuttingValue) + + endif + + endif + + !======================================================================================== + + + + + + + +!============================== kick 2 tarafe mate bashad *4 ============================== + + if ( MudSystem%Ann_KickLoc > 0 .and. MudSystem%Op_KickLoc > 0 ) then + !write(*,*) '****4' + + MudSystem%iLoc= 2 + + MudSystem%KickDv= MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%Ann_KickLoc)) * MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal + + + MudSystem%MinKickDv= min( MudSystem%KickDv,MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1), MudSystem%Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick + + MudSystem%NewDensity= MudSystem%Ann_Density%Array (MudSystem%Ann_KickLoc+1) + MudSystem%NewVolume= MudSystem%MinKickDv + + if ( MudSystem%MinKickDv == MudSystem%KickDv ) then !eleman bala sari baghi mimund, paeeni(kick) dar OP ham baghi mimund + !write(*,*) '****4----1' + + + MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) - MudSystem%MinKickDv + + MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc) + MudSystem%MinKickDv ! Ann_KickLoc= 1 + + MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc) - MudSystem%MinKickDv ! Op_KickLoc= last + + + ! backheade kick zire mate bashad + if ( MudSystem%Op_KickLoc>1) then + + !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then + + if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then + + MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc) + + call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0) + + + else ! merge + + MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + !write(*,*) '****5-2' + + MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc) + + + call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + + elseif ( MudSystem%MinKickDv == MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) ) then ! eleman bala sari baghi nemimund + !write(*,*) '****4----2' + + call MudSystem%Ann_MudDischarged_Volume%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Mud_Backhead_X%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Mud_Backhead_section%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Mud_Forehead_X%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Mud_Forehead_section%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_Density%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_RemainedVolume_in_LastSection%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_MudOrKick%Remove (MudSystem%Ann_KickLoc+1) + call MudSystem%Ann_CuttingMud%Remove (MudSystem%Ann_KickLoc+1) + + MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc) + MudSystem%MinKickDv ! Ann_KickLoc= 1 + + MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc) - MudSystem%MinKickDv ! Op_KickLoc= last + + ! backheade kick zire mate bashad + if (MudSystem%Op_KickLoc > 1) then + + !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then + + if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then + + + MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc) + + call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0) + + + else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity + MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + + MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc) + + + call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + elseif ( MudSystem%MinKickDv == MudSystem%Op_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick az OP kamel kharej mishod + !write(*,*) '****4----3' + + + + MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) - MudSystem%MinKickDv + + MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc) + MudSystem%MinKickDv ! Ann_KickLoc= 1 + + + + MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc) + MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc) + + + call MudSystem%Op_MudDischarged_Volume%Remove (MudSystem%Op_KickLoc) ! Op_KickLoc= last + call MudSystem%Op_Mud_Backhead_X%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_Mud_Backhead_section%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_Mud_Forehead_X%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_Mud_Forehead_section%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_Density%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_RemainedVolume_in_LastSection%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (MudSystem%Op_KickLoc) + call MudSystem%Op_MudOrKick%Remove (MudSystem%Op_KickLoc) + + ! backheade kick zire mate bashad + if (MudSystem%Op_KickLoc > 1) then + + !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then + + if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then + + + call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0) + call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0) + + else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity + MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + + call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity) + call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume) + call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X) + call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section) + call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + MudSystem%iLoc= 1 ! ok + + endif + + + endif + +!======================================================================================== + + + +!============================== kick 2 tarafe mate bashad *4 with pump ============================== + + ! + !if ( Ann_KickLoc > 0 .and. Op_KickLoc > 0 .and. MudSystem%AnnulusFlowRate /= 0.0 ) then + ! write(*,*) '****4 with pump' + ! + ! KickMigration_2SideBit= .true. + ! + ! !iloc= 2 + ! + ! KickDv= Area_PipeSectionFt(Ann_Mud_Forehead_section%Array(Ann_KickLoc)) * KickDx * 7.48051948d0 ! ft^3 to gal + ! !MinKickDv= min( KickDv,Ann_MudDischarged_Volume%Array (Ann_KickLoc+1), Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick + ! + ! + ! !MinKickDv= min( KickDv,Ann_MudDischarged_Volume%Array (Ann_KickLoc+1), Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick + ! ! + ! !MudSystem%NewDensity= Ann_Density%Array (Ann_KickLoc+1) + ! !NewVolume= MinKickDv + ! + ! + ! if ( ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) >= KickDv ) then ! sorate pump bishtar az kick bashad---tu in halat aslan kari be elemane balaiye kick tuye Ann nadarim + ! !WRITE(*,*) '*****sorate pump bishtar az kick*******' + ! MinKickDv= ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) ! dar asl maxKickDv ast + ! + ! + ! + ! + ! + ! + ! + ! + ! if ( Op_MudDischarged_Volume%Last () > MinKickDv ) then !eleman paeeni(kick) dar OP baghi mimund + ! + ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 + ! + ! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv ! Op_KickLoc= last + ! + ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! ! backheade kick zire mate bashad + ! if ( Op_KickLoc>1) then + ! + ! if ( Op_Density%Array (Op_KickLoc-1) /=MudSystem%St_Density%Last() ) then + ! + ! + ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! + ! call Op_Density%AddTo (Op_KickLocMudSystem%St_Density%Last()) + ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,MinKickDv) + ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) + ! call Op_MudOrKick%AddTo (Op_KickLoc,0) + ! + ! + ! else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity + ! + ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume + ! + ! endif + ! + ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + ! write(*,*) '****5-2 with pump' + ! + ! + ! !Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! !Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! + ! + ! call Op_Density%AddToFirst MudSystem%St_Density%Last()) + ! call Op_MudDischarged_Volume%AddToFirst (MinKickDv) + ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! call Op_MudOrKick%AddToFirst (0) + ! + ! endif + ! + ! elseif ( Op_MudDischarged_Volume%Last () <= MinKickDv ) then !eleman paeeni(kick) dar OP baghi nemimund yani kick az OP kamel kharej mishod + ! + ! MinKickDv= Op_MudDischarged_Volume%Last () + ! + ! + ! write(*,*) '****4----3 with pump a' + ! + ! + ! Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)= Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) + ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)-MinKickDv + ! + ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 + ! + ! call Op_MudDischarged_Volume%Remove (Op_KickLoc) ! Op_KickLoc= last + ! call Op_Mud_Backhead_X%Remove (Op_KickLoc) + ! call Op_Mud_Backhead_section%Remove (Op_KickLoc) + ! call Op_Mud_Forehead_X%Remove (Op_KickLoc) + ! call Op_Mud_Forehead_section%Remove (Op_KickLoc) + ! call Op_Density%Remove (Op_KickLoc) + ! call Op_RemainedVolume_in_LastSection%Remove (Op_KickLoc) + ! call Op_EmptyVolume_inBackheadLocation%Remove (Op_KickLoc) + ! call Op_MudOrKick%Remove (Op_KickLoc) + ! + ! + ! ! backheade kick zire mate bashad + ! if (Op_KickLoc > 1) then + ! + ! if ( Op_Density%Array (Op_KickLoc-1) /=MudSystem%St_Density%Last() ) then + ! + ! + ! !Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! !Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! + ! call Op_Density%AddTo (Op_KickLocMudSystem%St_Density%Last()) + ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,MinKickDv) + ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) + ! call Op_MudOrKick%AddTo (Op_KickLoc,0) + ! + ! + ! + ! else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity + ! + ! + ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + MinKickDv + ! + ! endif + ! + ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + ! + ! + ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! + ! + ! call Op_Density%AddToFirst MudSystem%St_Density%Last()) + ! call Op_MudDischarged_Volume%AddToFirst (MinKickDv) + ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! call Op_MudOrKick%AddToFirst (0) + ! + ! endif + ! + ! + ! endif ! ende 2 halat ke kick tuye Op baghi bemune ya namune- dar halati ke ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) >= KickDv ) ! sorate pump bishtar az kick bashad + ! + ! + ! + ! + ! else !if( ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) < KickDv ) then ! sorate pump kamtar az kick bashad + ! !WRITE(*,*) '*****sorate pump kamtar az kick*******' + ! + ! + ! + ! + ! MinKickDv= min( KickDv,Ann_MudDischarged_Volume%Array (Ann_KickLoc+1), Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick + ! + ! + ! + ! !write(*,*) 'MinKickDv=' , MinKickDv + ! + ! + ! if ( MinKickDv == KickDv ) then !eleman bala sari baghi mimund, paeeni(kick) dar OP ham baghi mimund + ! !write(*,*) '****4----1 with pump' + ! !write(*,*) MudSystem%St_Density%Last()=' ,MudSystem%St_Density%Last() + ! !write(*,*) '((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline)=' , ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) + ! !write(*,*) 'Ann_Density%Array(Ann_KickLoc+1)=' , Ann_Density%Array(Ann_KickLoc+1) + ! !write(*,*) '(MinKickDv-((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline))=' , (MinKickDv-((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline)) + ! + ! + ! MudSystem%NewDensity= MudSystem%St_Density%Last()*((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_Density%Array(Ann_KickLoc+1)*(MinKickDv-((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) & + ! / (((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + (MinKickDv-((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) + ! NewVolume= MinKickDv + ! + ! + ! Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)= Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) - (MinKickDv-((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)) + ! + ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 + ! + ! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv ! Op_KickLoc= last + ! + ! + ! ! backheade kick zire mate bashad + ! if ( Op_KickLoc>1) then + ! + ! + ! + ! if ( ABS(Op_Density%Array (Op_KickLoc-1) - MudSystem%NewDensity) > DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Array (Op_KickLoc-1)>42.) ) then + ! + ! + ! + ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! + ! call Op_Density%AddTo (Op_KickLoc,MudSystem%NewDensity) + ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,NewVolume) + ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) + ! call Op_MudOrKick%AddTo (Op_KickLoc,0) + ! + ! + ! else !Merge Condition + ! + ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume + ! Op_Density%Array (Op_KickLoc-1)= (Op_MudDischarged_Volume%Array (Op_KickLoc-1)*Op_Density%Array (Op_KickLoc-1)+NewVolume*MudSystem%NewDensity) / & + ! (Op_MudDischarged_Volume%Array (Op_KickLoc-1)+NewVolume) + ! + ! + ! endif + ! + ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + ! write(*,*) '****5-2 with pump' + ! + ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! + ! + ! call Op_Density%AddToFirst (MudSystem%NewDensity) + ! call Op_MudDischarged_Volume%AddToFirst (NewVolume) + ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! call Op_MudOrKick%AddToFirst (0) + ! + ! endif + ! + ! + ! + ! elseif ( MinKickDv == Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) ) then ! eleman bala sari baghi nemimund + ! write(*,*) '****4----2 with pump' + ! + ! MudSystem%NewDensity= MudSystem%St_Density%Last()*((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_Density%Array(Ann_KickLoc+1)*(MinKickDv-((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) & + ! / (((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)) + ! NewVolume= MinKickDv + ! + ! call RemoveAnnulusMudArrays(Ann_KickLoc+1) + ! + ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 + ! + ! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv ! Op_KickLoc= last + ! + ! ! backheade kick zire mate bashad + ! if (Op_KickLoc > 1) then + ! + ! if ( ABS(Op_Density%Array (Op_KickLoc-1) - MudSystem%NewDensity) > DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Array (Op_KickLoc-1)>42.) ) then + ! + ! ! + ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! + ! call Op_Density%AddTo (Op_KickLoc,MudSystem%NewDensity) + ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,NewVolume) + ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) + ! call Op_MudOrKick%AddTo (Op_KickLoc,0) + ! + ! + ! else !Merge Condition + ! + ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume + ! Op_Density%Array (Op_KickLoc-1)= (Op_MudDischarged_Volume%Array (Op_KickLoc-1)*Op_Density%Array (Op_KickLoc-1)+NewVolume*MudSystem%NewDensity) / & + ! (Op_MudDischarged_Volume%Array (Op_KickLoc-1)+NewVolume) + ! + ! + ! + ! endif + ! + ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + ! + ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! + ! + ! call Op_Density%AddToFirst (MudSystem%NewDensity) + ! call Op_MudDischarged_Volume%AddToFirst (NewVolume) + ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! call Op_MudOrKick%AddToFirst (0) + ! + ! endif + ! + ! + ! elseif ( MinKickDv == Op_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick az OP kamel kharej mishod + ! write(*,*) '****4----3 with pump b' + ! + ! MudSystem%NewDensity=MudSystem%St_Density%Last() + ! NewVolume= MinKickDv + ! + ! + ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) + ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) + ! + ! + ! !Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)= Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) - MinKickDv farz kardam dast be elemane balaee nazanam + ! + ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 + ! !write(*,*) 'pointer 1' + ! call Op_MudDischarged_Volume%Remove (Op_KickLoc) ! Op_KickLoc= last + ! call Op_Mud_Backhead_X%Remove (Op_KickLoc) + ! call Op_Mud_Backhead_section%Remove (Op_KickLoc) + ! call Op_Mud_Forehead_X%Remove (Op_KickLoc) + ! call Op_Mud_Forehead_section%Remove (Op_KickLoc) + ! call Op_Density%Remove (Op_KickLoc) + ! call Op_RemainedVolume_in_LastSection%Remove (Op_KickLoc) + ! call Op_EmptyVolume_inBackheadLocation%Remove (Op_KickLoc) + ! call Op_MudOrKick%Remove (Op_KickLoc) + ! + ! !write(*,*) 'pointer 2' + ! + ! ! backheade kick zire mate bashad + ! if (Op_KickLoc > 1) then + ! + ! if ( ABS(Op_Density%Array (Op_KickLoc-1) - MudSystem%NewDensity) > DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Array (Op_KickLoc-1)>42.) ) then + ! !write(*,*) 'pointer 3' + ! + ! + ! + ! + ! call Op_Density%AddTo (Op_KickLoc,MudSystem%NewDensity) + ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,NewVolume) + ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) + ! call Op_MudOrKick%AddTo (Op_KickLoc,0) + ! + ! !write(*,*) 'pointer 4' + ! + ! else !Merge Condition + ! + ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume + ! Op_Density%Array (Op_KickLoc-1)= (Op_MudDischarged_Volume%Array (Op_KickLoc-1)*Op_Density%Array (Op_KickLoc-1)+NewVolume*MudSystem%NewDensity) / & + ! (Op_MudDischarged_Volume%Array (Op_KickLoc-1)+NewVolume) + ! + ! endif + ! + ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + ! !write(*,*) 'pointer 5' + ! + ! + ! !write(*,*) 'pointer 6' + ! + ! + ! call Op_Density%AddToFirst (MudSystem%NewDensity) + ! call Op_MudDischarged_Volume%AddToFirst (NewVolume) + ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) + ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) + ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! call Op_MudOrKick%AddToFirst (0) + ! !write(*,*) 'pointer 7' + ! + ! endif + ! + ! + ! endif + ! + ! + ! + ! endif !( ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) < KickDv ) ! sorate pump kamtar az kick bashad + ! + ! + ! + ! + ! endif + +!======================================================================================== + +ENDDO ! KickNumber= 1, NewInfluxNumber +MudSystem%KickNumber = kickNumber + + !write(*,*) 'c)Ann_MudDischarged_Volume%Array(:)=' , sum(Ann_MudDischarged_Volume%Array(:)) + + + + end subroutine Kick_Migration \ No newline at end of file diff --git a/Equipments/MudSystem-old/MudSystem.f90 b/Equipments/MudSystem-old/MudSystem.f90 new file mode 100644 index 0000000..0798c79 --- /dev/null +++ b/Equipments/MudSystem-old/MudSystem.f90 @@ -0,0 +1,3295 @@ +module MudSystemModule + + USE MudSystemVARIABLES + use PressureDisplayVARIABLESModule + USE FricPressDropVarsModule + USE Fluid_Flow_Startup_Vars + USE CMudPropertiesVariables + USE CManifolds + USE CPumpsVariables + USE CUnityOutputs + use CWarningsVariables + use DynamicIntegerArray + use CError + use CLog1 + USE CDataDisplayConsoleVariables + use CStudentStationVariables !, PitGainLossReset=>PitGainLossZero + + + implicit none + + real j2,j12,j13,jj2,jj12,jj13 + real A71,A72,A73 + integer j3,B71,B77,B78 + integer j4 + real C71,C77,C78 + integer j5 + integer j6,D71,D80 + integer j7,j8,j9,j10,j11 + real E71,E72,E73 + real F71,F72,F73 + integer j14 + real G82,G83,G84 + integer j15 + real H82,H83,H84 + integer j16,K82,K83,K84,K79,K78 + integer j17,L82,L83,L84,L79,L78 + integer j18 + real M71,M77,M78, Pump1toCh,Pump2toCh,Pump3toCh,Denominator_a + integer j19 + real N82,N83,N84 + integer j20 + integer j21 + real unityreturn + + + + real(8) DumpPump1,DumpPump2,DumpCementPump,Denominator + real(8) Mp1Coef,Mp2Coef,CpCoef + real(8) PumpPressure1,PumpPressure2,PumpPressure3 + integer Mp1_NoPath,Mp2_NoPath,Cp_NoPath + real P1toSt,P2toSt,CptoSt + real(8) MaxWorkingPressure1,MaxWorkingPressure2,MaxWorkingPressure3,MaxWorkingPressure + + REAL(8) DumpFromKelly, DumpFromFillupHead + real(8) AddedVolumeToTank,PUMP1_Flow_Rate_Old,PUMP2_Flow_Rate_Old,PUMP3_Flow_Rate_Old + real(8) VolumeToActive,VolumeToBellNipple,BellNipple_FlowCoef,ChokeLine_FlowCoef + + + REAL RealJ2,RealJ12,RealJ13,RealJ4,RealJ18 + INTEGER active32,active33,active34,active35,active29 + + logical condition1, condition2, condition3, condition4, condition5, condition6, condition7, condition8, condition9, condition10, condition11, condition12, condition13, condition14, condition15 + logical condition16,condition17,condition18,condition19,condition20,condition21,condition22,condition23,condition24,condition25,condition26,condition27,condition28,condition29,condition30,condition31 + logical condition32,condition33,condition34,condition35,condition36,condition37,condition38,condition39,condition40,condition41,condition42,condition43,condition44,condition45 + logical condition46,condition47,condition48,condition49,condition50,condition51,condition52,condition53,condition54,condition55,condition56,condition57,condition58 + logical condition59,condition60,condition61 + logical ac32, ac33, ac34, ac35, ac29 + logical ThereIsPathFrom_71_72_73_To_82, ThereIsPathFrom_71_72_73_To_83, ThereIsPathFrom_71_72_73_To_84 + logical DumpFromKelly_Pump1, DumpFromKelly_Pump2, DumpFromKelly_Pump3 + logical DumpFromTopDrive_Pump1,DumpFromTopDrive_Pump2,DumpFromTopDrive_Pump3 + logical DumpFromFillupHead_Pump1, DumpFromFillupHead_Pump2, DumpFromFillupHead_Pump3 + logical State1,State2, State3, State4 + type(DynamicIntegerArrayType) Pump1_Lasts,Pump2_Lasts, Pump3_Lasts + REAL MP1_Q, MP2_Q, MP3_Q + real TimePassed + + real(8) active_after, active_before, active_increase, total_active_increase,total_decrease,sys_total_injected + real(8) total_annFlow,total_DeltaVPipe + contains + + subroutine LineupAndPath() + implicit none + +!=========================================================================== +! MUDLINE CODE +!=========================================================================== + ! Initialize + j2=0 + jj2=0 + A71=0 + A72=0 + A73=0 + RealJ2=0.0 + + j3=0 + B71=0 + B77=0 + B78=0 + + j4=0 + C71=0. + C77=0. + C78=0. + active32=0 + active33=0 + active34=0 + active35=0 + active29=0 + + + j5=0 + + j6=0 + D71=0 + D80=0 + + j7=0 + + j8=0 + + j9=0 + j10=0 + j11=0 + + j12=0 + jj12=0 + E71=0 + E72=0 + E73=0 + RealJ12=0.0 + + j13=0 + jj13=0 + F71=0 + F72=0 + F73=0 + RealJ13=0.0 + + j14=0 + G82=0 + G83=0 + G84=0 + + DumpPump1=0. + DumpPump2=0. + DumpCementPump=0. + + j15=0 + H82=0.0 + H83=0.0 + H84=0.0 + + Mp1Coef= 0.0 + Mp1Coef= 0.0 + CpCoef= 0.0 + + Mp1_NoPath= 0 + Mp2_NoPath= 0 + Cp_NoPath= 0 + + j16=0 + K82=0 + K83=0 + K84=0 + K78=0 + K79=0 + + + j17=0 + L82=0 + L83=0 + L84=0 + L78=0 + L79=0 + + j18=0 + M71=0. + M77=0. + M78=0. + Pump1toCh=0. + Pump2toCh=0. + Pump3toCh=0. + + + j19=0 + N82=0 + N83=0 + N84=0 + + j20=0 + + j21=0 + + + +!=========================================================================== + + !===============TanksToMudPump1================= + if(condition1) then + j2=j2+1 + A71=1 + jj2=1 + endif + + if(condition2) then + j2=j2+1 + A72=1 + jj2=1 + endif + + if(condition3) then + j2=j2+1 + A73=1 + jj2=1 + endif + + !================================================ + + !============BellNippleToPits-FullWell============== + if(MudSystem%FirstMudSet== 1 ) then !.and. WellisNOTFull== .false.) then ! Well Must Be Full !Ann_Mud_Forehead_X%Last()==AboveAnnularHeight .and. Ann_Density%Last()/=0.0) + if(condition4) then + j3=j3+1 + B71=1 + endif + + if(condition5) then + j3=j3+1 + B77=1 + endif + + if(condition6) then + j3=j3+1 + B78=1 + endif + + endif + + !================================================ + + !============WellToChokeManifold(Through 26)============== + if(condition7) then + j4=j4+1 + C71=1. + endif + + if(condition8) then + j4=j4+1 + C77=1. + endif + + if(condition45) then + j4=j4+1 + C78=1. + endif + if (ac32) active32=1 + if (ac33) active33=1 + if (ac34) active34=1 + if (ac35) active35=1 + if (ac29) active29=1 !BYPASS VALVE + + + + !================================================ + + + !============ActiveTankToTripTank============== + if(condition9) then + j5=j5+1 + endif + !================================================ + + !write(*,*) 'j5====' , j5 + !============TripTankToActiveTank And BellNipple============== + if(condition10) then + j6=j6+1 + D71=1 + endif + + if(condition11) then + j6=j6+1 + D80=1 + endif + !================================================ + + !============ActiveTankToDump============== + if(condition12) then + j7=j7+1 + endif + !================================================ + + !============TripTankToDump============== + if(condition13) then + j8=j8+1 + endif + !================================================ + + !============WellToBellNipple============== + if(condition14) then + j9=j9+1 + endif + !================================================ + + !============MudBucketToBellNipple============== + if(condition15) then + j10=j10+1 + endif + !================================================ + + !============BellNippleToWell-NonFullWell============== + + + if(condition16 .and. MudSystem%FirstMudSet== 1 .and. MudSystem%BellNippleVolume > 0.0001 .and. MudSystem%WellisNOTFull) then + + write(*,*) 'MUD(7)%Q=' , MUD(7)%Q + write(*,*) 'BellNippleVolume=' , MudSystem%BellNippleVolume + + + write(*,*) 'MudSystem%MudVolume_InjectedFromAnn-WellToBellNipple=' , MudSystem%MudVolume_InjectedFromAnn + + write(*,*) 'int:::=' , (MudSystem%Ann_Mud_Forehead_X%Last() - BopStackSpecification%AboveAnnularHeight) + write(*,*) 'Ann_Mud_Forehead_X%Last()=' , MudSystem%Ann_Mud_Forehead_X%Last() + write(*,*) 'AboveAnnularHeight=' , BopStackSpecification%AboveAnnularHeight + write(*,*) 'Ann_Density%Last()=' , MudSystem%Ann_Density%Last() + CALL ErrorStop('error stop1') + + j11=j11+1 + endif + !================================================ + + !===============TanksToMudPump2=================== + + if(condition17) then + j12=j12+1 + E71=1 + jj12=1 + endif + + if(condition18) then + j12=j12+1 + E72=1 + jj12=1 + endif + + if(condition19) then + j12=j12+1 + E73=1 + jj12=1 + endif + + !================================================ + + !===============TanksToCementPump=================== + if(condition20) then + j13=j13+1 + F71=1 + jj13=1 + endif + + if(condition21) then + j13=j13+1 + F72=1 + jj13=1 + endif + + if(condition22) then + j13=j13+1 + F73=1 + jj13=1 + endif + + !================================================ + + !===============PumpsToString=================== + if(condition23) then + j14=j14+1 + G82=1 + endif + + if(condition24) then + j14=j14+1 + G83=1 + endif + + if(condition25) then + j14=j14+1 + G84=1 + endif + !================================================ + + + !===============PumpsToDump=================== + if(condition26) then + DumpPump1=1.0 + endif + + if(condition27) then + DumpPump2=1.0 + endif + + if(condition28) then + DumpCementPump=1.0 + endif + !================================================ + + + !=======MudPumps1&2ToActiveTank_Through65&66========== + if(condition29) then + !write(*,*) 'condition 29' + j15=j15+1 + H82=1.0 + endif + + if(condition30) then + j15=j15+1 + H83=1.0 + endif + + !================================================ + + + !=======CementPumpToActiveTank_Through65========== + + if(condition31) then + + H84=1.0 + + endif + !================================================ + + !write(*,*) 'condition32===' , condition32 + + !============MudPump1HasNoPath=================== + if(MudSystem%condition32Final) then + !write(*,*) 'MudPump1HasNoPath' + Mp1_NoPath = 1 + endif + !================================================ + + !============MudPump2HasNoPath=================== + if(MudSystem%condition33Final) then + !write(*,*) 'MudPump2HasNoPath' + Mp2_NoPath = 1 + endif + !================================================ + + + !============CementPumpHasNoPath=================== + if(MudSystem%condition34Final) then + Cp_NoPath = 1 + endif + !================================================ + + !===============PathsToGauge75=================== + if(condition35) then !Pump1 to Gauge75 + j16=j16+1 + K82=1 + endif + + if(condition36) then !Pump2 to Gauge75 + j16=j16+1 + K83=1 + endif + + if(condition37) then !Pump3 to Gauge75 + j16=j16+1 + K84=1 + endif + + if(condition38) then !String to Gauge75 + j16=j16+1 + K79=1 + endif + + if(condition39) then !Dump to Gauge75 + j16=j16+1 + K78=1 + endif + + !================================================ + !write(*,*) '****j16=' , j16 + !===============PathsToGauge76=================== + if(condition40) then !Pump1 to Gauge76 + j17=j17+1 + L82=1 + endif + + if(condition41) then !Pump2 to Gauge76 + j17=j17+1 + L83=1 + endif + + if(condition42) then !Pump3 to Gauge76 + j17=j17+1 + L84=1 + endif + + if(condition43) then !String to Gauge76 + j17=j17+1 + L79=1 + endif + + if(condition44) then !Dump to Gauge76 + j17=j17+1 + L78=1 + endif + + !================================================ + + !====Pump1-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(condition46) then + j18=j18+1 + M71=1. + Pump1toCh= 1. + endif + + if(condition47) then + j18=j18+1 + M77=1. + Pump1toCh= 1. + endif + + if(condition48) then + j18=j18+1 + M78=1. + Pump1toCh= 1. + endif + !================================================================= + + + !====Pump2-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(condition49) then + j18=j18+1 + M71=1. + Pump2toCh= 1. + endif + + if(condition50) then + j18=j18+1 + M77=1. + Pump2toCh= 1. + endif + + if(condition51) then + j18=j18+1 + M78=1. + Pump2toCh= 1. + endif + !================================================================= + + + !====Pump3-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(condition52) then + j18=j18+1 + M71=1. + Pump3toCh= 1. + endif + + if(condition53) then + j18=j18+1 + M77=1. + Pump3toCh= 1. + endif + + if(condition54) then + j18=j18+1 + M78=1. + Pump3toCh= 1. + endif + !================================================================= + + + !===============PumpsToWell_KillLine============ + if(condition55) then + j19=j19+1 + N82=1 + endif + + if(condition56) then + j19=j19+1 + N83=1 + endif + + if(condition57) then + j19=j19+1 + N84=1 + endif + !================================================ + + !===============WellToChokeLineGauge============ + if(condition58) then + j20=j20+1 + endif + + if (j20>0) then + MudSystem%WellToChokeLineGauge= .true. + else + MudSystem%WellToChokeLineGauge= .false. + endif + !================================================ + + + !============ChokeLineGaugeToTanks=============== + if(condition59) then + j21=j21+1 + endif + + if(condition60) then + j21=j21+1 + endif + + if(condition61) then + j21=j21+1 + endif + + if (j21>0) then + MudSystem%ChokeLineGaugeToTanks= .true. + else + MudSystem%ChokeLineGaugeToTanks= .false. + endif + !================================================ + + + end subroutine + + subroutine main + Use GeoElements_FluidModule + USE Pumps_VARIABLES + USE CHOKEVARIABLES + USE CDataDisplayConsoleVariables + use CDrillWatchVariables + use CHOKEVARIABLES + use CChokeManifoldVariables + use CTanksVariables + use KickVARIABLESModule + Use CHoistingVariables + ! use CSimulationVariables + + implicit none + Integer I + + MudSystem%MudSys_timeCounter = MudSystem%MudSys_timeCounter + 1 + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + MudSystem%MudSys_timeCounter= 0 + endif + + !WRITE (*,*) 'MudSys_timeCounter', MudSys_timeCounter + if (PumpsSpecification%MudPump1ReliefValveIsSet==.false.) PumpsSpecification%MudPump1ReliefValvePressure=6000. + if (PumpsSpecification%MudPump2ReliefValveIsSet==.false.) PumpsSpecification%MudPump2ReliefValvePressure=6000. + if (PumpsSpecification%CementPumpReliefValveIsSet==.false.) PumpsSpecification%CementPumpReliefValvePressure=6000. + !=========================================================================================================================== + !=========================================================================================================================== + ! >>> Should Be on Top of Other Codes <<< + + + !ActiveTankVolume= ActiveMudVolumeGal ! update from student input + !ActiveTankDensity= ActiveDensity ! update from student input + !ReserveTankVolume= ReserveMudVolumeGal ! update from student input + !ReserveTankDensity= ReserveDensity ! update from student input + if (j7 > 0) then !ActiveTankToDump + MudSystem%ActiveTankDensity= 0. + MudSystem%ActiveTankVolume= 0. + endif + + if (j8 > 0) then !TripTankToDump + MudSystem%TripTankDensityCalc= 0. + MudSystem%TripTankVolumeCalc= 0. + endif + !=========================================================================================================================== + !=========================================================================================================================== + if (j15 > 0) then !MudPumps1&2ToActiveTank_Through65&66 + !write(*,*) 'j15 is open' + ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + if (j2>0) Mp1Coef= 1.0 + if (j12>0) Mp2Coef= 1.0 + if (j2 /= 0 .or. j12/= 0) then + MudSystem%ActiveTankDensity = (MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume+ Mp1Coef*MudSystem%Mp1Density*(PUMP(1)%Flow_Rate*MudSystem%DeltaT_Mudline/60.) + Mp2Coef*MudSystem%Mp2Density*(PUMP(2)%Flow_Rate*MudSystem%DeltaT_Mudline/60.))/ & + (MudSystem%ActiveTankVolume+ Mp1Coef*(PUMP(1)%Flow_Rate*MudSystem%DeltaT_Mudline/60.) + Mp2Coef*(PUMP(2)%Flow_Rate*MudSystem%DeltaT_Mudline/60.)) + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ Mp1Coef*PUMP(1)%Flow_Rate*MudSystem%DeltaT_Mudline/60. + Mp2Coef*PUMP(2)%Flow_Rate*MudSystem%DeltaT_Mudline/60. + !write(*,*) 'active by j15' + endif + MudSystem%ActiveTankVolume=min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal) + !if ActiveTankVolume is higher, excess amount is dumped + endif + if (H84 > 0.0) then !CementPumpToCementTank_Through67 + if (j13>0) CpCoef= 1.0 + MudSystem%CementTankDensityCalc= (MudSystem%CementTankDensityCalc*MudSystem%CementTankVolumeCalc+ CpCoef*MudSystem%Mp3Density*(PUMP(3)%Flow_Rate*MudSystem%DeltaT_Mudline/60.) ) / & + (MudSystem%CementTankVolumeCalc+CpCoef*(PUMP(3)%Flow_Rate*MudSystem%DeltaT_Mudline/60.)) + MudSystem%CementTankVolumeCalc= MudSystem%CementTankVolumeCalc+ CpCoef*(PUMP(3)%Flow_Rate*MudSystem%DeltaT_Mudline/60.) + endif + !=========================================================================================================================== + !=========================================================================================================================== + ! DUMP Path + MudSystem%PumpsDumpVolume= MudSystem%PumpsDumpVolume+ (jj2*(1-H82)*DumpPump1*PUMP(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*PUMP(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*PUMP(3)%Flow_Rate) *MudSystem%DeltaT_Mudline/60. + MudSystem%PumpsDumpFlowRate= jj2*(1-H82)*DumpPump1*PUMP(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*PUMP(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*PUMP(3)%Flow_Rate + !write(*,*) 'PumpsDumpFlowRate=' , PumpsDumpFlowRate + + if (Hoisting%DriveType==1 .and. MudSystem%PumpsDumpFlowRate > 0.0 .and. (DumpFromKelly_Pump1 .or. DumpFromKelly_Pump2 .or. DumpFromKelly_Pump3)) then + !write(*,*) 'Set_FlowFromKelly(.TRUE.)' + call Activate_PumpWithKellyDisconnected() + !write(*,*) 'PumpsDumpFlowRate=' , PumpsDumpFlowRate + CALL Set_FlowFromKelly(min(MudSystem%PumpsDumpFlowRate/6.,100.)) ! .TRUE. before + elseif (Hoisting%DriveType==1) then + call Deactivate_PumpWithKellyDisconnected() + CALL Set_FlowFromKelly(0.0) ! .FALSE. before + !write(*,*) 'Set_FlowFromKelly(.FALSE.)' + endif + !write(*,*) 'DumpFromFillupHead_Pump1=' , DumpFromFillupHead_Pump1 + if (Hoisting%DriveType==0 .and. MudSystem%PumpsDumpFlowRate > 0.0 .and. (DumpFromTopDrive_Pump1 .or. DumpFromTopDrive_Pump2 .or. DumpFromTopDrive_Pump3)) then + !write(*,*) 'Set_FlowFromKelly(.TRUE.)' + call Activate_PumpWithTopdriveDisconnected() + CALL Set_FlowFromKelly(min(MudSystem%PumpsDumpFlowRate/6.,100.)) ! .TRUE. before + elseif (Hoisting%DriveType==0) then + call Deactivate_PumpWithTopdriveDisconnected() + CALL Set_FlowFromKelly(0.0) ! .FALSE. before + !write(*,*) 'Set_FlowFromKelly(.FALSE.)' + endif + if (MudSystem%PumpsDumpFlowRate > 0.0 .and. (DumpFromFillupHead_Pump1 .or. DumpFromFillupHead_Pump2 .or. DumpFromFillupHead_Pump3)) then + !call Activate_PumpWithKellyDisconnected() + CALL Set_FlowFromFillupHead(min(MudSystem%PumpsDumpFlowRate/6.,100.)) ! .TRUE. before + else + !call Deactivate_PumpWithKellyDisconnected() + CALL Set_FlowFromFillupHead(0.0) ! .FALSE. before + endif + !####C_Program -----> DriveType = + ! = 0 TopDrive_DriveType + ! = 1 Kelly_DriveType + !=========================================================================================================================== + !=========================================================================================================================== + ! ****** Calculating Maximum Working Pressure + if (PumpsSpecification%MudPump1ReliefValveIsSet) then + MaxWorkingPressure1= PumpsSpecification%MudPump1ReliefValvePressure + else + MaxWorkingPressure1= 6000. !psi + endif + if (PumpsSpecification%MudPump2ReliefValveIsSet) then + MaxWorkingPressure2= PumpsSpecification%MudPump2ReliefValvePressure + else + MaxWorkingPressure2= 6000. !psi + endif + if (PumpsSpecification%CementPumpReliefValveIsSet) then + MaxWorkingPressure3= PumpsSpecification%CementPumpReliefValveIsSet + else + MaxWorkingPressure3= 6000. !psi + endif + if (State1) then + MaxWorkingPressure= min(MaxWorkingPressure1 , MaxWorkingPressure2 , MaxWorkingPressure3) + MaxWorkingPressure1= MaxWorkingPressure + MaxWorkingPressure2= MaxWorkingPressure + MaxWorkingPressure3= MaxWorkingPressure + endif + if (State2) then + MaxWorkingPressure= min(MaxWorkingPressure1 , MaxWorkingPressure2) + MaxWorkingPressure1= MaxWorkingPressure + MaxWorkingPressure2= MaxWorkingPressure + endif + if (State3) then + MaxWorkingPressure= min(MaxWorkingPressure1 , MaxWorkingPressure3) + MaxWorkingPressure1= MaxWorkingPressure + MaxWorkingPressure3= MaxWorkingPressure + endif + if (State4) then + MaxWorkingPressure= min(MaxWorkingPressure2 , MaxWorkingPressure3) + MaxWorkingPressure2= MaxWorkingPressure + MaxWorkingPressure3= MaxWorkingPressure + endif + ! Calculating Maximum Working Pressure ****** + !=========================================================================================================================== + !=========================================================================================================================== + + + ! ****** Blown Conditions + + !G: PumpsToString Coefficient + !jJ2,Jj12,Jj13: TanksToMudPump Coefficient + !H: Pumps To Tank_Through65 or 67 Coefficient + + !write(*,*) 'j12=' , j12 + !write(*,*) 'H83=' , H83 + !write(*,*) 'DumpPump2=' , DumpPump2 + !write(*,*) 'G83=' , G83 + PumpPressure1= jj2*(1-H82)*(1-DumpPump1)*G82* PressureGauges(1) + PumpPressure2= jj12*(1-H83)*(1-DumpPump2)*G83* PressureGauges(1) + PumpPressure3= jj13*(1-H84)*(1-DumpCementPump)*G84* PressureGauges(1) + ! + !write(*,*) 'jj2 , H82 , DumpPump1 , G82,PresCsureGauges(1)=' , jj2 , H82 , DumpPump1 , G82,PressureGauges(1) + !write(*,*) '1)PumpPressure1=' , PumpPressure1 + !write(*,*) 'PumpPressure2=' , PumpPressure2 + PumpToManifoldMudVol = 3.0 * 42.0 + !PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP1_Q / ConvMinToSec * dt + !PumpToManifoldDeltaPDueToCompressibility = PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol) + IF(Mp1_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_82 .and. MP1_Q > 0.0) then + PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP1_Q / ConvMinToSec * dt + PumpPressure1= PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol) + write(*,*) '21)PumpPressure1=' , PumpPressure1 + WRITE (*,*) ' valve 1 ', Manifold%Valve(1)%Status + WRITE (*,*) ' valve 4 ', Manifold%Valve(4)%Status + WRITE (*,*) ' valve 6 ', Manifold%Valve(6)%Status + WRITE (*,*) ' valve 7 ', Manifold%Valve(7)%Status + WRITE (*,*) ' valve 8 ', Manifold%Valve(8)%Status + WRITE (*,*) ' valve 9 ', Manifold%Valve(9)%Status + WRITE (*,*) ' valve 13 ', Manifold%Valve(13)%Status + WRITE (*,*) ' valve 68 ', Manifold%Valve(68)%Status + WRITE (*,*) ' valve 69 ', Manifold%Valve(69)%Status + WRITE (*,*) ' valve 48 ', Manifold%Valve(48)%Status + !call DisplayOpenPathsWrite() + ENDIF + + IF(Mp2_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_83 .and. MP2_Q > 0.0 ) then + PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP2_Q / ConvMinToSec * dt + PumpPressure2= PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol) + write(*,*) '22)PumpPressure1=' , PumpPressure2 + WRITE (*,*) ' -valve 1 ', Manifold%Valve(1)%Status + WRITE (*,*) ' -valve 4 ', Manifold%Valve(4)%Status + WRITE (*,*) ' -valve 6 ', Manifold%Valve(6)%Status + WRITE (*,*) ' -valve 7 ', Manifold%Valve(7)%Status + WRITE (*,*) ' -valve 8 ', Manifold%Valve(8)%Status + WRITE (*,*) ' -valve 9 ', Manifold%Valve(9)%Status + WRITE (*,*) ' -valve 13 ', Manifold%Valve(13)%Status + WRITE (*,*) ' -valve 68 ', Manifold%Valve(68)%Status + WRITE (*,*) ' -valve 69 ', Manifold%Valve(69)%Status + WRITE (*,*) ' -valve 48 ', Manifold%Valve(48)%Status + !call DisplayOpenPathsWrites() + ENDIF + + IF(Cp_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_84 .AND. MP3_Q > 0.0 ) then + PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP3_Q / ConvMinToSec * dt + PumpPressure3= PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol) + ENDIF + !***************************************************************************** + !if(((Mp1_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_82) .or. ( PumpPressure1 >= MaxWorkingPressure1 ) & + !.or.(J14> 0 .and. j4==0 .and. j9==0 .and. NOT(ALLOCATED(GasPocketWeight%Array)))) .and. MP1_Q > 0.0 ) then + !write(*,*) ' failurrrrre ' + + if (PumpPressure1 >= MaxWorkingPressure1 .and. MP1_Q > 0.0) then + write(*,*) 'mp1,if=' , PumpPressure1 , MaxWorkingPressure1 , MP1_Q + MudSystem%Pump1BlownCount = MudSystem%Pump1BlownCount + 1 + !if (Pump1BlownStarted == .FALSE.) then + ! write(*,*) 'if (Pump1BlownStarted == .FALSE. ) then' + ! Pump1BlownInTimeStep = SimulationTime + BlownThresholdInSecond + ! Pump1BlownStarted = .TRUE. + !endif + !write(*,*) 'SimulationTime===', SimulationTime, Pump1BlownInTimeStep + if(PumpsSpecification%MudPump1ReliefValveIsSet .and. MudSystem%Pump1BlownCount >= BlownThreshold) then + write(*,*) 'valve 65 open, BLOWN' + call ChangeValve(65, .TRUE.) + PumpToManifoldCompressedMudVol= 0.0 + MudSystem%Pump1BlownCount = 0 + !Pump1BlownStarted = .FALSE. + !else + ! write(*,*) 'PumpPressure1= 6000 psi' + ! PumpPressure1= 6000. !psi + endif + !else + !Pump1BlownInTimeStep = 0 + !Pump1BlownStarted = .FALSE. + !write(*,*) 'Pump1BlownStarted = .FALSE.' + endif + + !write(*,*) ' valve 65=' , Valve(65)%Status + !if(((Mp2_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_83) .or. PumpPressure2 >= MaxWorkingPressure2 & + !.or.(J14> 0 .and. j4==0 .and. j9==0 .and. NOT(ALLOCATED(GasPocketWeight%Array))) ) .and. MP2_Q > 0.0 ) then + + if(PumpPressure2 >= MaxWorkingPressure2 .and. MP2_Q > 0.0 ) then + write(*,*) 'mp2,if=' , PumpPressure2 , MaxWorkingPressure2 , MP2_Q + MudSystem%Pump2BlownCount = MudSystem%Pump2BlownCount + 1 + !if (Pump2BlownStarted == .FALSE. ) then + ! Pump2BlownInTimeStep = SimulationTime + BlownThresholdInSecond + ! Pump2BlownStarted = .TRUE. + !endif + !if (MudPump2ReliefValveIsSet .and. SimulationTime >= Pump2BlownInTimeStep .and. Pump2BlownStarted) then + if (PumpsSpecification%MudPump2ReliefValveIsSet .and. MudSystem%Pump2BlownCount >= BlownThreshold) then + write(*,*) 'valve 66 open, BLOWN' + call ChangeValve(66, .TRUE.) + PumpToManifoldCompressedMudVol= 0.0 + MudSystem%Pump2BlownCount = 0 + !Pump2BlownInTimeStep = 0 + !Pump2BlownStarted = .FALSE. + !else + ! PumpPressure2= 6000. !psi + endif + !else + !Pump2BlownInTimeStep = 0 + !Pump2BlownStarted = .FALSE. + endif + !if(((Cp_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_84) .or. PumpPressure3 >= MaxWorkingPressure3 & + !.or.(J14> 0 .and. j4==0 .and. j9==0 .and. NOT(ALLOCATED(GasPocketWeight%Array)))) .and. MP3_Q > 0.0 ) then + + if(PumpPressure3 >= MaxWorkingPressure3 .and. MP3_Q > 0.0 ) then + MudSystem%Pump3BlownCount = MudSystem%Pump3BlownCount + 1 + if (PumpsSpecification%CementPumpReliefValveIsSet .and. MudSystem%Pump3BlownCount >= BlownThreshold) then + !write(*,*) 'valve 67 open, BLOWN' + call ChangeValve(67, .TRUE.) + PumpToManifoldCompressedMudVol= 0.0 + MudSystem%Pump3BlownCount = 0 + !else + ! PumpPressure3= 6000. !psi + endif + !else + !Pump3BlownInTimeStep = 0 + !Pump3BlownStarted = .FALSE. + endif + !write(*,*) '3)PumpPressure1=' , PumpPressure1 + if (PumpPressure1>= 6000.) then + MudSystem%Pump1BlownCount = MudSystem%Pump1BlownCount + 1 + if(MudSystem%Pump1BlownCount >= BlownThreshold) then + call ChangeValve(65, .TRUE.) + PumpToManifoldCompressedMudVol= 0.0 + call Activate_Pump1Failure() + MudSystem%Pump1OffFailure= .true. + MudSystem%Pump1BlownCount = 0 + endif + !else + !Pump1BlownInTimeStep = 0 + !Pump1BlownStarted = .FALSE. + endif + + if (PumpPressure2>= 6000.) then + MudSystem%Pump2BlownCount = MudSystem%Pump2BlownCount + 1 + if(MudSystem%Pump2BlownCount >= BlownThreshold) then + call ChangeValve(66, .TRUE.) + PumpToManifoldCompressedMudVol= 0.0 + call Activate_Pump2Failure() + MudSystem%Pump2OffFailure= .true. + MudSystem%Pump2BlownCount = 0 + endif + !else + !Pump2BlownInTimeStep = 0 + !Pump2BlownStarted = .FALSE. + endif + + if (PumpPressure3>= 6000.) then + MudSystem%Pump3BlownCount = MudSystem%Pump3BlownCount + 1 + if(MudSystem%Pump3BlownCount >= BlownThreshold) then + call ChangeValve(67, .TRUE.) + PumpToManifoldCompressedMudVol= 0.0 + call Activate_Pump3Failure() + MudSystem%Pump3OffFailure= .true. + MudSystem%Pump3BlownCount = 0 + endif + !else + !Pump3BlownInTimeStep = 0 + !Pump3BlownStarted = .FALSE. + endif + ! Blown Conditions ******** + !=========================================================================================================================== + !=========================================================================================================================== + if (j9 > 0 ) then !.and. WellisNOTFull== .false.) then !WellToBellNipple + !write(*,*) 'j9 is open' + !MUD(7)%Q= ( Ann_Saved_MudDischarged_Volume_Final+Ann_Kick_Saved_Volume_Final - ((Qlost/60.0d0)*DeltaT_Mudline) )*60.d0/DeltaT_Mudline + MUD(7)%Q= ( MudSystem%MudVolume_InjectedFromAnn + MudSystem%Ann_Kick_Saved_Volume )*60.d0/MudSystem%DeltaT_Mudline !Injected is referred only to Mud + if (j4 > 0) then + BellNipple_FlowCoef= 13.625/(13.625+BopStackSpecification%ChokeLineId) ! 13.625= BellNipple ID (inch) + MUD(7)%Q= BellNipple_FlowCoef * MUD(7)%Q + endif + + !total_annFlow= total_annFlow+(AnnulusFlowRateFinal/600.d0) + !total_DeltaVPipe= total_DeltaVPipe + DeltaVolumePipe + !write(*,*) 'total_annFlow,total_DeltaVPipe' , total_annFlow,total_DeltaVPipe + if (MUD(7)%Q < 0.0 ) MUD(7)%Q= 0.0 !.or. WellisNOTFull== .true.) MUD(7)%Q= 0.0 + !!AnnulusFlowRateFinal: flow from string mud , DeltaVolumeOp: due to trip in + + !write(*,*) 'MUD(7)%Q=' , MUD(7)%Q + !write(*,*) 'MudSystem%MudVolume_InjectedFromAnn-WellToBellNipple=' , MudSystem%MudVolume_InjectedFromAnn + !write(*,*) 'Ann_Kick_Saved_Volume=' , Ann_Kick_Saved_Volume + sys_total_injected= sys_total_injected+ MudSystem%MudVolume_InjectedFromAnn + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + sys_total_injected= 0. + endif + !write(*,*) 'sys_total_injected=' , sys_total_injected + !WellOutletDensity= Ann_Density%Last() ! (ppg) <<< in CirculationCodeSelect Code + if ((MudSystem%BellNippleVolume+((MUD(7)%Q/60.)*MudSystem%DeltaT_Mudline)) /= 0.0) then + MudSystem%BellNippleDensity= ((MudSystem%BellNippleDensity*MudSystem%BellNippleVolume)+(MudSystem%WellOutletDensity*(MUD(7)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%BellNippleVolume+((MUD(7)%Q/60.)*MudSystem%DeltaT_Mudline)) + else + MudSystem%BellNippleDensity= 0.0 + endif + !IF (WellisNOTFull== .false.) THEN ! well must be full to do this order + MudSystem%BellNippleVolume= MudSystem%BellNippleVolume+ ((MUD(7)%Q/60.)*MudSystem%DeltaT_Mudline) + !ENDIF + VolumeToBellNipple= VolumeToBellNipple + MudSystem%BellNippleVolume + !write(*,*) 'VolumeToBellNipple*****=' , VolumeToBellNipple + !write(*,*) 'BellNippleVolume in j9=' , BellNippleVolume , MUD(7)%Q + endif + + if (j9 == 0 ) then !.or. WellisNOTFull== .true.) then + !write(*,*) 'WellisNOTFull=' , WellisNOTFull + MUD(7)%Q=0.0 ! for normal circulation input + endif + + if (j9 > 0) then + MudSystem%WellToPitsOpen= .true. + else + MudSystem%WellToPitsOpen= .false. + endif + !=========================================================================================================================== + !=========================================================================================================================== + if (j10 > 0) then !MudBucketToBellNipple + !write(*,*) 'j10 is open' + !MudBucketVolume= 0. + !MudBucketDensity= 0. + ! MudBucketVolume gets value in DisconnectingPipe subroutine + MudSystem%BellNippleVolume= MudSystem%BellNippleVolume+ MudSystem%MudBucketVolume + MudSystem%BellNippleDensity= MudSystem%ActiveTankDensity + MudSystem%MudBucketVolume= 0. + endif + !=========================================================================================================================== + !=========================================================================================================================== + if (j6 > 0) then !TripTankToActiveTank And BellNipple + !write(*,*) 'j6 is open' + !write(*,*) 'active by j6' + MUD(6)%Q= 300. ! constant flow rate(gpm) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc - ((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline) + !write(*,*) 'ActiveTankVolume before=', ActiveTankVolume + if (j6 == 1 .and. D71==1) then + !write(*,*) 'add to active' + MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%TripTankDensityCalc*(MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline) + !write(*,*) 'ActiveTankVolume after=', ActiveTankVolume + + endif + + if (j6 == 1 .and. D80==1) then + MudSystem%BellNippleDensity= ((MudSystem%BellNippleDensity*MudSystem%BellNippleVolume)+(MudSystem%TripTankDensityCalc*(MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%BellNippleVolume+((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%BellNippleVolume= MudSystem%BellNippleVolume+ ((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline) + endif + + if (j6 == 2) then + MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%TripTankDensityCalc*(0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+((0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%BellNippleDensity= ((MudSystem%BellNippleDensity*MudSystem%BellNippleVolume)+(MudSystem%TripTankDensityCalc*(0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%BellNippleVolume+((0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline)) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline) + MudSystem%BellNippleVolume= MudSystem%BellNippleVolume+ ((0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline) + endif + MudSystem%ActiveTankVolume=min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal) + !if ActiveTankVolume is higher, excess amount is dumped + endif + + if (j6 == 0) then + MUD(6)%Q=0.0 + endif + !=========================================================================================================================== + !=========================================================================================================================== + CALL Set_FlowFromReturnLine(.false.) + if (j3 > 0) then !BellNippleToPits-FullWell - must be after **WellToBellNipple(j9)** + !write(*,*) 'j3 is open' + !write(*,*) 'active by j3' + !BellNipple flow rate= sum flow rate (well+ mudbucket+ triptank) + !Well to BellNipple: BellNippleVolume + !MudBucket to BellNipple: BellNippleVolume + !TripTnak to BellNipple: BellNippleVolume + MUD(3)%Q = (MudSystem%BellNippleVolume/MudSystem%DeltaT_Mudline)*60.d0 ! (gpm) + !write(*,*) 'BellNippleVolume in j3 =' , BellNippleVolume + !write(*,*) 'MUD(3)%Q =' , MUD(3)%Q + call Set_FlowRate(real(100.*min(MUD(3)%Q,MudSystem%PedalMeter)/MudSystem%PedalMeter, 8)) ! for unity display + unityreturn = real(100.*min(MUD(3)%Q,MudSystem%PedalMeter)/MudSystem%PedalMeter, 8) + !write(*,*) 'unity return=' , real(100.*min(MUD(3)%Q,PedalMeter)/PedalMeter, 8) + if (MUD(3)%Q > MudSystem%PedalMeter .and. B78==0) then + MudSystem%BellNippleDumpVolume= MudSystem%BellNippleDumpVolume + ((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline - (MudSystem%PedalMeter/60.)*MudSystem%DeltaT_Mudline) + !BellNippleDumpRate= MUD(3)%Q - PedalMeter + CALL Set_FlowFromReturnLine(.TRUE.) ! for unity display + endif + !VolumeToActive = VolumeToActive + BellNippleVolume + !write(*,*) 'VolumeToActive*******=' , VolumeToActive + active_before= MudSystem%ActiveTankVolume + MudSystem%BellNippleVolume= MudSystem%BellNippleVolume- ((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline) ! to be 0. + if ( MudSystem%BellNippleDensity > 1.0) then + if (j3 == 1 .and. B71==1) then !(volumes in galon) + MUD(3)%Q = min(MUD(3)%Q , MudSystem%PedalMeter) + !write(*,*) 'MUD(3)%Q=' , MUD(3)%Q + IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN + MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%BellNippleDensity*(MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline) + !write(*,*) 'active increase bell 1=' , ((MUD(3)%Q/60.)*DeltaT_Mudline) + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity > MudSystem%ActiveTankDensity) THEN + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((20.8d0-MudSystem%BellNippleDensity)/(20.8d0-MudSystem%ActiveTankDensity))*((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed cutting density = 20.8 ppg + !write(*,*) 'active increase bell 2=' , ((20.8d0-BellNippleDensity)/(20.8d0-ActiveTankDensity))*((MUD(3)%Q/60.d0)*DeltaT_Mudline) + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity < 5.0) THEN + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((2.d0-MudSystem%BellNippleDensity)/(2.d0-MudSystem%ActiveTankDensity))*((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + !write(*,*) 'active increase bell 3=' , ((2.d0-BellNippleDensity)/(2.d0-ActiveTankDensity))*((MUD(3)%Q/60.d0)*DeltaT_Mudline) + ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%BellNippleDensity .and. MudSystem%BellNippleDensity <= MudSystem%ActiveTankDensity) THEN + !write(*,*) ' Auto true 3' + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) + !write(*,*) 'active increase bell 4=' , ((MUD(3)%Q/60.d0)*DeltaT_Mudline) + ENDIF + endif + if (j3 == 1 .and. B77==1) then + MUD(3)%Q = min(MUD(3)%Q , MudSystem%PedalMeter) + IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%BellNippleDensity*(MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity > MudSystem%ActiveTankDensity) THEN + AddedVolumeToTank= ((20.8d0-MudSystem%BellNippleDensity)/(20.8d0-MudSystem%ActiveTankDensity))*((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity < 5.0) THEN + AddedVolumeToTank= ((2.d0-MudSystem%BellNippleDensity)/(2.d0-MudSystem%ActiveTankDensity))*((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%BellNippleDensity .and. MudSystem%BellNippleDensity <= MudSystem%ActiveTankDensity) THEN + AddedVolumeToTank= ((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + ENDIF + endif + if (j3 == 1 .and. B78==1) then + MudSystem%BellNippleDumpVolume= MudSystem%BellNippleDumpVolume+ (MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline + !BellNippleDumpRate= MUD(3)%Q + endif + if (j3 == 2) then !78 is not allowded in this position + + MUD(3)%Q = min(MUD(3)%Q , MudSystem%PedalMeter) + + IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN + + MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%BellNippleDensity*(0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+((0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%BellNippleDensity*(0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+((0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline)) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ ((0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline) + + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity > MudSystem%ActiveTankDensity) THEN + + + AddedVolumeToTank= ((20.8d0-MudSystem%BellNippleDensity)/(20.8d0-MudSystem%ActiveTankDensity))*((0.5d0*MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((2.d0-MudSystem%BellNippleDensity)/(2.d0-MudSystem%ActiveTankDensity))*((0.5d0*MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%BellNippleDensity .and. MudSystem%BellNippleDensity <= MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + + ENDIF + + + endif + + endif !( BellNippleDensity > 1.0) then + + active_after= MudSystem%ActiveTankVolume + + active_increase = active_after - active_before + + total_active_increase= total_active_increase + active_increase + + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + total_active_increase= 0. + endif + + !write(*,*) 'total_active_increase=' , total_active_increase + + + + !write(*,*) 'ReturnFlowRate=MUD(3)%Q= after' , MUD(3)%Q + + MudSystem%ReturnFlowRate = MUD(3)%Q + + MudSystem%TripTankVolumeCalc = min(MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal + !if TripTankVolumeCalc>50 BBl, excess value(TripTankVolumeCalc-50) is dumped + + MudSystem%ActiveTankVolume = min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal - MudProperties%ActiveSettledContentsGal) + !if ActiveTankVolume is higher, excess amount is dumped + !write(*,*) 'BellNippleDensity=' , BellNippleDensity + + !MudWeightOut2 = BellNippleDensity !for drillwatch display + !write(*,*) 'MudWeightOut2=' , MudWeightOut2 + + !write(*,*) + + + endif + + if (j3 == 0) then + MUD(3)%Q=0.0 ! for normal circulation input + call Set_FlowRate(0d0) + endif + + + +!=========================================================================================================================== +!=========================================================================================================================== + + + + if (j11 > 0 .and. MudSystem%MudChecked== .true.) then !BellNippleToWell-NonFullWell ( FillingWell_By_BellNipple subroutine is called for this state ) + !write(*,*) 'j11 is open' + MudSystem%MudChecked= .false. !to be sure that well is not full after arranging muds + !WellToPitsOpen = .TRUE. + + !BellNipple flow rate= sum flow rate (well+ mudbucket+ triptank) + + !Well to BellNipple: BellNippleVolume + !MudBucket to BellNipple: BellNippleVolume + !TripTnak to BellNipple: BellNippleVolume + + MUD(8)%Q = (MudSystem%BellNippleVolume/MudSystem%DeltaT_Mudline)*60. + !write(*,*) 'MUD(8)%Q=' , MUD(8)%Q + + + MudSystem%BellNippleVolume= MudSystem%BellNippleVolume- ((MUD(8)%Q/60.)*MudSystem%DeltaT_Mudline) ! to be 0. + !write(*,*) 'BellNippleVolume-2nd Mode=' , BellNippleVolume + + !BellNippleDensity + ! + ! + !BellNippleDensity , MUD(8)%Q be code gel dade beshe + !shart: j11 > 0 , MUD(8)%Q > 0.0 + + + endif + + if (j11 == 0) then + MUD(8)%Q=0.0 ! for normal circulation input + !WellToPitsOpen= .false. + endif + + + +!=========================================================================================================================== +!=========================================================================================================================== + + + + !WRITE (*,*) 'choke condition', j4, ChokeLineNOTFull + if (j4 > 0 .and. MudSystem%ChokeLineNOTFull== .false.) then !WellToChokeManifold(Through 26) + !write(*,*) 'j4 is open' + !write(*,*) 'active by j4' + + + + !MUD(4)%Q= ( Ann_Saved_MudDischarged_Volume_Final+Ann_Kick_Saved_Volume_Final - ((Qlost/60.0d0)*DeltaT_Mudline) )*60.d0/DeltaT_Mudline + MUD(4)%Q= ( MudSystem%MudVolume_InjectedFromAnn + MudSystem%Ann_Kick_Saved_Volume )*60.d0/MudSystem%DeltaT_Mudline !Injected is referred only to Mud + + + !if ( WellisNOTFull== .true. ) MUD(4)%Q= 0.0 + + + if (j9 > 0) then + ChokeLine_FlowCoef= BopStackSpecification%ChokeLineId/(13.625+BopStackSpecification%ChokeLineId) ! 13.625= BellNipple ID (inch) + MUD(4)%Q= ChokeLine_FlowCoef * MUD(4)%Q + endif + + + !call Log_1('MUD(4)%Q=', MUD(4)%Q) + + MudSystem%ChokeOutletDensity= MudSystem%ChokeLine_Density%Last() ! <<< in CirculationCodeSelect Code + + + !MudWeightOut2= ChokeOutletDensity !for drillwatch display +! + !AnnulusFlowRateFinal: flow from string mud , DeltaVolumeOp: due to trip in + + + + + + RealJ4= real(j4) + + !C71: Active Tank C77: Trip Tank C78: ChokeManifoldDump + + if ( MudSystem%BellNippleDensity > 1.0) then + ! IN ALL CONDITIONS EFFECT OF 78 IS COMPUTED BY RealJ4 + if (C71==1 .and. C77==0) then !(volumes in galon) RealJ4: 1 OR 2(IF 78 IS OPEN) + + IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN + + MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%ChokeOutletDensity*((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline) + !write(*,*) 'active increase choke1=' , (((1./RealJ4)*MUD(4)%Q/60.)*DeltaT_Mudline) + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline) + + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity > MudSystem%ActiveTankDensity) THEN + + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((20.8d0-MudSystem%ChokeOutletDensity)/(20.8d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed cutting density = 20.8 ppg + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + !write(*,*) 'active increase choke2=' , ((20.8d0-ChokeOutletDensity)/(20.8d0-ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*DeltaT_Mudline) + + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity < 5.0) THEN + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((2.d0-MudSystem%ChokeOutletDensity)/(2.d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + !write(*,*) 'active increase choke3=' ,((2.d0-ChokeOutletDensity)/(2.d0-ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*DeltaT_Mudline) + + ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ChokeOutletDensity .and. MudSystem%ChokeOutletDensity <= MudSystem%ActiveTankDensity) THEN + !write(*,*) ' Auto true 3' + + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + + !write(*,*) 'active increase choke4=' , (((1.d0/RealJ4)*MUD(4)%Q/60.d0)*DeltaT_Mudline) + + ENDIF + + + + endif + + if (C77==1 .and. C71==0) then !RealJ4: 1 OR 2(IF 78 IS OPEN) + + IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ChokeOutletDensity*((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline) + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline) + + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity > MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((20.8d0-MudSystem%ChokeOutletDensity)/(20.8d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + + + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity < 5.0) THEN + + AddedVolumeToTank= ((2.d0-MudSystem%ChokeOutletDensity)/(2.d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + + ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ChokeOutletDensity .and. MudSystem%ChokeOutletDensity <= MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= (((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + + ENDIF + + + + endif + + if (C71==1 .and. C77==1) then !RealJ4: 2 OR 3(IF 78 IS OPEN) + + IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN + MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%ChokeOutletDensity*((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ChokeOutletDensity*((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline) + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline) + + ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity > MudSystem%ActiveTankDensity) THEN + + + AddedVolumeToTank= ((20.8d0-MudSystem%ChokeOutletDensity)/(20.8d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + + ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((2.d0-MudSystem%ChokeOutletDensity)/(2.d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + + ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ChokeOutletDensity .and. MudSystem%ChokeOutletDensity <= MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((1.d0/RealJ4)*MUD(4)%Q/60.d0) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) + + + ENDIF + + + endif + + + if (C71==0 .and. C77==0 .and. C78==1) then !RealJ4: 1 + ! autodensity niaz nadarad + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline) + + endif + + + + endif ! if ( BellNippleDensity > 1.0) then + + + MudSystem%TripTankVolumeCalc=min(MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal + !if TripTankVolumeCalc>50 BBl, excess value(TripTankVolumeCalc-50) is dumped + + MudSystem%ActiveTankVolume=min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal) + !if ActiveTankVolume is higher, excess amount is dumped + + endif + + + + + + if (j4 == 0 .or. MudSystem%ChokeLineNOTFull== .true.) then + !Pressure_BeforeChokes=0.0 ! for normal circulation input + MUD(4)%Q=0.0 ! for CirculationCodeSelect input. + endif + + + if (j4 > 0) then + MudSystem%WellToChokeManifoldOpen= .true. + else + MudSystem%WellToChokeManifoldOpen= .false. + endif + +!=========================================================================================================================== +!=========================================================================================================================== + + if (j18 > 0) then !StandPipeManifoldToChokeManifold-Through ChokeLine + !write(*,*) 'j18 is open' + !write(*,*) 'active by j18' + +! STEP 1: REDUCTION FROM PUMPS STEP 1: REDUCTION FROM PUMPS STEP 1: REDUCTION FROM PUMPS (SAME TO PumpsToString LINE) + ! (NOT NEEDED) + + + +! STEP 2: ADD TO TANKS STEP 2: ADD TO TANKS STEP 2: ADD TO TANKS STEP 2: ADD TO TANKS (SAME TO WellToChokeManifold LINE) + + !Pump1toCh: PumpsToChokeManifold Coefficient + !Jj2,Jj12,Jj13: TanksToMudPump Coefficient + !H: Pumps To Tank_Through65 or 67 Coefficient + + MUD(9)%Q= jj2*(1-H82)*(1-DumpPump1)*Pump1toCh*PUMP(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*Pump2toCh*PUMP(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*Pump3toCh*PUMP(3)%Flow_Rate + + + + Denominator_a= (jj2*(1.-H82)*(1.-DumpPump1)*Pump1toCh*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*Pump2toCh*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*Pump3toCh*PUMP(3)%Flow_Rate) + + if (Denominator_a /= 0.) then + MudSystem%Density_Ch= (jj2*(1.-H82)*(1.-DumpPump1)*Pump1toCh*MudSystem%Mp1Density*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*Pump2toCh*MudSystem%Mp2Density*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*Pump3toCh*MudSystem%Mp3Density*PUMP(3)%Flow_Rate)/ & + Denominator_a + !write(*,*) 'Density_Ch=' , Density_Ch + ! + ! else + !Density_Ch= 0.0 + endif + + + RealJ18= M71+M77+M78 + + !C71: Active Tank C77: Trip Tank C78: ChokeManifoldDump + + + ! IN ALL CONDITIONS EFFECT OF 78 IS COMPUTED BY RealJ18 + if (M71==1 .and. M77==0) then !(volumes in galon) RealJ18: 1 OR 2(IF 78 IS OPEN) + + ! autodensity niaz nadarad + MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%Density_Ch*((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline) + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline) + + endif + + if (M77==1 .and. M71==0) then !RealJ18: 1 OR 2(IF 78 IS OPEN) + + ! autodensity niaz nadarad + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%Density_Ch*((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline) + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline) + + endif + + if (M71==1 .and. M77==1) then !RealJ18: 2 OR 3(IF 78 IS OPEN) + + ! autodensity niaz nadarad + MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%Density_Ch*((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)) + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%Density_Ch*((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)) + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline) + + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline) + + endif + + + if (M71==0 .and. M77==0 .and. M78==1) then !RealJ18: 1 + ! autodensity niaz nadarad + MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline) + + endif + + + + + + + + + MudSystem%TripTankVolumeCalc=min(MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal + !if TripTankVolumeCalc>50 BBl, excess value(TripTankVolumeCalc-50) is dumped + + MudSystem%ActiveTankVolume=min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal) + !if ActiveTankVolume is higher, excess amount is dumped + + endif + + + if (j18 == 0) then + MUD(9)%Q=0.0 + endif + + +!=========================================================================================================================== +!=========================================================================================================================== + + if (j5 > 0 .and. (MudSystem%ActiveTankVolume/MudSystem%ActiveTankFloorArea) > (MudSystem%TripTankVolumeCalc/MudSystem%TripTankFloorArea)) then !ActiveTankToTripTank + ! second condition is for Utube flow + !write(*,*) 'j5 is open' + + ! ActiveTankVolume/ActiveTankFloorArea... means tank height + MUD(5)%Q= 300. ! constant flow rate(gpm) + + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume - ((MUD(5)%Q/60.)*MudSystem%DeltaT_Mudline) + MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc + ((MUD(5)%Q/60.)*MudSystem%DeltaT_Mudline) + + MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*(MUD(5)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+((MUD(5)%Q/60.)*MudSystem%DeltaT_Mudline)) + + + + MudSystem%TripTankVolumeCalc=min(MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal + !if TripTankVolumeCalc>50, excess value(TripTankVolumeCalc-50) is dumped + + endif + + if (j5 == 0) then + MUD(5)%Q=0.0 + endif + +!=========================================================================================================================== +!=========================================================================================================================== + + if (j16 > 0) then !PathsToGauge75 + + if (K79 == 1) then + + MudSystem%PressureGauge75= PressureGauges(1) !String to Gauge75 + + elseif (K82 == 1 .and. k83 == 0 .and. k84 == 0 .and. k78 == 0) then + MudSystem%PressureGauge75= PumpPressure1 + elseif (K82 == 0 .and. k83 == 1 .and. k84 == 0 .and. k78 == 0) then + MudSystem%PressureGauge75= PumpPressure2 + elseif (K82 == 0 .and. k83 == 0 .and. k84 == 1 .and. k78 == 0) then + MudSystem%PressureGauge75= PumpPressure3 + elseif (K82 == 0 .and. k83 == 0 .and. k84 == 0 .and. k78 == 1) then + MudSystem%PressureGauge75= 0. + endif + + !if (K82 == 1) PressureGauge75= PumpPressure1 !Pump1 to Gauge75' + !if (K83 == 1) PressureGauge75= PumpPressure2 !Pump2 to Gauge75 + !if (K84 == 1) PressureGauge75= PumpPressure3 !Pump3 to Gauge75 + !if (K78 == 1) PressureGauge75= 0. !Dump to Gauge75 + + endif + + + StandPipeManifold%StandPipeGauge1= (1 - MudSystem%StandPipeGauge1Malf) * MudSystem%PressureGauge75 ! for STManifold Display + !write(*,*) 'PressureGauge75=' , PressureGauge75 + !P1toSt= jj2*(1-H82)*(1-DumpPump1)*G82 + !P2toSt= jj12*(1-H83)*(1-DumpPump2)*G83 + !CptoSt= jj13*(1-H84)*(1-DumpCementPump)*G84 +!=========================================================================================================================== +!=========================================================================================================================== + + if (j17 > 0) then !PumpsToGauge76 + + if (L79 == 1) then + + MudSystem%PressureGauge76= PressureGauges(1) !String to Gauge76 + + elseif (L82 == 1 .and. L83 == 0 .and. L84 == 0 .and. L78 == 0) then + MudSystem%PressureGauge76= PumpPressure1 + elseif (L82 == 0 .and. L83 == 1 .and. L84 == 0 .and. L78 == 0) then + MudSystem%PressureGauge76= PumpPressure2 + elseif (L82 == 0 .and. L83 == 0 .and. L84 == 1 .and. L78 == 0) then + MudSystem%PressureGauge76= PumpPressure3 + elseif (L82 == 0 .and. L83 == 0 .and. L84 == 0 .and. L78 == 1) then + MudSystem%PressureGauge76= 0. + endif + + + !if (L79 == 1) PressureGauge76= PressureGauges(1) !String to Gauge76 + !if (L82 == 1) PressureGauge76= PumpPressure1 !Pump1 to Gauge76 + !if (L83 == 1) PressureGauge76= PumpPressure2 !Pump2 to Gauge76 + !if (L84 == 1) PressureGauge76= PumpPressure3 !Pump3 to Gauge76 + !if (L78 == 1) PressureGauge76= 0. !Dump to Gauge76 + + endif + StandPipeManifold%StandPipeGauge2= (1 - MudSystem%StandPipeGauge2Malf) * MudSystem%PressureGauge76 ! for STManifold Display +!=========================================================================================================================== +!=========================================================================================================================== + ! + !if (PressureGauge75 == PressureGauges(1)) then ! means: 75 goes to string + ! PumpPressureDW= PressureGauges(1) !for DrillWatch Display + ! CALL Set_StandPipePressure(real(PressureGauges(1) , 8)) !for Data Display Console + !endif + ! + ! + !if (PressureGauge76 == PressureGauges(1)) then ! means: 76 goes to string + ! PumpPressureDW= PressureGauges(1) !for DrillWatch Display + ! CALL Set_StandPipePressure(real(PressureGauges(1) , 8)) !for Data Display Console + !endif + ! + !if (PressureGauge75 /= PressureGauges(1) .and. PressureGauge76 /= PressureGauges(1)) then ! means: non of gauges go to string + ! PumpPressureDW= max(PressureGauge75,PressureGauge76) !for DrillWatch Display + ! !StandPipePressureGauge= max(PressureGauge75,PressureGauge76) !for Data Display Console + ! CALL Set_StandPipePressure(real(max(PressureGauge75,PressureGauge76) , 8)) !for Data Display Console + !endif + !write(*,*) 'TapSelector=' , TapSelector + + + if (StudentStation%TapSelector == .false.) then + + DrillingWatch%PumpPressure= MudSystem%PressureGauge75 !for DrillWatch Display + CALL Set_StandPipePressure(real((1-MudSystem%DrillPipePressureMalf)*MudSystem%PressureGauge75 , 8)) !for Data Display Console + else + DrillingWatch%PumpPressure= MudSystem%PressureGauge76 !for DrillWatch Display + CALL Set_StandPipePressure(real((1-MudSystem%DrillPipePressureMalf)*MudSystem%PressureGauge76 , 8)) !for Data Display Console + endif + +!=========================================================================================================================== +!=========================================================================================================================== + ! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem + + if (j2 > 0) then !TanksToMudPump1 + + + !Relief= 0: deactive 1: active PUMP(1)%Flow_Rate , PUMP(2)%Flow_Rate + + + RealJ2= real(j2) + + if (A71==1 .and. (MudSystem%ActiveTankVolume-(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then + A71= 0 + RealJ2= RealJ2-1 + write(*,*) 'ActiveTank Level Warning' + call Activate_ActiveTankUnderVolume() + endif + + if (A72==1 .and. (MudSystem%ReserveTankVolume-(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then + A72= 0 + RealJ2= RealJ2-1 + write(*,*) 'ReserveTank Level Warning' + endif + + if (A71==3 .and. (MudSystem%CementTankVolumeCalc-(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then + A73= 0 + RealJ2= RealJ2-1 + write(*,*) 'CementTank Level Warning' + endif + + + if(RealJ2> 0.0) then + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume- A71*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + MudSystem%ReserveTankVolume= MudSystem%ReserveTankVolume- A72*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + MudSystem%CementTankVolumeCalc= MudSystem%CementTankVolumeCalc- A73*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + !write(*,*) 'Active-decline=' , A71*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*DeltaT_Mudline) + total_decrease= total_decrease+ A71*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + total_decrease= 0. + endif + !write(*,*) 'total_decrease=' , total_decrease + + + MudSystem%Mp1Density= (A71*MudSystem%ActiveTankDensity+A72*MudSystem%ReserveTankDensity+A73*MudSystem%CementTankDensityCalc)/RealJ2 + else + write(*,*) 'stop' + endif + + + + endif + + +!=========================================================================================================================== +!=========================================================================================================================== + ! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem + + if (j12 > 0) then !TanksToMudPump2 + + + !Relief= 0: deactive 1: active PUMP(1)%Flow_Rate , PUMP(2)%Flow_Rate + + RealJ12= real(J12) + + if (E71==1 .and. (MudSystem%ActiveTankVolume-(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then + E71= 0 + RealJ12= RealJ12-1 + write(*,*) 'ActiveTank Level Warning' + endif + + if (E72==1 .and. (MudSystem%ReserveTankVolume-(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then + E72= 0 + RealJ12= RealJ12-1 + write(*,*) 'ReserveTank Level Warning' + endif + + if (E71==3 .and. (MudSystem%CementTankVolumeCalc-(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then + E73= 0 + RealJ12= RealJ12-1 + write(*,*) 'CementTank Level Warning' + endif + + + if(RealJ12> 0.0) then + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume- E71*(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + MudSystem%ReserveTankVolume= MudSystem%ReserveTankVolume- E72*(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + MudSystem%CementTankVolumeCalc= MudSystem%CementTankVolumeCalc- E73*(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + + + + MudSystem%Mp2Density= (E71*MudSystem%ActiveTankDensity+E72*MudSystem%ReserveTankDensity+E73*MudSystem%CementTankDensityCalc)/RealJ12 + else + write(*,*) 'stop' + endif + + + endif + + +!=========================================================================================================================== +!=========================================================================================================================== + ! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem + + if (j13 > 0) then !TanksToCementPump + + + !Relief= 0: deactive 1: active PUMP(1)%Flow_Rate , PUMP(2)%Flow_Rate + + + RealJ13= real(J13) + + if (F71==1 .and. (MudSystem%ActiveTankVolume-(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then + F71= 0 + RealJ13= RealJ13-1 + write(*,*) 'ActiveTank Level Warning' + endif + + if (F72==1 .and. (MudSystem%ReserveTankVolume-(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then + F72= 0 + RealJ13= RealJ13-1 + write(*,*) 'ReserveTank Level Warning' + endif + + if (F71==3 .and. (MudSystem%CementTankVolumeCalc-(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then + F73= 0 + RealJ13= RealJ13-1 + write(*,*) 'CementTank Level Warning' + endif + + + if(RealJ13> 0.0) then + + MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume- F71*(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + MudSystem%ReserveTankVolume= MudSystem%ReserveTankVolume- F72*(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + MudSystem%CementTankVolumeCalc= MudSystem%CementTankVolumeCalc- F73*(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline) + + + MudSystem%Mp3Density= (F71*MudSystem%ActiveTankDensity+F72*MudSystem%ReserveTankDensity+F73*MudSystem%CementTankDensityCalc)/RealJ13 + else + write(*,*) 'stop' + endif + + + endif + + + +!=========================================================================================================================== +!=========================================================================================================================== + ! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem + + if (j14 > 0) then !PumpsToString Suction_Density_MudSystem is used for Mud Circulation Code + !write(*,*) 'j14 is open' + !call Log_1('j14 is open') + + ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + + ! pump flow rate1 be sharti be samte string miravad ke masire j2 bar gharar bashad + ! pump flow rate2 be sharti be samte string miravad ke masire j12 bar gharar bashad + ! pump flow rate3 be sharti be samte string miravad ke masire j13 bar gharar bashad + + !G: PumpsToString Coefficient + !Jj2,Jj12,Jj13: TanksToMudPump Coefficient + !H: Pumps To Tank_Through65 or 67 Coefficient + ! + !write(*,*) 'jj2=' , jj2 + !write(*,*) 'jj12=' , jj12 + !write(*,*) 'jj13=' , jj13 + !write(*,*) 'H82=' , H82 + !write(*,*) 'H83=' , H83 + !write(*,*) 'H84=' , H84 + !write(*,*) 'DumpPump1=' , DumpPump1 + !write(*,*) 'DumpPump2=' , DumpPump2 + !write(*,*) 'DumpCementPump=' , DumpCementPump + !write(*,*) 'G82=' , G82 + !write(*,*) 'G83=' , G83 + !write(*,*) 'G84=' , G84 + !write(*,*) 'Mp1Density=' , Mp1Density + !write(*,*) 'Mp2Density=' , Mp2Density + !write(*,*) 'Mp3Density=' , Mp3Density + ! + ! + + + + !PumpsDumpVolume= PumpsDumpVolume+ jj2*(1-H82)*DumpPump1*PUMP(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*PUMP(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*PUMP(3)%Flow_Rate + + Denominator= (jj2*(1.-H82)*(1.-DumpPump1)*G82*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*G83*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*G84*PUMP(3)%Flow_Rate) + + if (Denominator /= 0.) then + MudSystem%Suction_Density_MudSystem= (jj2*(1.-H82)*(1.-DumpPump1)*G82*MudSystem%Mp1Density*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*G83*MudSystem%Mp2Density*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*G84*MudSystem%Mp3Density*PUMP(3)%Flow_Rate)/ & + Denominator + endif + + MudSystem%CompressedMudDensity= MudSystem%Suction_Density_MudSystem + + DrillingWatch%MudWeightIn= MudSystem%Suction_Density_MudSystem !for drillwatch display + + + MUD(2)%Q= jj2*(1-H82)*(1-DumpPump1)*G82*PUMP(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*G83*PUMP(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*G84*PUMP(3)%Flow_Rate + + !write(*,*) 'MUD(2)%Q=' , MUD(2)%Q + + + + !jj2*(1-H82)*(1-DumpPump1)*G82 :if ==1, Pump1 to String is open + !jj12*(1-H83)*(1-DumpPump2)*G83 :if ==1, Pump2 to String is open + !jj13*(1-H84)*(1-DumpCementPump)*G84 :if ==1, Cement to String is open + + + + endif + + if (j14 == 0) then ! for normal circulation input + MUD(2)%Q=0.0 + !PumpPressure1= 0.0 + !PumpPressure2= 0.0 + !PumpPressure3= 0.0 + endif + + + +!=========================================================================================================================== +!=========================================================================================================================== + + if (j19 > 0 .and. MudSystem%MudChecked== .true.) then !PumpsToWell_KillLine Suction_Density_PumpsToWell is used for Mud Circulation Code + !write(*,*) 'j19 is open' + MudSystem%MudChecked= .false. !to be sure that well is not full after arranging muds + + ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + + ! pump flow rate1 be sharti be samte well miravad ke masire j2 bar gharar bashad + ! pump flow rate2 be sharti be samte well miravad ke masire j12 bar gharar bashad + ! pump flow rate3 be sharti be samte well miravad ke masire j13 bar gharar bashad + + !G: PumpsToString Coefficient + !Jj2,Jj12,Jj13: TanksToMudPump Coefficient + !H: Pumps To Tank_Through65 or 67 Coefficient + ! + !write(*,*) 'jj2=' , jj2 + !write(*,*) 'jj12=' , jj12 + !write(*,*) 'jj13=' , jj13 + !write(*,*) 'H82=' , H82 + !write(*,*) 'H83=' , H83 + !write(*,*) 'H84=' , H84 + !write(*,*) 'DumpPump1=' , DumpPump1 + !write(*,*) 'DumpPump2=' , DumpPump2 + !write(*,*) 'DumpCementPump=' , DumpCementPump + !write(*,*) 'G82=' , G82 + !write(*,*) 'G83=' , G83 + !write(*,*) 'G84=' , G84 + !write(*,*) 'Mp1Density=' , Mp1Density + !write(*,*) 'Mp2Density=' , Mp2Density + !write(*,*) 'Mp3Density=' , Mp3Density + ! + ! + + + + !PumpsDumpVolume= PumpsDumpVolume+ jj2*(1-H82)*DumpPump1*PUMP(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*PUMP(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*PUMP(3)%Flow_Rate + + Denominator= (jj2*(1.-H82)*(1.-DumpPump1)*N82*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*N83*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*N84*PUMP(3)%Flow_Rate) + + if (Denominator /= 0.) then + MudSystem%Suction_Density_PumpsToWell= (jj2*(1.-H82)*(1.-DumpPump1)*N82*MudSystem%Mp1Density*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*N83*MudSystem%Mp2Density*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*N84*MudSystem%Mp3Density*PUMP(3)%Flow_Rate)/ & + Denominator + endif + + + + + + MUD(10)%Q= jj2*(1-H82)*(1-DumpPump1)*N82*PUMP(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*N83*PUMP(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*N84*PUMP(3)%Flow_Rate + + + + + + + endif + + if (j19 == 0) then ! for normal circulation input + MUD(10)%Q=0.0 + !PumpPressure1= 0.0 + !PumpPressure2= 0.0 + !PumpPressure3= 0.0 + endif +!=========================================================================================================================== +!=========================================================================================================================== + + + +!AnnulusFlowRateFinal = 0.d0 ! this is a reset for calculated flow rate in UTUBES,TRIPIN,TRIPOUT codes + + + + + + + + + + + + + +!!====================================================================== +!! Well Head Condition Determination +!!====================================================================== + + + if ( MudSystem%WellToChokeManifoldOpen .or. MudSystem%WellToPitsOpen) then + MudSystem%WellHeadIsOpen= .true. + else + MudSystem%WellHeadIsOpen= .false. + endif + + + + + + + +!!====================================================================== +!! WARNINGS +!!====================================================================== + + + IF (Manifold%Valve(65)%Status == .TRUE.) call Activate_Pump1PopOffValveBlown() !Pump1PopOffValveBlown= .TRUE. + IF (Manifold%Valve(66)%Status == .TRUE.) call Activate_Pump2PopOffValveBlown() ! Pump2PopOffValveBlown= .TRUE. + IF (Manifold%Valve(67)%Status == .TRUE.) call Activate_Pump3PopOffValveBlown() !Pump2PopOffValveBlown= .TRUE. + + + IF (MudSystem%ActiveTankVolume >= (MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal)) THEN + MudSystem%ActiveTankVolume = (MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal) + call Activate_ActiveTankOverflow() + ELSE + call Deactivate_ActiveTankOverflow() + ENDIF + + + +!!====================================================================== +!! UPDATING TANKS DENSITIES & Volumes FOR MUD CIRCULATION +!!====================================================================== + + !write(*,*) 'ReserveTankVolume=' , real(ReserveTankVolume) + + call Set_ActiveMudVolume_StudentStation(real(MudSystem%ActiveTankVolume/42.,8)) ! 42: gal to bbl + call Set_ActiveDensity_StudentStation(real(MudSystem%ActiveTankDensity,8)) + call Set_ReserveMudVolume_StudentStation(real(MudSystem%ReserveTankVolume/42.,8)) ! 42: gal to bbl + call Set_ReserveDensity_StudentStation(real(MudSystem%ReserveTankDensity,8)) + DrillingWatch%KillMudVolume= MudSystem%ReserveTankVolume/42. ! for DrillWatch + !PitGainLose= + + +!!====================================================================== +!! DRILLING DATA DISPLAY +!!====================================================================== + + + IF (DataDisplayConsole%TotalStrokeCounterResetSwitch == 1) then !for drilling data display + MudSystem%TotalStrokesPump1=0. + MudSystem%TotalStrokesPump2=0. + ENDIF + + MudSystem%TotalStrokesPump1=MudSystem%TotalStrokesPump1+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline !for drilling data display + MudSystem%TotalStrokesPump2=MudSystem%TotalStrokesPump2+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline !for drilling data display + MudSystem%GraphTotalStrokes=MudSystem%GraphTotalStrokes+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline + + + MPumps%Total_Stroke_Counter_For_Plot = MPumps%Total_Stroke_Counter_For_Plot + ((DataDisplayConsole%MP1SPMGauge + DataDisplayConsole%MP2SPMGauge) / 60.0) * MudSystem%DeltaT_Mudline + + ! CALL SetTotalStrokes(INT(MPumps%Total_Stroke_Counter_For_Plot)) + + DataDisplayConsole%TotalStrokeCounter= real(nint(MudSystem%TotalStrokesPump1+MudSystem%TotalStrokesPump2)) !for drilling data display + +!=========================================================================== +! MUD PUMP STROKES +! & TOTAL STROKE- CHOKE CONTROL PANEL +!=========================================================================== + !write(*,*) 'a)))' , ChokePanelStrokeResetSwitch + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + IF (ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN + !write(*,*) '1 reset' + Choke%TotalStrokes1 =0. + elseif (ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN + !write(*,*) '2 reset' + Choke%TotalStrokes2 =0. + else + !write(*,*) 'both reset' + + Choke%TotalStrokes1 =0. + Choke%TotalStrokes2 =0. + endif + endif + + !write(*,*) 'b)))' , ChokePanelStrokeResetSwitch + + + Choke%TotalStrokes1= Choke%TotalStrokes1+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline + Choke%TotalStrokes2= Choke%TotalStrokes2+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline + + + + IF (ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN + ChokeControlPanel%ChokePanelSPMCounter = real(nint(DataDisplayConsole%MP1SPMGauge)) + ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(Choke%TotalStrokes1)) + ELSEIF (ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN + ChokeControlPanel%ChokePanelSPMCounter = real(nint(DataDisplayConsole%MP2SPMGauge)) + ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(Choke%TotalStrokes2)) + ELSE + ChokeControlPanel%ChokePanelSPMCounter= real(nint(DataDisplayConsole%MP1SPMGauge+DataDisplayConsole%MP2SPMGauge)) + ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(Choke%TotalStrokes1+Choke%TotalStrokes2)) + ENDIF + + ! ChokePanelStrokeResetSwitch = 0 +!====================================================================== + +!!====================================================================== +!! MUD VOLUME TOTALIZER DISPLAY VALUES +!!====================================================================== + + + DrillingWatch%PitVolume= MudSystem%ActiveTankVolume/42.d0 !(bbl) For DrillWatch Display + + !write(*,*) 'PitVolume,ActiveTankVolume=' ,PitVolume,ActiveTankVolume + + + MudSystem%MudTank1_vol= MudSystem%ActiveTankVolume/3. ! (gal) + MudSystem%MudTank2_vol= MudSystem%ActiveTankVolume/3. ! (gal) + MudSystem%MudTank3_vol= MudSystem%ActiveTankVolume/3. ! (gal) + MudSystem%MudTank4_vol= MudSystem%TripTankVolumeCalc + + + + + + IF (DataDisplayConsole%MVTPowerSwitch==1) THEN + DataDisplayConsole%MudTanksVolumeGauge= (1 - MudSystem%MudTanksVolumeGaugeMalf) *((MudSystem%MudTank1_vol*DataDisplayConsole%MudTank1Switch)+(MudSystem%MudTank2_vol*DataDisplayConsole%MudTank2Switch)+ & + (MudSystem%MudTank3_vol*DataDisplayConsole%MudTank3Switch)+(MudSystem%MudTank4_vol*DataDisplayConsole%MudTank4Switch)+MudSystem%ActiveTankSettled) !(gal) + ELSEIF (DataDisplayConsole%MVTPowerSwitch==0) THEN + DataDisplayConsole%MudTanksVolumeGauge= (1 - MudSystem%MudTanksVolumeGaugeMalf) *0. + ENDIF + +!!====================================================================== +!! MUD VOLUME TOTALIZER +!!====================================================================== + + + + + ! IF (DataDisplayConsole%MVTPowerSwitch==1 .and. IsPortable==.false.) THEN + + + + ! IF (DataDisplayConsole%MVTSetAlarmSwitch==0) THEN + + ! DataDisplayConsole%PitGainLossGauge= ( ((ActiveTankVolume/42.) - RefrencePitVolume)) - PitGainLossGaugeMalf*(( ((ActiveTankVolume/42.) - RefrencePitVolume))+50) !(bbl) + + ! ELSEIF (DataDisplayConsole%MVTSetAlarmSwitch==-1) THEN + + + ! MVT_MinVol_Allowded= PitGainLossZero+ MIN(0.,(DataDisplayConsole%MVTSetAlarmLowKnob-50))-0.1 + ! DataDisplayConsole%PitGainLossGauge= MVT_MinVol_Allowded - PitGainLossGaugeMalf*(MVT_MinVol_Allowded+50) + ! ! - PitGainLossGaugeMalf*(MVT_MinVol_Allowded+50) : Malf effect + ! !PitGainLose=(MVT_MinVol_Allowded) ! DrillWatch (incorrect) + ! !RefrencePitVolume= ActiveTankVolume/42. !(bbl) + + ! ELSE !(MVTSetAlarmSwitch==1) + + ! MVT_MaxVol_Allowded= PitGainLossZero+ MAX(0., (DataDisplayConsole%MVTSetAlarmHighKnob-50.))+0.1 + ! DataDisplayConsole%PitGainLossGauge= MVT_MaxVol_Allowded - PitGainLossGaugeMalf*(MVT_MaxVol_Allowded+50) + ! ! - PitGainLossGaugeMalf*(MVT_MaxVol_Allowded+50) : Malf effect + ! !PitGainLose=(MVT_MaxVol_Allowded) ! DrillWatch (incorrect) + ! !RefrencePitVolume= ActiveTankVolume/42. !(bbl) + ! ENDIF + + ! !PitGainLossZero_Old= PitGainLossZero + ! !MVTCoarseKnob_Old= MVTCoarseKnob + ! !MVTFineKnob_Old= MVTFineKnob + ! !FirstSet_Time= .false. + + + + ! IF ( ActiveTankVolume/42. < (RefrencePitVolume-ABS(MVT_MinVol_Allowded)) .OR. ActiveTankVolume/42. > (RefrencePitVolume+ABS(MVT_MaxVol_Allowded)) ) THEN + + ! DataDisplayConsole%MVTAlarmLED = 1 !(blinking) + ! IF (DataDisplayConsole%MVTHornSwitch) THEN + ! DataDisplayConsole%Buzzer2= .TRUE. + ! ELSE + ! DataDisplayConsole%Buzzer2= .FALSE. + ! ENDIF + + ! ELSE + ! DataDisplayConsole%MVTAlarmLED = 0 !(OFF) + ! DataDisplayConsole%Buzzer2= .false. + ! ENDIF + + + + ! ELSEIF (DataDisplayConsole%MVTPowerSwitch==0) THEN + ! !MudTanksVolumeGauge= 0. + ! DataDisplayConsole%PitGainLossGauge= -50 + ! DataDisplayConsole%MVTAlarmLED= 0 + ! DataDisplayConsole%Buzzer2= .false. + + + ! ENDIF + +!!====================================================================== +!! RETURN CALCULATIONS +!!====================================================================== + + + + + DrillingWatch%PercentFlow= (MudSystem%ReturnFlowRate/MudSystem%PedalMeter) *100. !(percent) ! for DrillWatch display + if (abs(DrillingWatch%PercentFlow - unityreturn) > 1.0) then + + write(*,*) 'PercentFlow,ReturnFlowRate,PedalMeter=' , DrillingWatch%PercentFlow,MudSystem%ReturnFlowRate,MudSystem%PedalMeter + write(*,*) 'unityreturn=' , unityreturn + endif + + + ! ReturnFlowRate=800. set in startup as initial value + MudSystem%ReturnFlowPercent= (MudSystem%ReturnFlowRate/MudSystem%PedalMeter) *100. !(percent) + !write(*,*) 'ReturnFlowPercent,ReturnFlowRate=' , ReturnFlowPercent,ReturnFlowRate + ! if ReturnFlowRate>PedalMeter, excess value(ReturnFlowRate-PedalMeter) is dumped in the code before + + +!!====================================================================== +!! DRILL WATCH +!!====================================================================== + + DrillingWatch%PitGainLose= ((MudSystem%ActiveTankVolume/42.) - MudSystem%RefrencePitVolume_DrillWatch) ! DrillWatch + !write(*,*) 'PitGainLose galon' , PitGainLose*42. + + + ! if (IsPortable) then + + ! MVT_MinVol_Allowded= DataDisplayConsole%PitAlarmLow + ! MVT_MaxVol_Allowded= DataDisplayConsole%PitAlarmHigh + + ! IF ( ActiveTankVolume/42. < (RefrencePitVolume-ABS(MVT_MinVol_Allowded)) .OR. ActiveTankVolume/42. > (RefrencePitVolume+ABS(MVT_MaxVol_Allowded)) ) THEN + + ! DataDisplayConsole%MVTAlarmLED = 1 !(blinking) + ! IF (DataDisplayConsole%MVTHornSwitch) THEN + ! DataDisplayConsole%Buzzer2= .TRUE. + ! ELSE + ! DataDisplayConsole%Buzzer2= .FALSE. + ! ENDIF + + ! ELSE + ! DataDisplayConsole%MVTAlarmLED = 0 !(OFF) + ! DataDisplayConsole%Buzzer2= .false. + ! ENDIF + + ! endif + + + if (StudentStation%PitGainLossZero) then + DrillingWatch%PitGainLose= 0.d0 !DrillWatch + MudSystem%RefrencePitVolume_DrillWatch= MudSystem%ActiveTankVolume/42. !(bbl) !DrillWatch + !********************************************* + DataDisplayConsole%PitGainLossGauge= 0. !MFF Indicator + MudSystem%RefrencePitVolume= MudSystem%ActiveTankVolume/42. !(bbl) !MFF Indicator + endif +!!====================================================================== +!! MUD FLOW-FILL INDICATOR +!!====================================================================== + IF (DataDisplayConsole%MFFIPowerSwitch==1 ) THEN !.and. IsPortable==.false. +!====================TotalStrokes Reset and Calculate====================== + if (DataDisplayConsole%MFFIResetTotalStrokes == 1) then + IF (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN + MudSystem%TotalStrokes1MFFI =0. + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN + MudSystem%TotalStrokes2MFFI =0. + else + MudSystem%TotalStrokes1MFFI =0. + MudSystem%TotalStrokes2MFFI =0. + endif + endif + MudSystem%TotalStrokes1MFFI= MudSystem%TotalStrokes1MFFI+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline + MudSystem%TotalStrokes2MFFI= MudSystem%TotalStrokes2MFFI+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline + +!==================FillStrokes Reset and Calculate========================= + if (DataDisplayConsole%MFFIResetFillCounter == 1) then + IF (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN + MudSystem%TotalFillStrokes1MFFI =0. + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN + MudSystem%TotalFillStrokes2MFFI =0. + else + MudSystem%TotalFillStrokes1MFFI =0. + MudSystem%TotalFillStrokes2MFFI =0. + endif + endif + + + MudSystem%TotalFillStrokes1MFFI= MudSystem%TotalFillStrokes1MFFI+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline + MudSystem%TotalFillStrokes2MFFI= MudSystem%TotalFillStrokes2MFFI+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline +!=================================================================== + + + if (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + DataDisplayConsole%MFFITotalStrokeCounter = real(nint(MudSystem%TotalStrokes1MFFI)) !TotalStroke LED + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + DataDisplayConsole%MFFITotalStrokeCounter = real(nint(MudSystem%TotalStrokes2MFFI)) !TotalStroke LED + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + DataDisplayConsole%MFFITotalStrokeCounter = real(nint(MudSystem%TotalStrokes1MFFI+MudSystem%TotalStrokes2MFFI)) !TotalStroke LED + endif + + + IF (DataDisplayConsole%MFFIFillSPMSelectorSwitch== .false.) THEN !(spm mode) + if (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + DataDisplayConsole%FillStrokeCounter = real(nint(DataDisplayConsole%MP1SPMGauge)) !Fill or SPM LED + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + DataDisplayConsole%FillStrokeCounter = real(nint(DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + DataDisplayConsole%FillStrokeCounter= real(nint(DataDisplayConsole%MP1SPMGauge+DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED + endif + + ELSE ! (MFFIFillSPMSelectorSwitch== .true.) then !(fill mode) + if (MudSystem%ReturnFlowRate== 0) then + if (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + DataDisplayConsole%FillStrokeCounter = real(nint(MudSystem%TotalFillStrokes1MFFI)) !Fill or SPM LED + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + DataDisplayConsole%FillStrokeCounter = real(nint(MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + DataDisplayConsole%FillStrokeCounter= real(nint(MudSystem%TotalFillStrokes1MFFI+MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED + endif + + + MudSystem%TotalFilledStrokesBy1MFFI = real(nint(MudSystem%TotalFillStrokes1MFFI))! for values=fix on LED after the well filled + MudSystem%TotalFilledStrokesBy2MFFI = real(nint(MudSystem%TotalFillStrokes2MFFI))! for values=fix on LED after the well filled + MudSystem%TotalFilledStrokesBy1and2MFFI= real(nint(MudSystem%TotalFillStrokes1MFFI+MudSystem%TotalFillStrokes2MFFI))! for values=fix on LED after the well filled + + + + else !(ReturnFlowRate>0) + + ! these values=fix on LED after the well filled + if (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + DataDisplayConsole%FillStrokeCounter = MudSystem%TotalFilledStrokesBy1MFFI !Fill or SPM LED + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + DataDisplayConsole%FillStrokeCounter = MudSystem%TotalFilledStrokesBy2MFFI !Fill or SPM LED + elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + DataDisplayConsole%FillStrokeCounter= MudSystem%TotalFilledStrokesBy1and2MFFI !Fill or SPM LED + endif + endif + + + ENDIF + + + + !=================================================================================== + + + + + if (MudSystem%ReturnFlowRate>0) then + DataDisplayConsole%MFFIPumpLED=1 !(Returns Lamp) + else + DataDisplayConsole%MFFIPumpLED=0 !(Returns Lamp) + endif + + + + IF (DataDisplayConsole%MFFISetAlarmSwitch==0) THEN + + DataDisplayConsole%ReturnMudFlowGauge= (1 - MudSystem%ReturnMudFlowGaugeMalf)*MudSystem%ReturnFlowPercent !(percent) + + ELSEIF (DataDisplayConsole%MFFISetAlarmSwitch==-1) THEN + MudSystem%MFFI_MinPercent_Allowded=DataDisplayConsole%MFFISetAlarmLowKnob + DataDisplayConsole%ReturnMudFlowGauge= (1 - MudSystem%ReturnMudFlowGaugeMalf)*MudSystem%MFFI_MinPercent_Allowded + + ELSE !(MFFISetAlarmSwitch==1) + + MudSystem%MFFI_MaxPercent_Allowded=DataDisplayConsole%MFFISetAlarmHighKnob + DataDisplayConsole%ReturnMudFlowGauge= (1 - MudSystem%ReturnMudFlowGaugeMalf)*MudSystem%MFFI_MaxPercent_Allowded + ENDIF + + + IF (MudSystem%ReturnFlowPercentMudSystem%MFFI_MaxPercent_Allowded) THEN + !write(*,*) 'alarm return:' , ReturnFlowRate + DataDisplayConsole%MFFIAlarmLED = 2 !(blinking) + IF (DataDisplayConsole%MFFIHornSwitch) THEN + DataDisplayConsole%Buzzer3= .true. + ELSE + DataDisplayConsole%Buzzer3= .FALSE. + ENDIF + ELSE + DataDisplayConsole%MFFIAlarmLED = 0 !(OFF) + DataDisplayConsole%Buzzer3= .false. + ENDIF + !=================================================================================== + + + ELSEIF (DataDisplayConsole%MFFIPowerSwitch==0) THEN + DataDisplayConsole%ReturnMudFlowGauge= 0. + DataDisplayConsole%FillStrokeCounter= 0 + DataDisplayConsole%MFFITotalStrokeCounter= 0 + DataDisplayConsole%MFFIAlarmLED= 0 + DataDisplayConsole%Buzzer3= .false. + ENDIF + + + ! if ( IsPortable ) then + + ! MFFI_MinPercent_Allowded=DataDisplayConsole%RetFlowAlarmLow + ! MFFI_MaxPercent_Allowded=DataDisplayConsole%RetFlowAlarmHigh + + + ! IF (ReturnFlowPercentMFFI_MaxPercent_Allowded) THEN + + ! DataDisplayConsole%MFFIAlarmLED = 1 !(blinking) + ! IF (DataDisplayConsole%MFFIHornSwitch) THEN + ! DataDisplayConsole%Buzzer3= .true. + ! ELSE + ! DataDisplayConsole%Buzzer3= .FALSE. + ! ENDIF + ! ELSE + ! DataDisplayConsole%MFFIAlarmLED = 0 !(OFF) + ! DataDisplayConsole%Buzzer3= .false. + ! ENDIF + + ! endif + + +!!====================================================================== +!! TRIP TANK PANEL DISPLAY VALUES +!!====================================================================== + + Tank%TripTankVolume = MudSystem%TripTankVolumeCalc/42. !(Drill Watch display) + Tank%TripTankDensity= MudSystem%TripTankDensityCalc !(display) + + + IF (DataDisplayConsole%TripTankPowerSwitch==1 ) THEN !.and. IsPortable==.false. + + IF (DataDisplayConsole%TripTankSetAlarmSwitch==0) THEN + + DataDisplayConsole%TripTankGauge= (1 - MudSystem%TripTankPressure_DataDisplayMalf) * MudSystem%TripTankVolumeCalc ! (gal) + ELSEIF (DataDisplayConsole%TripTankSetAlarmSwitch==-1) THEN + + MudSystem%TripTank_MinVol_Allowded= DataDisplayConsole%TripTankSetAlarmLow/2. ! 2: because knob input is 0-100 but gauge is 0-50 + DataDisplayConsole%TripTankGauge= (1 - MudSystem%TripTankPressure_DataDisplayMalf) * MudSystem%TripTank_MinVol_Allowded + + ELSE !(TripTankSetAlarmSwitch==1) + MudSystem%TripTank_MaxVol_Allowded= DataDisplayConsole%TripTankSetAlarmHigh/2. ! 2: because knob input is 0-100 but gauge is 0-50 + DataDisplayConsole%TripTankGauge= (1 - MudSystem%TripTankPressure_DataDisplayMalf) * MudSystem%TripTank_MaxVol_Allowded + ENDIF + + + + IF ((MudSystem%TripTankVolumeCalc < MudSystem%TripTank_MinVol_Allowded) .OR. (MudSystem%TripTankVolumeCalc > MudSystem%TripTank_MaxVol_Allowded)) THEN + DataDisplayConsole%TripTankAlarmLED = 2 !(blinking) + IF (DataDisplayConsole%TripTankHornSwitch) THEN + DataDisplayConsole%Buzzer1= .true. + ELSE + DataDisplayConsole%Buzzer1= .false. + ENDIF + ELSE + DataDisplayConsole%TripTankAlarmLED = 0 !(OFF) + DataDisplayConsole%Buzzer1= .false. + ENDIF + + DataDisplayConsole%TripTankPumpLED= DataDisplayConsole%TripTankPumpSwitch + + + ELSEIF (DataDisplayConsole%TripTankPowerSwitch==0) THEN + DataDisplayConsole%TripTankGauge= 0. !(gal) + DataDisplayConsole%TripTankAlarmLED= 0 + DataDisplayConsole%TripTankPumpLED= 0 + DataDisplayConsole%Buzzer1= .false. + ENDIF + + + ! if ( IsPortable ) then + + ! TripTank_MinVol_Allowded= DataDisplayConsole%TripAlarmLow + ! TripTank_MaxVol_Allowded= DataDisplayConsole%TripAlarmHigh + + + ! IF ((TripTankVolumeCalc < TripTank_MinVol_Allowded) .OR. (TripTankVolumeCalc > TripTank_MaxVol_Allowded)) THEN + ! DataDisplayConsole%TripTankAlarmLED = 1 !(blinking) + ! IF (DataDisplayConsole%TripTankHornSwitch) THEN + ! DataDisplayConsole%Buzzer1= .true. + ! ELSE + ! DataDisplayConsole%Buzzer1= .false. + ! ENDIF + ! ELSE + ! DataDisplayConsole%TripTankAlarmLED = 0 !(OFF) + ! DataDisplayConsole%Buzzer1= .false. + ! ENDIF + + ! endif + + + + + !write(*,*) '=====================================================================' + + + + ! if (IsStopped) return + + end subroutine main + + + + + !=================================================================================================================== + !=================================================================================================================== + !=================================================================================================================== + + subroutine ActiveMudVolumeChanged(v) + !use CLog4 + implicit none + real(8), intent (in) :: v + !call Log_4('ActiveMudVolumeChanged=', v) + MudSystem%ActiveTankVolume= MudProperties%ActiveMudVolumeGal ! update from student input + end subroutine + + subroutine ActiveDensityChanged(v) + !use CLog4 + implicit none + real(8), intent (in) :: v + !call Log_4('ActiveDensityChanged=', v) + MudSystem%ActiveTankDensity= MudProperties%ActiveDensity ! update from student input + end subroutine + + subroutine ReserveMudVolumeChanged(v) + !use CLog4 + implicit none + real(8), intent (in) :: v + !call Log_4('ReserveMudVolumeChanged=', v) + MudSystem%ReserveTankVolume= MudProperties%ReserveMudVolumeGal ! update from student input + end subroutine + + subroutine ReserveDensityChanged(v) + !use CLog4 + implicit none + real(8), intent (in) :: v + !call Log_4('ReserveDensityChanged=', v) + MudSystem%ReserveTankDensity= MudProperties%ReserveDensity ! update from student input + end subroutine + + ! subroutine SetupMudSystem() + ! ! use CPathChangeEvents + ! use CMudPropertiesVariables + ! implicit none + + ! call BeforeTraverse%Add(InitialVarsBeforePathsChanges) + ! call AfterTraverse%Add(AfterPathsChanges) + ! call OnPathOpen%Add(WhenPathOpen) + + + ! call OnActiveMudVolumeChange%Add(ActiveMudVolumeChanged) + ! call OnActiveDensityChange%Add(ActiveDensityChanged) + ! call OnReserveMudVolumeChange%Add(ReserveMudVolumeChanged) + ! call OnReserveDensityChange%Add(ReserveDensityChanged) + + ! end subroutine + + subroutine AfterPathsChanges() + implicit none + integer i + + if(Pump1_Lasts%Length() <= 0) return + do i = 1, Pump1_Lasts%Length() + if(Pump2_Lasts%Length() <= 0) cycle + if(any(Pump2_Lasts%Array == Pump1_Lasts%Array(i))) then + State2 = .true. ! Pumps 1 & 2 have same destination + !print*, 'State2 = .true.' + endif + if(Pump3_Lasts%Length() <= 0) cycle + if(any(Pump3_Lasts%Array == Pump1_Lasts%Array(i))) then + State3 = .true. ! Pumps 1 & 3 have same destination + !print*, 'State3 = .true.' + endif + enddo + + if(Pump2_Lasts%Length() <= 0) return + do i = 1, Pump2_Lasts%Length() + if(Pump3_Lasts%Length() <= 0) cycle + if(any(Pump3_Lasts%Array == Pump2_Lasts%Array(i))) then + State4 = .true. ! Pumps 2 & 3 have same destination + !print*, 'State4 = .true.' + endif + enddo + + State1 = State2 .and. State3 ! Pumps 1 & 2 & 3 have same destination + !if(State1) print*, 'State1 = .true.' + + end subroutine + + subroutine InitialVarsBeforePathsChanges() + implicit none + + condition1 = .false. + condition2 = .false. + condition3 = .false. + condition4 = .false. + condition5 = .false. + condition6 = .false. + condition7 = .false. + condition8 = .false. + condition9 = .false. + condition10 = .false. + condition11 = .false. + condition12 = .false. + condition13 = .false. + condition14 = .false. + condition15 = .false. + condition16 = .false. + condition17 = .false. + condition18 = .false. + condition19 = .false. + condition20 = .false. + condition21 = .false. + condition22 = .false. + condition23 = .false. + condition24 = .false. + condition25 = .false. + condition26 = .false. + condition27 = .false. + condition28 = .false. + condition29 = .false. + condition30 = .false. + condition31 = .false. + condition32 = .true. + condition33 = .true. + condition34 = .true. + condition35 = .false. + condition36 = .false. + condition37 = .false. + condition38 = .false. + condition39 = .false. + condition40 = .false. + condition41 = .false. + condition42 = .false. + condition43 = .false. + condition44 = .false. + condition45 = .false. + condition46 = .false. + condition47 = .false. + condition48 = .false. + condition49 = .false. + condition50 = .false. + condition51 = .false. + condition52 = .false. + condition53 = .false. + condition54 = .false. + condition55 = .false. + condition56 = .false. + condition57 = .false. + condition58 = .false. + condition59= .false. + condition60= .false. + condition61= .false. + + + + + + + + !ThereIsPathFrom82 = .false. + !!print*, "ThereIsPathFrom82=",ThereIsPathFrom82 + !ThereIsPathFrom83 = .false. + !!print*, "ThereIsPathFrom82=",ThereIsPathFrom82 + !ThereIsPathFrom84 = .false. + !!print*, "ThereIsPathFrom82=",ThereIsPathFrom82 + + ThereIsPathFrom_71_72_73_To_82 = .false. + !print*, "ThereIsPathFrom_71_72_73_To_82=",ThereIsPathFrom_71_72_73_To_82 + ThereIsPathFrom_71_72_73_To_83 = .false. + !print*, "ThereIsPathFrom_71_72_73_To_83=",ThereIsPathFrom_71_72_73_To_83 + ThereIsPathFrom_71_72_73_To_84 = .false. + !print*, "ThereIsPathFrom_71_72_73_To_84=",ThereIsPathFrom_71_72_73_To_84 + + DumpFromKelly_Pump1 = .false. + DumpFromFillupHead_Pump1 = .false. + DumpFromTopDrive_Pump1 = .false. + + + DumpFromKelly_Pump2 = .false. + DumpFromFillupHead_Pump2 = .false. + DumpFromTopDrive_Pump2 = .false. + + + DumpFromKelly_Pump3 = .false. + DumpFromFillupHead_Pump3 = .false. + DumpFromTopDrive_Pump3 = .false. + + + + State1 = .false. + State2 = .false. + State3 = .false. + State4 = .false. + + call Pump1_Lasts%Empty() + call Pump2_Lasts%Empty() + call Pump3_Lasts%Empty() + + + + + + ac32 = .false. + ac33 = .false. + ac34 = .false. + ac35 = .false. + ac29 = .false. + + end subroutine + + subroutine WhenPathOpen(valves) + use Pumps_VARIABLES + implicit none + integer, allocatable, intent (in) :: valves(:) + integer :: first, last + if (.not.allocated(valves)) return + if(size(valves) <= 0) return + + if ( any(valves == 32)) ac32 = .true. + if ( any(valves == 33)) ac33 = .true. + if ( any(valves == 34)) ac34 = .true. + if ( any(valves == 35)) ac35 = .true. + if ( any(valves == 29)) ac29 = .true. + + + first = 1 + last = size(valves) + + MP1_Q = PUMP(1)%Flow_Rate + MP2_Q = PUMP(2)%Flow_Rate + MP3_Q = PUMP(3)%Flow_Rate + + + + if(valves(first) == 82) call Pump1_Lasts%Add(valves(last)) + if(valves(first) == 83) call Pump2_Lasts%Add(valves(last)) + if(valves(first) == 84) call Pump3_Lasts%Add(valves(last)) + + !print*, '==============================================' + !do i = 1, Pump1_Lasts%Length() + ! print*, 'mp1=', Pump1_Lasts%Array(i) + !enddo + ! + !print*, '-------------------------------' + ! + !do i = 1, Pump2_Lasts%Length() + ! print*, 'mp2=', Pump2_Lasts%Array(i) + !enddo + ! + !print*, '-------------------------------' + ! + ! + !do i = 1, Pump3_Lasts%Length() + ! print*, 'mp3=', Pump3_Lasts%Array(i) + !enddo + ! + !print*, '==============================================' + + + !if(valves(first)==82 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71)) then + ! ThereIsPathFrom82 = .true. + ! !print*, "ThereIsPathFrom82=",ThereIsPathFrom82 + !endif + ! + !if(valves(first)==83 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71)) then + ! ThereIsPathFrom83 = .true. + ! !print*, "ThereIsPathFrom83=",ThereIsPathFrom83 + !endif + ! + !if(valves(first)==84 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71)) then + ! ThereIsPathFrom84 = .true. + ! !print*, "ThereIsPathFrom84=",ThereIsPathFrom84 + !endif + + if(valves(last)==82 .and. (valves(first)==71 .or. valves(first)==72 .or. valves(first)==73)) then + ThereIsPathFrom_71_72_73_To_82 = .true. + !print*, "ThereIsPathFrom_71_72_73_To_82=",ThereIsPathFrom_71_72_73_To_82 + endif + + if(valves(last)==83 .and. (valves(first)==71 .or. valves(first)==72 .or. valves(first)==73)) then + ThereIsPathFrom_71_72_73_To_83 = .true. + !print*, "ThereIsPathFrom_71_72_73_To_83=",ThereIsPathFrom_71_72_73_To_83 + endif + + if(valves(last)==84 .and. (valves(first)==71 .or. valves(first)==72 .or. valves(first)==73)) then + ThereIsPathFrom_71_72_73_To_84 = .true. + !print*, "ThereIsPathFrom_71_72_73_To_84=",ThereIsPathFrom_71_72_73_To_84 + endif + + !if (.not.allocated(OpenPaths)) exit + !===============TanksToMudPump1=================== + if(valves(last)==82) then + if(valves(first)==71) then + !j2=j2+1 + !A71=1 + condition1 = .true. + endif + + if(valves(first)==72) then + !j2=j2+1 + !A72=1 + condition2 = .true. + endif + + if(valves(first)==73) then + !j2=j2+1 + !A73=1 + condition3 = .true. + endif + + endif + !================================================ + + + !============BellNippleToPits-FullWell(MLnumber=3)============== + + if ( Manifold%Valve(41)%Status == .false. .and. Manifold%Valve(42)%Status == .false. ) then + call ChangeValve(60, .TRUE.) + else + call ChangeValve(60, .FALSE.) + endif + + if(valves(first)==80 .and. valves(last)==71 .and. any(valves == 42)) condition4 = .true. + if(valves(first)==80 .and. valves(last)==77 .and. any(valves == 41)) condition5 = .true. + if(valves(first)==80 .and. valves(last)==78) condition6 = .true. + + !================================================ + + + !============WellToChokeManifold(Through 26)============== + if(valves(first)==79 .and. any(valves == 26)) then + if(valves(last)==71) then + !j4=j4+1 + !C71=1. + condition7 = .true. + endif + + if(valves(last)==77) then + !j4=j4+1 + !C77=1. + condition8 = .true. + endif + + if(valves(last)==78) then + !j4=j4+1 + !C78=1. + condition45 = .true. + endif + + endif + + !================================================ + + + !============ActiveTankToTripTank============== + if(valves(first)==71 .and. valves(last)==77) then + !j5=j5+1 + condition9 = .true. + endif + !================================================ + + + + !============TripTankToActiveTank And BellNipple============== + if(valves(first)==77) then + if(valves(last)==71) then + !j6=j6+1 + !D71=1 + condition10 = .true. + endif + + if(valves(last)==80) then + !j6=j6+1 + !D80=1 + condition11 = .true. + endif + + endif + !================================================ + + + !============ActiveTankToDump============== + if(valves(first)==71 .and. valves(last)==78) then + !j7=j7+1 + condition12 = .true. + endif + !================================================ + + + !============TripTankToDump============== + if(valves(first)==77 .and. valves(last)==78) then + !j8=j8+1 + condition13 = .true. + endif + !================================================ + + + !============WellToBellNipple============== + if(valves(first)==79 .and. valves(last)==80) then + !j9=j9+1 + condition14 = .true. + endif + !================================================ + + !============MudBucketToBellNipple============== + if(valves(first)==81 .and. valves(last)==80) then + !j10=j10+1 + condition15 = .true. + endif + !================================================ + + + !============BellNippleToWell-NonFullWell============== + if(valves(first)==80 .and. valves(last)==79) then ! Well is NOT Full + !j11=j11+1 + condition16 = .true. + endif + !================================================ + + !===============TanksToMudPump2=================== + if(valves(last)==83) then + if(valves(first)==71) then + !j12=j12+1 + !E71=1 + condition17 = .true. + endif + + if(valves(first)==72) then + !j12=j12+1 + !E72=1 + condition18 = .true. + endif + + if(valves(first)==73) then + !j12=j12+1 + !E73=1 + condition19 = .true. + endif + + endif + !================================================ + + + !===============TanksToCementPump=================== + if(valves(last)==84) then + if(valves(first)==71) then + !j13=j13+1 + !F71=1 + condition20 = .true. + endif + + if(valves(first)==72) then + !j13=j13+1 + !F72=1 + condition21 = .true. + endif + + if(valves(first)==73) then + !j13=j13+1 + !F73=1 + condition22 = .true. + endif + + endif + !================================================ + + !===============PumpsToString=================== + if(valves(last)==79) then + if(valves(first)==82) then + !j14=j14+1 + !G82=1 + condition23 = .true. + endif + + if(valves(first)==83) then + !j14=j14+1 + !G83=1 + condition24 = .true. + endif + + if(valves(first)==84) then + !j14=j14+1 + !G84=1 + condition25 = .true. + endif + + endif + !================================================ + + + + + + !============MudPump1HasPath=================== + if(ThereIsPathFrom_71_72_73_To_82 .and. (valves(first)==82 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71))) then + !Mp1_NoPath= 0 + condition32 = .false. + endif + MudSystem%condition32Final = condition32 + !================================================ + + + !============MudPump2HasPath=================== + if(ThereIsPathFrom_71_72_73_To_83 .and. (valves(first)==83 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71))) then + !write(*,*) 'condition33 ******' + !Mp2_NoPath= 0 + condition33 = .false. + endif + MudSystem%condition33Final= condition33 + !================================================ + + + !============CementPumpHasNoPath=================== + if(ThereIsPathFrom_71_72_73_To_84 .and. (valves(first)==84 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71))) then + !Cp_NoPath= 1 + condition34 = .false. + endif + MudSystem%condition34Final = condition34 + !================================================ + + + + + !===============PumpsToDump=================== + !DumpFromKelly = 0.0 + !DumpFromFillupHead= 0.0 + + if(valves(last)==78) then + if(valves(first)==82) then + !DumpPump1=1 + condition26 = .true. + IF(any(valves == 56)) DumpFromKelly_Pump1 = .true. + IF(any(valves == 14)) DumpFromFillupHead_Pump1 = .true. + IF(any(valves == 70)) DumpFromTopDrive_Pump1 = .true. + + + endif + + + if(valves(first)==83) then + !DumpPump2=1 + print*, "THERE IS DUMP" + condition27 = .true. + IF(any(valves == 56)) DumpFromKelly_Pump2 = .true. + IF(any(valves == 14)) DumpFromFillupHead_Pump2 = .true. + IF(any(valves == 70)) DumpFromTopDrive_Pump2 = .true. + + endif + + + if(valves(first)==84) then + !DumpCementPump=1 + condition28 = .true. + IF(any(valves == 56)) DumpFromKelly_Pump3 = .true. + IF(any(valves == 14)) DumpFromFillupHead_Pump3 = .true. + IF(any(valves == 70)) DumpFromTopDrive_Pump3 = .true. + + endif + + ! DumpFromKelly + !if (DumpFromKelly_Pump1 .or. DumpFromKelly_Pump2 .or. DumpFromKelly_Pump3) then + ! DumpFromKelly = 1.0 + !else + ! DumpFromKelly = 0.0 + !endif + + + ! DumpFromFillupHead + if (DumpFromFillupHead_Pump1 .or. DumpFromFillupHead_Pump2 .or. DumpFromFillupHead_Pump3) then + DumpFromFillupHead = 1.0 + else + DumpFromFillupHead = 0.0 + endif + + endif + + + + !================================================ + + + !=======MudPumps1&2ToActiveTank_Through65&66========== + + ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + + + if(valves(last)==71) then + if(valves(first)==82 .and. any(valves == 65)) then + !j15=j15+1 + !H82=1.0 + condition29 = .true. + endif + + if(valves(first)==83 .and. any(valves == 66)) then + !j15=j15+1 + !H83=1.0 + condition30 = .true. + endif + + endif + !================================================ + + !=======CementPumpToCementTank_Through67========== + + ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + + + if(valves(last)==73 .and. valves(first)==84 .and. any(valves == 67)) then + + !H84=1.0 + condition31 = .true. + + endif + !================================================ + + + + !===============PathsToGauge75=================== + if(valves(last)==75) then + if(valves(first)==82) then !Pump1 to Gauge75 + !j16=j16+1 + !K82=1 + condition35 = .true. + endif + + if(valves(first)==83) then !Pump2 to Gauge75 + !j16=j16+1 + !K83=1 + condition36 = .true. + endif + + if(valves(first)==84) then !Pump3 to Gauge75 + !j16=j16+1 + !K84=1 + condition37 = .true. + endif + + if(valves(first)==79) then !String to Gauge75 + !j16=j16+1 + !K79=1 + condition38 = .true. + endif + + if(valves(first)==78) then !Dump to Gauge75 + !j16=j16+1 + !K78=1 + condition39 = .true. + endif + + endif + !================================================ + + !===============PathsToGauge76=================== + if(valves(last)==76) then + if(valves(first)==82) then !Pump1 to Gauge76 + !j17=j17+1 + !L82=1 + condition40 = .true. + endif + + if(valves(first)==83) then !Pump2 to Gauge76 + !j17=j17+1 + !L83=1 + condition41 = .true. + endif + + if(valves(first)==84) then !Pump3 to Gauge76 + !j17=j17+1 + !L84=1 + condition42 = .true. + endif + + if(valves(first)==79) then !String to Gauge76 + !j17=j17+1 + !L79=1 + condition43 = .true. + endif + + if(valves(first)==78) then !Dump to Gauge76 + !j17=j17+1 + !L78=1 + condition44 = .true. + endif + + endif + !================================================ + + + !====Pump1-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(valves(first)==82 .and. any(valves == 2)) then + if(valves(last)==71) then + !j18=j18+1 + !M71=1. + !Pump1toCh= 1. + condition46 = .true. + endif + + if(valves(last)==77) then + !j18=j18+1 + !M77=1. + !Pump1toCh= 1. + condition47 = .true. + endif + + if(valves(last)==78) then + !j18=j18+1 + !M78=1. + !Pump1toCh= 1. + condition48 = .true. + endif + + endif + !================================================================= + + + !====Pump2-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(valves(first)==83 .and. any(valves == 2)) then + if(valves(last)==71) then + !j18=j18+1 + !M71=1. + !Pump2toCh= 1. + condition49 = .true. + endif + + if(valves(last)==77) then + !j18=j18+1 + !M77=1. + !Pump2toCh= 1. + condition50 = .true. + endif + + if(valves(last)==78) then + !j18=j18+1 + !M78=1. + !Pump2toCh= 1. + condition51 = .true. + endif + + endif + !================================================================= + + + !====Pump3-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(valves(first)==84 .and. any(valves == 2)) then + if(valves(last)==71) then + !j18=j18+1 + !M71=1. + !Pump3toCh= 1. + condition52 = .true. + endif + + if(valves(last)==77) then + !j18=j18+1 + !M77=1. + !Pump3toCh= 1. + condition53 = .true. + endif + + if(valves(last)==78) then + !j18=j18+1 + !M78=1. + !Pump3toCh= 1. + condition54 = .true. + endif + + endif + !================================================================= + + + + + !===============PumpsToWell_KillLine============ + if(valves(last)==79) then + if(valves(first)==82) then + !j19=j19+1 + !N82=1 + condition55 = .true. + endif + + if(valves(first)==83) then + !j19=j19+1 + !N83=1 + condition56 = .true. + endif + + if(valves(first)==84) then + !j19=j19+1 + !N84=1 + condition57 = .true. + endif + + endif + !================================================ + + !===============WellToChokeLineGauge============ + if(valves(first)==79 .and. valves(last)==85) then + !j20=j20+1 + condition58 = .true. + endif + !================================================ + + + !============ChokeLineGaugeToTanks=============== + if(valves(first)==85) then + if(valves(last)==71) then + !j21=j21+1 + condition59 = .true. + endif + + if(valves(last)==77) then + !j21=j21+1 + condition60 = .true. + endif + + if(valves(last)==78) then + !j21=j21+1 + condition61 = .true. + endif + + endif + !================================================ + + end subroutine + +end module MudSystemModule \ No newline at end of file diff --git a/Equipments/MudSystem-old/MudSystemMain.f90 b/Equipments/MudSystem-old/MudSystemMain.f90 new file mode 100644 index 0000000..f5a437e --- /dev/null +++ b/Equipments/MudSystem-old/MudSystemMain.f90 @@ -0,0 +1,85 @@ +module MudSystemMain + implicit none + public + contains + + ! subroutine MudSystem_Setup() + ! ! use CSimulationVariables + ! use MudSystemModule + ! implicit none + ! call SetupMudSystem() + ! call OnSimulationStop%Add(MudSystem_Stop) + ! call OnMudSystemStart%Add(MudSystem_Start) + ! call OnMudSystemStep%Add(MudSystem_Step) + ! call OnMudSystemMain%Add(MudSystemMainBody) + ! end subroutine + + subroutine MudSystem_Stop + implicit none + !print* , 'MudSystem_Stop' + CALL DEALLOCATE_ARRAYS_MudSystem() + end subroutine MudSystem_Stop + + subroutine MudSystem_Init + implicit none + !print* , 'MudSystem_Start' + CALL MudSystem_StartUp() + end subroutine MudSystem_Init + + subroutine MudSystem_Step + use MudSystemModule + use CManifolds + implicit none + !print* , 'MudSystem_Step' + !CALL main + if(Manifold%IsTraverse) then + call LineupAndPath() + Manifold%IsTraverse = .false. + endif + call main() + end subroutine MudSystem_Step + + ! subroutine MudSystemMainBody + ! ! use CSimulationVariables + ! use MudSystemModule + ! implicit none + +! INTEGER :: MudDuration +! integer,dimension(8) :: MudStartTime , MudEndTime +! +!CALL MudSystem_StartUp() +! loop1: DO +! +! CALL DATE_AND_TIME(values=MudStartTime) +! !WRITE (*,*) '***MudSys_timeCounter', MudSys_timeCounter +! +! +! CALL main +! +! CALL DATE_AND_TIME(values=MudEndTime) +! +! MudDuration = 3600000 * (MudEndTime(5) - MudStartTime(5)) + 60000 * (MudEndTime(6) - MudStartTime(6)) + 1000 * (MudEndTime(7) - MudStartTime(7)) + (MudEndTime(8) - MudStartTime(8)) +! +! if (MudDuration < 100) then +! ELSE +! WRITE (*,*) 'Mud System run duration exceeded 100 ms and =', MudDuration +! end if +! +! IF (IsStopped==.true.) THEN +! EXIT loop1 +! ENDIF +! +! !CALL DATE_AND_TIME(values=FlowEndTime) +! !WRITE (*,*) 'FlowEndTime=' , FlowEndTime +! +! !FlowDuration = FlowEndTime(8) - FlowStartTime(8) +! +! !WRITE (*,*) 'FlowDuration Mud system=' , FlowDuration +! +! ENDDO loop1 +! +! CALL DEALLOCATE_ARRAYS_MudSystem() + + ! end subroutine MudSystemMainBody + +end module MudSystemMain \ No newline at end of file diff --git a/Equipments/MudSystem-old/MudSystemStartup.f90 b/Equipments/MudSystem-old/MudSystemStartup.f90 new file mode 100644 index 0000000..f16b31d --- /dev/null +++ b/Equipments/MudSystem-old/MudSystemStartup.f90 @@ -0,0 +1,501 @@ + SUBROUTINE NormalCirculation_StartUp() ! is called in module FluidFlowMain + + USE MudSystemVARIABLES + use CTanksVariables + USE CMudPropertiesVariables + Use GeoElements_FluidModule + use KickVARIABLESModule + Use CUnityOutputs + Use CShoeVariables + USE Pumps_VARIABLES + + implicit none + + ! temporary varibales for solving pressure jerks -- 1399-11-09 + !Pump1BlownInTimeStep = 0 + !Pump2BlownInTimeStep = 0 + !Pump3BlownInTimeStep = 0 + + !Pump1BlownStarted = .FALSE. + !Pump2BlownStarted = .FALSE. + !Pump3BlownStarted = .FALSE. + + MudSystem%Pump1BlownCount = 0 + MudSystem%Pump2BlownCount = 0 + MudSystem%Pump3BlownCount = 0 + + +MudSystem%DeltaWellCap=0. +MudSystem%WellCapOld = 0. +MudSystem%AnnCapOld=0. +MudSystem%DeltaAnnCap=0. + + +MPumps%Total_Stroke_Counter_For_Plot = 0.0 + + MudSystem%DeltaT_Mudline=0.1 !second + + Call Set_FlowKellyDisconnect(.false.) + Call Set_FlowPipeDisconnect(.false.) + +!HZ_ADD= 0.d0 +MudSystem%Flow_timeCounter= 0 +MudSystem%MudSys_timeCounter= 0 +MudSystem%FluidFlowCounter = 0 +!======================================================================== +! MUD CIRCULATION STARTUP +!======================================================================== + + MudSystem%FormationLostPressure= Shoe%LeakOff * Shoe%ShoeDepth + MudSystem%ShoeFractured= .false. + + MudSystem%UGBOSuccessionCounter = 0 ! also in starup + MudSystem%UGBOSuccessionCounterOld = 0 ! also in starup + + + + MudSystem%ChokeLineFlowRate= 0.0 + MudSystem%StringFlowRate= 0.0 + MudSystem%AnnulusFlowRate= 0.0 + + MudSystem%MudVolume_InjectedFromAnn= 0.D0 + MudSystem%MudVolume_InjectedToBH= 0.D0 + + MudSystem%DensityMixTol= 0.1 !(ppg) + MudSystem%CuttingDensityMixTol= 0.5 + MudSystem%NewPipeFilling= 1 + MudSystem%UtubeFilling= 1 + MudSystem%UtubeEmptyVolume= 0.0 + + MudSystem%UtubeMode1Activated= .false. + MudSystem%UtubeMode2Activated= .false. + MudSystem%UtubePossibility= .false. + + + !KickMigration_2SideBit = .FALSE. + + MudSystem%KickDx= (Reservoir%AutoMigrationRate/3600.)*MudSystem%DeltaT_Mudline !AutoMigrationRate (ft/h)= ft per DeltaT_Mudline + + + MudSystem%NewInfluxElementCreated= 0 + MudSystem%NewInfluxNumber= 0 + + !KickVolumeinAnnulus= 0.0 + MudSystem%KickDeltaVinAnnulus= 0.0 + GasKickPumpFlowRate= 0.0 + + 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) + + MudSystem%TotalAddedVolume= 0. + + + MudSystem%xx=0. + + + + END SUBROUTINE NormalCirculation_StartUp + + + + + + + + SUBROUTINE MudSystem_StartUp() + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE CDataDisplayConsoleVariables + USE CHOKEVARIABLES + USE Pumps_VARIABLES + USE CBopStackVariables + USE CPumpsVariables + use CTanksVariables + use KickVARIABLESModule + implicit none + + + + + + CALL MUDLINE_LOSS_INPUTS() + +!MPumps%Total_Pump_GPM=10. ! Initial Value + MUD%Q=0. ! Initial Value + + MudSystem%Q_flow32=0. + MudSystem%Q_flow33=0. + MudSystem%Q_flow34=0. + MudSystem%Q_flow35=0. + + MudSystem%DeltaT_Mudline=0.1 !second + + GasKickPumpFlowRate= 0. + MudSystem%BellNippleVolume= 0. + MudSystem%BellNippleDensity= 0. + MudSystem%MudBucketVolume= 0. + MudSystem%MudBucketDensity= 0. + MudSystem%BellNippleDumpVolume= 0. + !BellNippleDumpRate= 0. + !BellNippleToPitsRate= 0.0 + MudSystem%MudChecked= .true. + + MudSystem%condition32Final= .TRUE. + MudSystem%condition33Final= .TRUE. + MudSystem%condition34Final= .TRUE. + + +MudSystem%PressureGauge75= 0.0 +MudSystem%PressureGauge76 = 0.0 + + +!!====================================================================== +!! TRIP TANK +!!====================================================================== + + MudSystem%TripTank_MinVol_Allowded= 50.*42. !(bbl to gal, initial value) + MudSystem%TripTank_MaxVol_Allowded= 50. *42. !(bbl to gal, initial value) + + +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 + + + +MudSystem%TripTank_Vol= MudProperties%InitialTripTankMudVolumeGal !(gal) +MudSystem%TripTank_Dens= 1. +DataDisplayConsole%TripTankGauge=0. + + + +MudSystem%ReturnToTrip_Q= 1. +MudSystem%ActiveToTrip_Q= 1. + + +MudSystem%TripTankPump_Q= .8 + + +MudSystem%ReturnToTrip_Dens=1.0 ! ppg(lbm/gal) +MudSystem%ActiveToTrip_Dens=1.0 + +!!====================================================================== +!! MUD VOLUME TOTALIZER +!!====================================================================== + +MudSystem%Mp1Density= 0.0 !(VALVE82) +MudSystem%Mp2Density= 0.0 !(VALVE83) +MudSystem%Mp3Density= 0.0 !(VALVE84) + + +MudSystem%ReserveTankVolume= MudProperties%ReserveMudVolumeGal ! initial volume (gal) +MudSystem%ReserveTankDensity= MudProperties%ReserveDensity ! initial + + + +MudSystem%CementTankVolumeCalc= Tank%CementTankVolume !movaghat--- initial volume (gal) +MudSystem%CementTankDensityCalc= Tank%CementTankDensity !movaghat--- initial + +MudSystem%PumpsDumpVolume=0.0 +MudSystem%PumpsDumpFlowRate= 0.0 + + + +MudSystem%ActiveTankVolume= MudProperties%ActiveMudVolumeGal ! initial volume (gal) +MudSystem%RefrencePitVolume= MudSystem%ActiveTankVolume/42. !(bbl) +MudSystem%RefrencePitVolume_DrillWatch= MudSystem%ActiveTankVolume/42. !(bbl) + +MudSystem%MVT_MinVol_Allowded= 0. +MudSystem%MVT_MaxVol_Allowded= 0. + +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) + +MudSystem%TripTankVolumeCalc= MudProperties%InitialTripTankMudVolumeGal ! initial volume (gal) +MudSystem%ActiveTankDensity= MudProperties%ActiveDensity ! initial(ppg) +MudSystem%TripTankDensityCalc= Tank%TripTankDensity ! initial(ppg) + +MudSystem%ChokeManifoldDumpVolume= 0.0 + +MudSystem%PitGainLossZero= 0. +MudSystem%PitGainLossZero_Old= MudSystem%PitGainLossZero +MudSystem%MVTCoarseKnob_Old= DataDisplayConsole%MVTCoarseKnob +MudSystem%MVTFineKnob_Old= DataDisplayConsole%MVTFineKnob +MudSystem%FirstSet_Time= .true. + + + +MudSystem%PedalMeter= MudProperties%PedalFlowMeter !1600. !(gpm) +MudSystem%ReturnFlowRate=0. + + + + MudSystem%TotalStrokes1MFFI =0. + MudSystem%TotalStrokes2MFFI =0. + + MudSystem%TotalStrokesPump1=0. + MudSystem%TotalStrokesPump2=0. + MudSystem%GraphTotalStrokes=0. + + + Choke%TotalStrokes1 =0. + Choke%TotalStrokes2 =0. + + + + + + + end + + + + + + + + + + + +SUBROUTINE MUDLINE_LOSS_INPUTS() +USE MudSystemVARIABLES +USE CBopStackVariables +USE CPumpsVariables +implicit none +INTEGER I + + + +!=========================================================================== +! MUDLINE MINOR LOSSES INPUT +!=========================================================================== + +MudSystem%NO_MudMinors=4 + +ALLOCATE (MudSystem%MudMinors(MudSystem%NO_MudMinors,4)) + +! ID(INCH) LF CV NOTE(BAR) DESCRIPTION +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 (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,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) + + + MudSystem%AREAMINOR_MUDLINE(I)=PII*(MudSystem%MINORDIAMETER_MUDLINE(I)*0.0254)**2/4. !D(in), AREA(m^2) +ENDDO + +!=========================================================================== +! MUDLINE PIPNING LOSSES INPUT +!=========================================================================== +MudSystem%NO_PIPINGSMUDLINE=4 + +ALLOCATE (MudSystem%PIPINGS_MUDLINE(MudSystem%NO_PIPINGSMUDLINE,3)) + + ! ID(INCH) L(FEET) ROUGHNESS(MM)=e DESCRIPTION +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) + +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 (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,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) + + + + 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) + MudSystem%LENGT_MUDLINE(I)=MudSystem%LENGT_MUDLINE(I)*.3048 ! (m) +ENDDO + + +!=========================================================================== +! MUDLINE STATIC LOSSES INPUT +!=========================================================================== + +! Height are in (meter) +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 + + + + + + + + + + + + + + END + + + + + SUBROUTINE MUDLINE_LOSSES(MLnumber) + + USE MudSystemVARIABLES + implicit none + integer I + INTEGER MLnumber + + +!===============================PIPE LOSS=================================== + 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_MUDlineStandPipePressure + !use CManifolds + use CDrillWatchVariables + !use CHOKEVARIABLES + !use CChokeManifoldVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + USE CKellyConnectionEnumVariables + use UTUBEVARSModule + use CLog1 + Use CError + Use , intrinsic :: IEEE_Arithmetic + + implicit none + + integer jelement, jmud, jsection,ielement,i + integer jopelement,jopmud,jopsection + character(len=120) :: temp1, temp2 + + + + + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + write(*,*) 'well cap=' , sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) + sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) + MudSystem%DeltaWellCap= sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) + sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) - MudSystem%WellCapOld + MudSystem%WellCapOld= sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) + sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) + write(*,*) 'cap_reset,DeltaWellCap=' , MudSystem%DeltaWellCap + endif + + + + +!========================ANNULUS END================= +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 + MudSystem%WellisNOTFull= .false. +endif + +!WRITE(*,*) 'Ann_Mud_Forehead_X%Last() , KillHeight', Ann_Mud_Forehead_X%Last() , KillHeight +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 + MudSystem%ChokeLineNOTFull= .false. +endif + +!========================================================= + + jmud= 1 + jsection= 1 + jelement= 0 ! number of final mud elements + + + + 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 MudSystem%MudType_MudElement%Empty() + + + + DO WHILE(jmud <= MudSystem%Hz_Mud_Forehead_X%Length() .and. jsection<=1) + + jelement= jelement+1 + MudSystem%TrueMinValue= min(MudSystem%Hz_Mud_Forehead_X%Array(jmud), MudSystem%Xend_PipeSection(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 MudSystem%MudType_MudElement%Add(MudSystem%Hz_MudOrKick%Array(jmud)) + + + if (MudSystem%Xend_MudElement%Array(jelement)== MudSystem%Hz_Mud_Forehead_X%Array(jmud)) then + jmud= jmud+1 + else + jsection= jsection+1 + endif + + ENDDO + + MudSystem%NoHorizontalMudElements= jelement + + + + + jmud= 1 + jsection= 2 + + DO WHILE(jmud <= MudSystem%St_Mud_Forehead_X%Length() .and. jsection<=F_Counts%StringIntervalCounts) + + jelement= jelement+1 + MudSystem%TrueMinValue= min(MudSystem%St_Mud_Forehead_X%Array(jmud), MudSystem%Xend_PipeSection(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 MudSystem%MudType_MudElement%Add(MudSystem%St_MudOrKick%Array(jmud)) + + + if (MudSystem%Xend_MudElement%Array(jelement)== MudSystem%St_Mud_Forehead_X%Array(jmud)) then + jmud= jmud+1 + else + jsection= jsection+1 + endif + + ENDDO + + MudSystem%NoStringMudElements= jelement- MudSystem%NoHorizontalMudElements + + + + + + jmud= 1 + jsection= F_Counts%StringIntervalCounts+1 + DO WHILE(jmud<= MudSystem%Ann_Mud_Forehead_X%Length() .and. jsection<=MudSystem%NoPipeSections) + + jelement= jelement+1 + MudSystem%TrueMinValue= max(MudSystem%Ann_Mud_Forehead_X%Array(jmud), MudSystem%Xend_PipeSection(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 MudSystem%MudType_MudElement%Add(MudSystem%Ann_MudOrKick%Array(jmud)) + + + if (MudSystem%Xend_MudElement%Array(jelement)== MudSystem%Ann_Mud_Forehead_X%Array(jmud)) then + jmud= jmud+1 + else + jsection= jsection+1 + endif + + ENDDO + + 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 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 + + MudSystem%NoCasingMudElements = jelement- MudSystem%NoStringMudElements- MudSystem%NoHorizontalMudElements + + +!=========================For Torque and Drag======================== + 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)) + + MudSystem%TDNoHorizontalMudElements= MudSystem%NoHorizontalMudElements + MudSystem%TDNoStringMudElements= MudSystem%NoStringMudElements + MudSystem%TDNoCasingMudElements= MudSystem%NoCasingMudElements + + + MudSystem%TDXstart_MudElementArray(:) = MudSystem%Xstart_MudElement%Array(:) + MudSystem%TDXend_MudElementArray(:) = MudSystem%Xend_MudElement%Array(:) + MudSystem%TDDensity_MudElementArray(:) = MudSystem%Density_MudElement%Array(:) +!===================================================================== + + + !do i=NoHorizontalMudElements+1, NoHorizontalMudElements+NoStringMudElements ! 2-string elements + ! 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 + + + + !================================================================ + + ! Open Hole Mud Elements + jopmud= 1 + jopsection= 1 + jopelement= 0 ! number of final mud elements + + + 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 MudSystem%MudTypeOp_MudElement%Empty() + + + + DO WHILE(jopmud<= MudSystem%Op_Mud_Forehead_X%Length() .and. jopsection<=F_Counts%BottomHoleIntervalCounts) + + jopelement= jopelement+1 + 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 MudSystem%MudTypeOp_MudElement%Add(MudSystem%Op_MudOrKick%Array(jopmud)) + + + if (MudSystem%Xend_OpMudElement%Array(jopelement)== MudSystem%Op_Mud_Forehead_X%Array(jopmud)) then + jopmud= jopmud+1 + else + jopsection= jopsection+1 + endif + + ENDDO + + 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 + + MudSystem%NoBottomHoleMudElements = jopelement + + + !================================================================ + + + + if(allocated(MudSystem%StringMudElement)) deallocate(MudSystem%StringMudElement) + allocate(MudSystem%StringMudElement(MudSystem%NoStringMudElements)) + + if(allocated(MudSystem%CasingMudElement)) deallocate(MudSystem%CasingMudElement) + allocate(MudSystem%CasingMudElement(MudSystem%NoCasingMudElements+MudSystem%NoBottomHoleMudElements)) + + MudSystem%istring=0 + MudSystem%icasing=0 + + 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 (MudSystem%UtubePossibility== .true. .and. TD_StConn%FluidStringConnectionMode==0 .and. MudSystem%WellHeadIsOpen .AND. NoGasPocket == 0) THEN + CALL WellPressureDataTransfer + !WRITE (*,*) ' U-Tube Done 1' + CALL Utube + !WRITE (*,*) ' U-Tube Done 2' + if (QUtubeInput> 0.0) call Utube1_and_TripIn + if (QUtubeOutput> 0.0) call Utube2_and_TripIn + END IF + + !========================== UTUBE- end ========================= + + ! do imud=1, st_MudDischarged_Volume%Length() + ! write(*,*) 'st-plot:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud) + !enddo +!==================== Display ======================== + !do i=1, St_MudOrKick%Length() + ! write(*,555) i,'St_Volume(i), type=' ,St_MudDischarged_Volume%Array(i),St_MudOrKick%Array(i) + ! + ! IF (IEEE_Is_NaN(St_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in St Volume-Plot') + ! IF (St_MudDischarged_Volume%Array(i)<0.) call ErrorStop('St Volume <0' , St_MudDischarged_Volume%Array(i)) + !enddo + + + 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(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 + + !do i=1, Ann_MudOrKick%Length() + ! !write(*,555) i,'Ann_Volume(i), type=' ,Ann_MudDischarged_Volume%Array(i),Ann_MudOrKick%Array(i),Ann_Density%Array(i) + ! + ! IF (IEEE_Is_NaN(Ann_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in Ann Volume-Plot') + ! IF (Ann_MudDischarged_Volume%Array(i)<=0.) call ErrorStop('Ann Volume <=0' , Ann_MudDischarged_Volume%Array(i)) + !enddo + +555 FORMAT(I3,5X,A42,(f12.5),5X,I3,5X,(f12.5)) + + 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=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 + 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) + MudSystem%StringMudElement(MudSystem%istring)%Density = MudSystem%Density_MudElement%Array(i) + + 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 + + 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=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) + MudSystem%CasingMudElement(MudSystem%icasing)%Density = MudSystem%Density_MudElement%Array(i) + + 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 + + MudSystem%CasingMudElement(MudSystem%icasing)%MudType = MudSystem%MudType_MudElement%Array(i) + + enddo + + 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) + MudSystem%CasingMudElement(MudSystem%icasing)%Density = MudSystem%Density_OpMudElement%Array(i) + + 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 + + MudSystem%CasingMudElement(MudSystem%icasing)%MudType = MudSystem%MudTypeOp_MudElement%Array(i) + enddo + + + +333 FORMAT(A10,I3,5X,A8,(f12.5),5X,A8,(f12.5),5X,A8,(f12.5),5X,A8,I3) +444 FORMAT(A10,I2,5X,A8,(f12.3),5X,A8,(f12.3),5X,A8,(f12.3),5X,A8,(f12.3)) + + + + ! shomare gozari be tartib HZ mud, ST mud, Casing + ! shomare gzari OpenHole jodagane ast az 1 + + call SetStringFluids(MudSystem%NoStringMudElementsForPlot, MudSystem%StringMudElement) !for data display in string + call SetAnnalusFluids(MudSystem%NoCasingMudElements+MudSystem%NoBottomHoleMudElements, MudSystem%CasingMudElement) !for data display in casing + + +!=========================================================================================================================== +!=========================================================================================================================== + + + end subroutine PlotFinalMudElements + + + diff --git a/Equipments/MudSystem-old/Pump_and_Trip_In.f90 b/Equipments/MudSystem-old/Pump_and_Trip_In.f90 new file mode 100644 index 0000000..d9cf373 --- /dev/null +++ b/Equipments/MudSystem-old/Pump_and_Trip_In.f90 @@ -0,0 +1,1627 @@ +subroutine Pump_and_TripIn ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + !USE CHOKEVARIABLES + !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure + !use CManifolds + use CDrillWatchVariables + !use CHOKEVARIABLES + !use CChokeManifoldVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + Use CShoeVariables + use CError + + + implicit none + +integer i,ii,AddLocation +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + + MudSystem%StringFlowRate= MUD(2)%Q + MudSystem%AnnulusFlowRate= MUD(2)%Q + + + !write(*,*) 'Trip In' + + +!========================Horizontal PIPE ENTRANCE================= + + if (ABS(MudSystem%SuctionDensity_Old - MudSystem%Suction_Density_MudSystem) >= MudSystem%DensityMixTol) then ! new mud is pumped + + call MudSystem%Hz_Density%AddToFirst (MudSystem%Suction_Density_MudSystem) + call MudSystem%Hz_MudDischarged_Volume%AddToFirst (0.0d0) + call MudSystem%Hz_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(1)) + call MudSystem%Hz_Mud_Forehead_section%AddToFirst (1) + call MudSystem%Hz_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(1)) + call MudSystem%Hz_Mud_Backhead_section%AddToFirst (1) + call MudSystem%Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Hz_MudOrKick%AddToFirst (0) + + MudSystem%SuctionDensity_Old= MudSystem%Suction_Density_MudSystem + endif + +!========================Horizontal PIPE STRING================= + + MudSystem%Hz_MudDischarged_Volume%Array(1)= MudSystem%Hz_MudDischarged_Volume%Array(1)+ ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) + + MudSystem%total_add = MudSystem%total_add + ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) + + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + MudSystem%total_add= 0. + endif + + + !write(*,*) ' total decrease(add to HZ)=' , total_add + !write(*,*) ' add to HZ=' , ((MudSystem%StringFlowRate/60.0d0)*DeltaT_Mudline) + +imud=0 + do while (imud < MudSystem%Hz_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%Hz_Mud_Backhead_X%Array(imud)= MudSystem%Hz_Mud_Forehead_X%Array(imud-1) + MudSystem%Hz_Mud_Backhead_section%Array(imud)= MudSystem%Hz_Mud_Forehead_section%Array(imud-1) + endif + + + MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))- MudSystem%Hz_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_PipeSectionFt(MudSystem%Hz_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( MudSystem%Hz_MudDischarged_Volume%Array(imud) <= MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Hz_Mud_Forehead_section%Array(imud)= MudSystem%Hz_Mud_Backhead_section%Array(imud) + MudSystem%Hz_Mud_Forehead_X%Array(imud)= MudSystem%Hz_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%Hz_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%Hz_Mud_Backhead_section%Array(imud)) + + else + + + MudSystem%isection= MudSystem%Hz_Mud_Backhead_section%Array(imud)+1 + MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Hz_MudDischarged_Volume%Array(imud)- MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > 1) then ! (horizontal pipe exit) + MudSystem%Hz_MudDischarged_Volume%Array(imud)= MudSystem%Hz_MudDischarged_Volume%Array(imud)- MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud) + MudSystem%Hz_Mud_Forehead_X%Array(imud)= MudSystem%Xend_PipeSection(1) + MudSystem%Hz_Mud_Forehead_section%Array(imud)= 1 + + if (MudSystem%Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveHzMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Hz_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%Hz_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_PipeSection(MudSystem%isection)- MudSystem%Xstart_PipeSection(MudSystem%isection)))+ MudSystem%Xstart_PipeSection(MudSystem%isection) + exit + else + MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo +!========================Horizontal PIPE END================= + + +!========================Utube1 Air Element Removing================= + + !if (UtubeMode1Activated== .true.) then ! StringUpdate == .true. + ! + ! + ! !StringDensity_Old=MudSystem%St_Density%Array(2) + ! + ! write(*,*) 'StringDensity_Old=' , StringDensity_Old + ! + ! UtubeMode1Activated= .false. + !endif + +!========================Utube1 Air Element Removing End================= + +!!========================Utube2 Removing from Annulus================= not needed 97.04.26 +! +! if (UtubeMode2Activated== .true.) then ! StringUpdate == .true. +! +! if (Ann_MudOrKick%Last() == 104) then !movaghati. albate age merge anjam shode bashe moshkeli nist +! call RemoveAnnulusMudArrays(Ann_MudOrKick%Length()) +! endif +! +! UtubeMode2Activated= .false. +! endif +! +! +!!========================Utube2 Removing from Annulus End================= + +!========================New Pipe Filling================= + + !if (F_StringIntervalCounts > F_StringIntervalCountsOld) then ! StringUpdate == .true. + if (MudSystem%AddedElementsToString > 0) then ! StringUpdate == .true. + + !NoPipeAdded= F_Counts%StringIntervalCounts - F_StringIntervalCountsOld + + + MudSystem%NewPipeFilling=0 + + IF (MudSystem%St_MudOrKick%First() == 104) then + MudSystem%St_MudDischarged_Volume%Array(1) = MudSystem%St_MudDischarged_Volume%Array(1) + sum(MudSystem%PipeSection_VolumeCapacity(2:1+MudSystem%AddedElementsToString)) ! new pipe is filled by air + else + call MudSystem%St_Density%AddToFirst (0.d0) + call MudSystem%St_MudDischarged_Volume%AddToFirst (sum(MudSystem%PipeSection_VolumeCapacity(2:1+MudSystem%AddedElementsToString))) + call MudSystem%St_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Forehead_section%AddToFirst (2) + call MudSystem%St_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.d0) + call MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.d0) + call MudSystem%St_MudOrKick%AddToFirst (104) + endif + + endif + + !F_StringIntervalCountsOld= F_StringIntervalCounts + + + + if (MudSystem%NewPipeFilling == 0) then ! 2= is the first element of string (1= is for Hz pipe) + + + MudSystem%LackageMudVolume= MudSystem%St_MudDischarged_Volume%Array(1) ! = Air element + + + write(*,*) 'LackageMudVolume=' , MudSystem%LackageMudVolume + + + + if (ABS(MudSystem%St_Density%Array(2) - MudSystem%Hz_Density%Last()) >= MudSystem%DensityMixTol) then ! new mud is pumped + call MudSystem%St_Density%AddTo (2,MudSystem%Hz_Density%Last()) + call MudSystem%St_MudDischarged_Volume%AddTo (2, 0.d0) + call MudSystem%St_Mud_Forehead_X%AddTo (2,MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Forehead_section%AddTo (2 , 2) + call MudSystem%St_Mud_Backhead_X%AddTo (2,MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Backhead_section%AddTo (2 ,2) + call MudSystem%St_RemainedVolume_in_LastSection%AddTo (2,0.d0) + call MudSystem%St_EmptyVolume_inBackheadLocation%AddTo (2,0.d0) + call MudSystem%St_MudOrKick%AddTo (2,0) + + !StringDensity_Old= Hz_Density%Last() + endif + + + MudSystem%St_MudDischarged_Volume%Array(2)= MudSystem%St_MudDischarged_Volume%Array(2)+ min( ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline), MudSystem%LackageMudVolume) !(gal) + + MudSystem%St_MudDischarged_Volume%Array(1)= MudSystem%St_MudDischarged_Volume%Array(1)- min( ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline), MudSystem%LackageMudVolume) ! air(gal) + + !LackageMudVolumeAfterFilling= sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts)) - sum(St_MudDischarged_Volume%Array(:)) + + MudSystem%LackageMudVolumeAfterFilling= MudSystem%St_MudDischarged_Volume%Array(1) ! last time it should be zero + + + + if (MudSystem%LackageMudVolumeAfterFilling == 0.) then + MudSystem%NewPipeFilling= 1 + call RemoveStringMudArrays(1) + MudSystem%St_Mud_Backhead_X%Array(1) = MudSystem%Xstart_PipeSection(2) + MudSystem%St_Mud_Backhead_section%Array(1) = 2 + endif + + endif + +!========================New Pipe Filling End================= + + + + + if (MudSystem%NewPipeFilling == 0) then + MudSystem%StringFlowRate= 0. + MudSystem%AnnulusFlowRate= 0. + endif + + MudSystem%StringFlowRateFinal= MudSystem%StringFlowRate + MudSystem%AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate + + + + +!========================STRING ENTRANCE================= + + if (MudSystem%StringFlowRateFinal > 0.0 .and. ABS(MudSystem%St_Density%First() - MudSystem%Hz_Density%Last()) >= MudSystem%DensityMixTol) then ! new mud is pumped + call MudSystem%St_Density%AddToFirst (MudSystem%Hz_Density%Last()) + call MudSystem%St_MudDischarged_Volume%AddToFirst (0.0d0) + call MudSystem%St_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Forehead_section%AddToFirst (2) + call MudSystem%St_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%St_MudOrKick%AddToFirst (0) + + !StringDensity_Old= Hz_Density%Last() + endif + + + MudSystem%St_MudDischarged_Volume%Array(1)= MudSystem%St_MudDischarged_Volume%Array(1)+ ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) + +!=============== save String Mud data=========== + + + + + MudSystem%StMudVolumeSum= 0.d0 + !St_MudSaved_Density= 0.d0 + MudSystem%St_Saved_MudDischarged_Volume= 0.d0 + !Saved_St_MudOrKick= 0 + !Ann_to_Choke_2mud= .false. + + do imud=1, MudSystem%St_MudDischarged_Volume%Length() + + MudSystem%StMudVolumeSum = MudSystem%StMudVolumeSum + MudSystem%St_MudDischarged_Volume%Array(imud) + + if ( MudSystem%StMudVolumeSum > sum(MudSystem%PipeSection_VolumeCapacity(2:F_Counts%StringIntervalCounts)) ) then + + !IF (St_MudOrKick%Array(imud) == 0) THEN + MudSystem%St_MudSaved_Density =MudSystem%St_Density%Array(imud) + MudSystem%St_Saved_MudDischarged_Volume = MudSystem%StMudVolumeSum - sum(MudSystem%PipeSection_VolumeCapacity(2:F_Counts%StringIntervalCounts)) + !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR + ! St_Kick_Saved_Volume = StMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! Saved_St_MudOrKick= St_MudOrKick%Array (imud) + ! St_KickSaved_Density=MudSystem%St_Density%Array(imud) + !END IF + + do ii= imud + 1, MudSystem%St_MudDischarged_Volume%Length() + !IF (St_MudOrKick%Array(ii) == 0) THEN + MudSystem%St_MudSaved_Density = ((MudSystem%St_MudSaved_Density * MudSystem%St_Saved_MudDischarged_Volume) + (MudSystem%St_Density%Array(ii) * MudSystem%St_MudDischarged_Volume%Array(ii))) / (MudSystem%St_Saved_MudDischarged_Volume + MudSystem%St_MudDischarged_Volume%Array(ii)) + MudSystem%St_Saved_MudDischarged_Volume = MudSystem%St_Saved_MudDischarged_Volume + MudSystem%St_MudDischarged_Volume%Array(ii) + + !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR + ! St_Kick_Saved_Volume = St_Kick_Saved_Volume + St_MudDischarged_Volume%Array(ii) + ! Saved_St_MudOrKick= St_MudOrKick%Array (ii) + ! St_KickSaved_Density=MudSystem%St_Density%Array(ii) + !END IF + enddo + + + !WRITE (*,*) 'St_Saved_Mud_Volume, St_Kick_Saved_Volume', St_Saved_MudDischarged_Volume, St_Kick_Saved_Volume + exit ! exits do + + endif + + enddo +MudSystem%St_Saved_MudDischarged_Volume_Final = MudSystem%St_Saved_MudDischarged_Volume + +IF (MudSystem%WellHeadIsOpen) MudSystem%MudVolume_InjectedToBH = MudSystem%St_Saved_MudDischarged_Volume_Final +!====================================================================== + +!========================STRING================= + +imud=0 + do while (imud < MudSystem%St_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%St_Mud_Backhead_X%Array(imud)= MudSystem%St_Mud_Forehead_X%Array(imud-1) + MudSystem%St_Mud_Backhead_section%Array(imud)= MudSystem%St_Mud_Forehead_section%Array(imud-1) + endif + + MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))- MudSystem%St_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_PipeSectionFt(MudSystem%St_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + !write(*,*) 'St_Mud_Backhead_section%Array(1)=' , St_Mud_Backhead_section%Array(1) + !write(*,*) 'Xend_PipeSection(St_Mud_Backhead_section%Array(1))=' , Xend_PipeSection(St_Mud_Backhead_section%Array(1)) + ! + !write(*,*) 'St_EmptyVolume_inBackheadLocation%Array(1)=' , St_EmptyVolume_inBackheadLocation%Array(1) + !write(*,*) 'St_Mud_Backhead_X%Array(1)=' , St_Mud_Backhead_X%Array(1) + + + if ( MudSystem%St_MudDischarged_Volume%Array(imud) <= MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%St_Mud_Forehead_section%Array(imud)= MudSystem%St_Mud_Backhead_section%Array(imud) + MudSystem%St_Mud_Forehead_X%Array(imud)= MudSystem%St_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%St_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%St_Mud_Backhead_section%Array(imud)) + ! 7.48 is for gal to ft^3 + + else + + MudSystem%isection= MudSystem%St_Mud_Backhead_section%Array(imud)+1 + MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= MudSystem%St_MudDischarged_Volume%Array(imud)- MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > F_Counts%StringIntervalCounts) then ! last pipe section(string exit) F_Counts%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_Counts%StringIntervalCounts) + MudSystem%St_Mud_Forehead_section%Array(imud)= F_Counts%StringIntervalCounts + + if (MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveStringMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%St_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%St_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_PipeSection(MudSystem%isection)- MudSystem%Xstart_PipeSection(MudSystem%isection)))+ MudSystem%Xstart_PipeSection(MudSystem%isection) + exit + else + MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + + endif + + enddo + + endif + + enddo + + + !write(*,*) ' a before==' + ! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + ! + !write(*,*) '==== a before' + + + + + !write(*,*) ' iloc (a): ' , iloc + +!========================STRING END================= + + IF (MudSystem%Op_MudOrKick%Last() /= 0 .and. MudSystem%Op_MudOrKick%Last()==MudSystem%Ann_MudOrKick%First()) MudSystem%iLoc=2 ! it may be 1,2,3 or more, all of them are kick +!write(*,*) ' iloc (b): ' , iloc + +!=============================Add PumpFlowRate to Bottom Hole ============================== + !if ( MudSystem%AnnulusFlowRate>0.0 ) then + if ( MudSystem%MudVolume_InjectedToBH > 0.0 ) then + + + if (KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the + AddLocation= MudSystem%Op_Density%Length()-MudSystem%iLoc+1+1 ! well, thus pumped mud should be placed above the kick + else + AddLocation= MudSystem%Op_Density%Length()+1 + endif + !write(*,*) 'AddLocation====' , AddLocation + if ( AddLocation== 0) CALL ErrorStop ('AddLocation=0') + + + if ( ABS(MudSystem%St_Density%Last() - MudSystem%Op_Density%Array(AddLocation-1)) >= MudSystem%DensityMixTol ) then + !write(*,*) 'new pocket**' + !write(*,*) MudSystem%St_Density%Last()=' ,MudSystem%St_Density%Last() + !write(*,*) 'Op_Density%Array(AddLocation-1)=' , Op_Density%Array(AddLocation-1) + + + call MudSystem%Op_Density% AddTo (AddLocation,MudSystem%St_Density%Last()) + !call Op_MudDischarged_Volume%AddTo (AddLocation,((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)) + call MudSystem%Op_MudDischarged_Volume%AddTo (AddLocation,MudSystem%MudVolume_InjectedToBH) + call MudSystem%Op_Mud_Forehead_X%AddTo (AddLocation,MudSystem%Xstart_OpSection(1)) + call MudSystem%Op_Mud_Forehead_section%AddTo (AddLocation,1) + call MudSystem%Op_Mud_Backhead_X%AddTo (AddLocation,MudSystem%Xstart_OpSection(1)) + call MudSystem%Op_Mud_Backhead_section%AddTo (AddLocation,1) + call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (AddLocation,0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (AddLocation,0.0d0) + call MudSystem%Op_MudOrKick%AddTo (AddLocation,0) + else + !write(*,*) 'merge**' + !write(*,*) 'density before=' , Op_Density%Array(AddLocation-1) + !write(*,*) MudSystem%St_Density%Last() for mix=' ,MudSystem%St_Density%Last() + + !Op_Density%Array(AddLocation-1)= (Op_Density%Array(AddLocation-1)*Op_MudDischarged_Volume%Array(AddLocation-1)MudSystem%St_Density%Last()*((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline))/(Op_MudDischarged_Volume%Array(AddLocation-1)+((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)) + !Op_MudDischarged_Volume%Array(AddLocation-1)= Op_MudDischarged_Volume%Array(AddLocation-1) + ((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) + + MudSystem%Op_Density%Array(AddLocation-1)= (MudSystem%Op_Density%Array(AddLocation-1)*MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+MudSystem%St_Density%Last()*MudSystem%MudVolume_InjectedToBH)/(MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+MudSystem%MudVolume_InjectedToBH) + MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)= MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1) + MudSystem%MudVolume_InjectedToBH + !write(*,*) 'density after=' , Op_Density%Array(AddLocation-1) + + endif + + endif +!=======================Add PumpFlowRate to Bottom Hole- End ============================== + + + + +!=============== save OP Mud data to transfer to the annulus enterance due to tripin or kick + MudSystem%OpMudVolumeSum= 0.d0 + !Op_MudSaved_Density= 0.d0 + !Op_KickSaved_Density= 0.d0 + MudSystem%Op_Saved_MudDischarged_Volume= 0.d0 + MudSystem%Op_Kick_Saved_Volume= 0.d0 + MudSystem%Saved_Op_MudOrKick= 0 + + + + !write(*,*) 'Op_Capacity===' , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) + !write(*,*) 'Op_MudDischarged_Volume%Length()===' , Op_MudDischarged_Volume%Length() + ! + + do imud=1, MudSystem%Op_MudDischarged_Volume%Length() + !write(*,*) 'imud, Op_MudDischarged_Volume%Array(imud)=' , imud,Op_MudDischarged_Volume%Array(imud) + + MudSystem%OpMudVolumeSum= MudSystem%OpMudVolumeSum + MudSystem%Op_MudDischarged_Volume%Array(imud) + + if ( MudSystem%OpMudVolumeSum > sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) ) then + + IF (MudSystem%Op_MudOrKick%Array(imud) == 0) THEN + MudSystem%Op_MudSaved_Density = MudSystem%Op_Density%Array(imud) + MudSystem%Op_Saved_MudDischarged_Volume = MudSystem%OpMudVolumeSum - sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) + ELSE + MudSystem%Op_Kick_Saved_Volume = MudSystem%OpMudVolumeSum - sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) + !write(*,*) 'cond 1- Op_MudOrKick%Array (imud),Op_Density%Array(imud):' ,Op_MudOrKick%Array (imud),Op_Density%Array(imud) + MudSystem%Saved_Op_MudOrKick= MudSystem%Op_MudOrKick%Array (imud) + MudSystem%Op_KickSaved_Density= MudSystem%Op_Density%Array(imud) + MudSystem%iLoc= 2 + END IF + + do ii= imud + 1, MudSystem%Op_MudDischarged_Volume%Length() + IF (MudSystem%Op_MudOrKick%Array(ii) == 0) THEN + MudSystem%Op_MudSaved_Density = ((MudSystem%Op_MudSaved_Density * MudSystem%Op_Saved_MudDischarged_Volume) + (MudSystem%Op_Density%Array(ii) * MudSystem%Op_MudDischarged_Volume%Array(ii))) / (MudSystem%Op_Saved_MudDischarged_Volume + MudSystem%Op_MudDischarged_Volume%Array(ii)) + MudSystem%Op_Saved_MudDischarged_Volume = MudSystem%Op_Saved_MudDischarged_Volume + MudSystem%Op_MudDischarged_Volume%Array(ii) + ELSE + MudSystem%Op_Kick_Saved_Volume = MudSystem%Op_Kick_Saved_Volume + MudSystem%Op_MudDischarged_Volume%Array(ii) + !write(*,*) 'cond 2- Op_MudOrKick%Array (ii),Op_Density%Array(ii):' ,Op_MudOrKick%Array (ii),Op_Density%Array(ii) + MudSystem%Saved_Op_MudOrKick= MudSystem%Op_MudOrKick%Array (ii) + MudSystem%Op_KickSaved_Density= MudSystem%Op_Density%Array(ii) + MudSystem%iLoc= 2 + END IF + enddo + + exit ! exits do + + endif + + enddo + !WRITE (*,*) 'Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume',Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume +!write(*,*) ' iloc (c): ' , iloc + +!====================================================================== + +!====================================================================== + + + + + + !if (iLoc == 1) then + MudSystem%MudSection= F_Counts%StringIntervalCounts+1 + MudSystem%BackheadX= MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1) + !elseif (iLoc == 2) then + ! MudSection= Kick_Forehead_section + ! BackheadX= Kick_Forehead_X + !endif + +!========================ANNULUS ENTRANCE==================== + !if (KickMigration_2SideBit == .FALSE.) then ! because its effect is applied in Migration Code + ! !write(*,*) 'iloc=====' , iLoc bejaye ROP_Bit%RateOfPenetration ==0. in bude: DeltaVolumeOp == 0.0 + ! if (ABS(AnnulusSuctionDensity_OldMudSystem%St_Density%Last()) >= DensityMixTol .OR. (DeltaVolumeOp == 0.0 .and. ABS(Ann_Density%Array(iLoc)MudSystem%St_Density%Last())>=DensityMixTol .and. MudSystem%AnnulusFlowRate/=0.0d0) ) then ! new mud is pumped + ! call Ann_Density%AddTo (iLocMudSystem%St_Density%Last()) + ! call Ann_MudDischarged_Volume%AddTo (iLoc,0.0d0) + ! call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX) + ! call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection) + ! call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX) + ! call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection) + ! call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0) + ! call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0) + ! call Ann_MudOrKick%AddTo (iLoc,0) + ! call Ann_CuttingMud%AddTo (iLoc,0) + ! !write(*,*) 'c) annLength=' , Ann_Density%Length() + ! + ! AnnulusSuctionDensity_Old=MudSystem%St_Density%Last() + ! + ! MudIsChanged= .true. + ! endif + ! + ! Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+ ((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) !(gal) + ! + !endif + + + + + + + MudSystem%Ann_Mud_Backhead_section%Array(1)= MudSystem%MudSection !it is needed to be updated for a condition that one pipe is removed from Annulus due to trip out + MudSystem%Ann_Mud_Backhead_X%Array(1)= MudSystem%BackheadX + + + + ! write(*,*) 'zero)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:)) + ! + ! + !write(*,*) 'pump added-before add to ann==' + ! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + ! + !write(*,*) '====pump added-before add to ann' + + + +!========================Tripping In==================== + +!write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp + if (ROP_Bit%RateOfPenetration==0.) then ! .and. Op_MudOrKick%Last() == 0) then ! trip in mode(loole paeen) Mud + + !write(*,*) 'Tripping In' + !write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + !if ( MudIsChanged== .true. ) then + ! call RemoveAnnulusMudArrays(iLoc) + !endif + + + if (MudSystem%Op_Kick_Saved_Volume > 0.0 .and. MudSystem%Ann_MudOrKick%First() == 0) then + write(*,*) 'Kick influx enters Annulus' + call MudSystem%Ann_Density%AddToFirst (MudSystem%Op_KickSaved_Density) + call MudSystem%Ann_MudDischarged_Volume%AddToFirst (MudSystem%Op_Kick_Saved_Volume) + call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Forehead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Backhead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Ann_MudOrKick%AddToFirst (MudSystem%Saved_Op_MudOrKick) !<<<<<<<< + call MudSystem%Ann_CuttingMud%AddToFirst (0) + elseif (MudSystem%Op_Kick_Saved_Volume > 0.0 .and. MudSystem%Ann_MudOrKick%First() /= 0) then + MudSystem%Ann_MudDischarged_Volume%Array(1)= MudSystem%Ann_MudDischarged_Volume%Array(1) + MudSystem%Op_Kick_Saved_Volume + endif + + + if (MudSystem%Op_Saved_MudDischarged_Volume> 0.0) then + MudSystem%NewDensity= MudSystem%Op_MudSaved_Density + MudSystem%NewVolume= MudSystem%Op_Saved_MudDischarged_Volume + !write(*,*) 'NewVolume=' , NewVolume + !write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + + + if ((ROP_Bit%RateOfPenetration==0 .and. abs(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%NewDensity)< MudSystem%DensityMixTol) & + .or. (ROP_Bit%RateOfPenetration>0. .and. MudSystem%Ann_CuttingMud%Array(MudSystem%iLoc)==1 .and. abs(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%NewDensity)< MudSystem%CuttingDensityMixTol) & + .or. (ROP_Bit%RateOfPenetration>0. .and. MudSystem%Ann_CuttingMud%Array(MudSystem%iLoc)==0 .and. MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged + + MudSystem%Ann_Density%Array(MudSystem%iLoc)= (MudSystem%Ann_Density%Array(MudSystem%iLoc)*MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewVolume) + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewVolume + MudSystem%Ann_Mud_Forehead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_Mud_Backhead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Backhead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_RemainedVolume_in_LastSection%Array(MudSystem%iLoc)= (0.0d0) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(MudSystem%iLoc)= (0.0d0) + !write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + else ! 2-Merging conditions are not meeted, so new pocket + call MudSystem%Ann_Density%AddTo (MudSystem%iLoc,MudSystem%NewDensity) + call MudSystem%Ann_MudDischarged_Volume%AddTo (MudSystem%iLoc,MudSystem%NewVolume) + call MudSystem%Ann_Mud_Forehead_X%AddTo (MudSystem%iLoc,MudSystem%BackheadX) + call MudSystem%Ann_Mud_Forehead_section%AddTo (MudSystem%iLoc,MudSystem%MudSection) + call MudSystem%Ann_Mud_Backhead_X%AddTo (MudSystem%iLoc,MudSystem%BackheadX) + call MudSystem%Ann_Mud_Backhead_section%AddTo (MudSystem%iLoc,MudSystem%MudSection) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (MudSystem%iLoc,0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystem%iLoc,0.0d0) + call MudSystem%Ann_MudOrKick%AddTo (MudSystem%iLoc,0) + call MudSystem%Ann_CuttingMud%AddTo (MudSystem%iLoc,0) + !write(*,*) 'd) annLength=' , Ann_Density%Length() + !write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + endif + endif + + endif + +!========================Tripping In - End==================== + +!========================Drilling Mode======================== + + if (ROP_Bit%RateOfPenetration>0. .and. MudSystem%DeltaVolumeOp>0.0) then ! trip in mode(loole paeen) DrillingMode== .true. + !write(*,*) 'Drilling Mode' + + !if ( MudIsChanged== .true. ) then + ! call RemoveAnnulusMudArrays(iLoc) + !endif + !write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + + !MudSystem%NewDensity= MudSystem%St_Density%Last() * MudSystem%AnnulusFlowRate + 141.4296E-4*ROP_Bit%RateOfPenetration*ROP_Spec%DiameterOfBit**2)/(MudSystem%AnnulusFlowRate+6.7995E-4*ROP_Bit%RateOfPenetration*Diameter_of_Bit**2) + + MudSystem%NewDensity=MudSystem%St_Density%Last() + + + !NewVolume= ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)+DeltaVolumeOp + !!! Density in ppg, flow rate in gpm, ROP in ft/s, bit diameter in inch + + + do imud=1, MudSystem%Op_MudDischarged_Volume%Length() + if ( MudSystem%Op_MudOrKick%Array(imud) == 0 ) then + MudSystem%Op_Density%Array(imud)= MudSystem%NewDensity + + endif + enddo + + + + if (MudSystem%Op_Kick_Saved_Volume > 0.0 .and. MudSystem%Ann_MudOrKick%First() == 0) then + write(*,*) 'Kick influx enters Annulus first time' + !write(*,*) 'Saved_Op_MudOrKick=',Saved_Op_MudOrKick + call MudSystem%Ann_Density%AddToFirst (MudSystem%Op_KickSaved_Density) + call MudSystem%Ann_MudDischarged_Volume%AddToFirst (MudSystem%Op_Kick_Saved_Volume) + call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Forehead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Backhead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Ann_MudOrKick%AddToFirst (MudSystem%Saved_Op_MudOrKick) !<<<<<<<< + call MudSystem%Ann_CuttingMud%AddToFirst (0) + elseif (MudSystem%Op_Kick_Saved_Volume > 0.0 .and. MudSystem%Ann_MudOrKick%First() /= 0) then + MudSystem%Ann_MudDischarged_Volume%Array(1)= MudSystem%Ann_MudDischarged_Volume%Array(1) + MudSystem%Op_Kick_Saved_Volume + endif + + + if (MudSystem%Op_Saved_MudDischarged_Volume> 0.0) then + !write(*,*) 'Op_Saved_Mud added' + MudSystem%NewDensity= MudSystem%NewDensity !(drilling density) + MudSystem%NewVolume= MudSystem%Op_Saved_MudDischarged_Volume + MudSystem%DeltaVolumeOp ! (DeltaVolumeOp: for Cuttings Volume) + !write(*,*) 'NewVolume=' , NewVolume + !write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + if ( (MudSystem%Ann_CuttingMud%Array(MudSystem%iLoc)==1 .and. abs(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%NewDensity)< MudSystem%CuttingDensityMixTol ) & + .or. (MudSystem%Ann_CuttingMud%Array(MudSystem%iLoc)==0 .and. MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged + + MudSystem%Ann_Density%Array(MudSystem%iLoc)= (MudSystem%Ann_Density%Array(MudSystem%iLoc)*MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewVolume) + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewVolume + MudSystem%Ann_Mud_Forehead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_Mud_Backhead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Backhead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_RemainedVolume_in_LastSection%Array(MudSystem%iLoc)= (0.0d0) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(MudSystem%iLoc)= (0.0d0) + MudSystem%Ann_CuttingMud%Array(MudSystem%iLoc)= 1 + !write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + else ! 2-Merging conditions are not meeted, so new pocket + !write(*,*) 'before e) ', iloc, Ann_Density%Array(iLoc),MudSystem%NewDensity + !write(*,*) 'before e) Ann_MudDischarged_Volume%Array(iLoc)=' , Ann_MudDischarged_Volume%Array(iLoc) + + + 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,1) ! 1= cutting 0= mud + !write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + !write(*,*) 'e) annLength=' , Ann_Density%Length() + + + endif + + + endif + + endif +!=================================================================== + + !write(*,*) 'after add to ann==' + ! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + ! + !write(*,*) '==after add to ann' + + MudSystem%NewVolume= ((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) - MudSystem%Op_Saved_MudDischarged_Volume + + if (MudSystem%iLoc==2 .and. MudSystem%Op_MudOrKick%Last()==0 .and. MudSystem%NewVolume > 0.d0 ) then ! for avoid kick separation + !write(*,*) 'avoid kick separation' + + + MudSystem%NewDensity= MudSystem%Op_MudSaved_Density + + call RemoveOpMudArrays(MudSystem%Op_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann + if ( MudSystem%Ann_MudDischarged_Volume%Array(1) > ((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline)- MudSystem%Op_Saved_MudDischarged_Volume) then! 1st in Ann = kick + !write(*,*) 'mode1' + MudSystem%Ann_MudDischarged_Volume%Array(1)= MudSystem%Ann_MudDischarged_Volume%Array(1) - (((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) -MudSystem%Op_Saved_MudDischarged_Volume) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())+ (((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) - MudSystem%Op_Saved_MudDischarged_Volume) !kick + else + call RemoveAnnulusMudArrays(1) !kick is removed + MudSystem%iLoc= 1 + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())+ (((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) - MudSystem%Op_Saved_MudDischarged_Volume) + !write(*,*) 'mode2' + + ! including a little expand + endif + + + if ((ROP_Bit%RateOfPenetration==0 .and. abs(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%NewDensity)< MudSystem%DensityMixTol) & + .or. (ROP_Bit%RateOfPenetration>0. .and. MudSystem%Ann_CuttingMud%Array(MudSystem%iLoc)==1 .and. abs(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%NewDensity)< MudSystem%CuttingDensityMixTol) & + .or. (ROP_Bit%RateOfPenetration>0. .and. MudSystem%Ann_CuttingMud%Array(MudSystem%iLoc)==0 .and. MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged + + MudSystem%Ann_Density%Array(MudSystem%iLoc)= (MudSystem%Ann_Density%Array(MudSystem%iLoc)*MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewVolume) + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewVolume + MudSystem%Ann_Mud_Forehead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_Mud_Backhead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Backhead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_RemainedVolume_in_LastSection%Array(MudSystem%iLoc)= (0.0d0) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(MudSystem%iLoc)= (0.0d0) + else ! 2-Merging conditions are not meeted, so new pocket + call MudSystem%Ann_Density%AddTo (MudSystem%iLoc,MudSystem%NewDensity) + call MudSystem%Ann_MudDischarged_Volume%AddTo (MudSystem%iLoc,MudSystem%NewVolume) + call MudSystem%Ann_Mud_Forehead_X%AddTo (MudSystem%iLoc,MudSystem%BackheadX) + call MudSystem%Ann_Mud_Forehead_section%AddTo (MudSystem%iLoc,MudSystem%MudSection) + call MudSystem%Ann_Mud_Backhead_X%AddTo (MudSystem%iLoc,MudSystem%BackheadX) + call MudSystem%Ann_Mud_Backhead_section%AddTo (MudSystem%iLoc,MudSystem%MudSection) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (MudSystem%iLoc,0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystem%iLoc,0.0d0) + call MudSystem%Ann_MudOrKick%AddTo (MudSystem%iLoc,0) + call MudSystem%Ann_CuttingMud%AddTo (MudSystem%iLoc,0) + !write(*,*) 'd) annLength=' , Ann_Density%Length() + + endif + + + endif +!=================================================================== + if( MudSystem%Op_MudOrKick%Last() == 1 .and. MudSystem%Ann_MudOrKick%First() == 0 ) then + + write(*,*) '***error2****==' + + write(*,*) 'Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume=' , MudSystem%Op_Kick_Saved_Volume,MudSystem%Op_Saved_MudDischarged_Volume + + + write(*,*) 'after add to ann==' + + do imud=1, MudSystem%Op_MudDischarged_Volume%Length() + write(*,*) 'Op:', imud, MudSystem%Op_MudDischarged_Volume%Array(imud), MudSystem%Op_Density%Array(imud) ,MudSystem%Op_MudOrKick%Array(imud) + enddo + + do imud=1, MudSystem%Ann_MudDischarged_Volume%Length() + write(*,*) 'Ann:', imud, MudSystem%Ann_MudDischarged_Volume%Array(imud), MudSystem%Ann_Density%Array(imud) ,MudSystem%Ann_MudOrKick%Array(imud) + enddo + + write(*,*) '==after add to ann' + + write(*,*) 'NewVolume,Op_MudOrKick%Last=' , MudSystem%NewVolume,MudSystem%Op_MudOrKick%Last() + write(*,*) '==***error2****' + + endif + + + + + +!=============== save Ann Mud data to transfer to the ChokeLine enterance + MudSystem%AnnMudVolumeSum= 0.d0 + !Ann_MudSaved_Density= 0.d0 + !Ann_KickSaved_Density= 0.d0 + MudSystem%Ann_Saved_MudDischarged_Volume= 0.d0 + MudSystem%Ann_Kick_Saved_Volume= 0.d0 + MudSystem%Saved_Ann_MudOrKick= 0 + MudSystem%Ann_to_Choke_2mud= .false. + + + + + do imud=1, MudSystem%Ann_MudDischarged_Volume%Length() + + MudSystem%AnnMudVolumeSum= MudSystem%AnnMudVolumeSum + MudSystem%Ann_MudDischarged_Volume%Array(imud) + + if ( MudSystem%AnnMudVolumeSum > sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) ) then + + IF (MudSystem%Ann_MudOrKick%Array(imud) == 0) THEN + MudSystem%Ann_MudSaved_Density = MudSystem%Ann_Density%Array(imud) + MudSystem%Ann_Saved_MudDischarged_Volume = MudSystem%AnnMudVolumeSum - sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) + ELSEIF (MudSystem%Ann_MudOrKick%Array(imud) > 0 .AND. MudSystem%Ann_MudOrKick%Array(imud) <100) THEN ! 104= AIR + MudSystem%Ann_Kick_Saved_Volume = MudSystem%AnnMudVolumeSum - sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) + MudSystem%Saved_Ann_MudOrKick= MudSystem%Ann_MudOrKick%Array (imud) + MudSystem%Ann_KickSaved_Density= MudSystem%Ann_Density%Array(imud) + END IF + + do ii= imud + 1, MudSystem%Ann_MudDischarged_Volume%Length() + IF (MudSystem%Ann_MudOrKick%Array(ii) == 0) THEN + MudSystem%Ann_MudSaved_Density = ((MudSystem%Ann_MudSaved_Density * MudSystem%Ann_Saved_MudDischarged_Volume) + (MudSystem%Ann_Density%Array(ii) * MudSystem%Ann_MudDischarged_Volume%Array(ii))) / (MudSystem%Ann_Saved_MudDischarged_Volume + MudSystem%Ann_MudDischarged_Volume%Array(ii)) + MudSystem%Ann_Saved_MudDischarged_Volume = MudSystem%Ann_Saved_MudDischarged_Volume + MudSystem%Ann_MudDischarged_Volume%Array(ii) + MudSystem%Ann_to_Choke_2mud= .true. + ELSEIF (MudSystem%Ann_MudOrKick%Array(ii) > 0 .AND. MudSystem%Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR + MudSystem%Ann_Kick_Saved_Volume = MudSystem%Ann_Kick_Saved_Volume + MudSystem%Ann_MudDischarged_Volume%Array(ii) + MudSystem%Saved_Ann_MudOrKick= MudSystem%Ann_MudOrKick%Array (ii) + MudSystem%Ann_KickSaved_Density= MudSystem%Ann_Density%Array(ii) + END IF + enddo + + + !WRITE (*,*) 'Ann_Saved_Mud_Volume, Ann_Kick_Saved_Volume', Ann_Saved_MudDischarged_Volume, Ann_Kick_Saved_Volume + exit + + endif + + enddo +MudSystem%Ann_Saved_MudDischarged_Volume_Final= MudSystem%Ann_Saved_MudDischarged_Volume !+ Ann_Kick_Saved_Volume +MudSystem%Ann_Kick_Saved_Volume_Final= MudSystem%Ann_Kick_Saved_Volume +IF (MudSystem%WellHeadIsOpen) MudSystem%MudVolume_InjectedFromAnn = MudSystem%Ann_Saved_MudDischarged_Volume_Final -((MudSystem%Qlost/60.0d0)*MudSystem%DeltaT_Mudline) +!WRITE (*,*) 'MudSystem%MudVolume_InjectedFromAnn=', MudSystem%MudVolume_InjectedFromAnn +!====================================================================== + + !write(*,*) 'c)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:)) + !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + !write(*,*) 'Ann_Saved_Mud=' , Ann_Saved_MudDischarged_Volume + + MudSystem%total_injected = MudSystem%total_injected + MudSystem%MudVolume_InjectedFromAnn + + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + MudSystem%total_injected= 0. + endif + + !write(*,*) ' total injected-tripin =' , total_injected + !write(*,*) 'injected-tripin =' , MudSystem%MudVolume_InjectedFromAnn + + + + + +!======================== Annulus ==================== + + !MudIsChanged= .false. + +imud= 0 + + do while (imud < MudSystem%Ann_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%Ann_Mud_Backhead_X%Array(imud)= MudSystem%Ann_Mud_Forehead_X%Array(imud-1) + MudSystem%Ann_Mud_Backhead_section%Array(imud)= MudSystem%Ann_Mud_Forehead_section%Array(imud-1) + endif + + + +! <<< Fracture Shoe Lost + IF ( MudSystem%ShoeLost .and. Shoe%ShoeDepth < MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. Shoe%ShoeDepth >= MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then + !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)-((MudSystem%Qlost/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) + if (MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then + !write(*,*) 'mud is removed by shoe lost, imud=' , imud + call RemoveAnnulusMudArrays(imud) + imud= imud-1 + cycle + endif + + ENDIF +! Fracture Shoe Lost >>> + + + MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))- MudSystem%Ann_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( MudSystem%Ann_MudDischarged_Volume%Array(imud) <= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%Ann_Mud_Backhead_section%Array(imud) + MudSystem%Ann_Mud_Forehead_X%Array(imud)= MudSystem%Ann_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Backhead_section%Array(imud)) + ! 7.48 is for gal to ft^3 + + else + + MudSystem%isection= MudSystem%Ann_Mud_Backhead_section%Array(imud)+1 + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > MudSystem%NoPipeSections) then ! last pipe section(well exit) + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + MudSystem%Ann_Mud_Forehead_X%Array(imud)= MudSystem%Xend_PipeSection(MudSystem%NoPipeSections) + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%NoPipeSections + + if (MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + !write(*,*) 'remove******' + call RemoveAnnulusMudArrays(imud) + endif + exit + endif + + MudSystem%xx= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%Ann_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_PipeSection(MudSystem%isection)- MudSystem%Xstart_PipeSection(MudSystem%isection)))+ MudSystem%Xstart_PipeSection(MudSystem%isection) + exit + else + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + endif + + enddo + + endif +! write(*,*) 'imud=' , imud +!write(*,*) 'Pinter4 **Ann_Length()=' , Ann_Mud_Forehead_X%Length() +! write(*,*) 'Ann_Density%Array (imud)=' , Ann_Density%Array (imud) +! +! +!write(*,*) imud,'Ann_Mud_Forehead_X%Array(imud)=' , Ann_Mud_Forehead_X%Array(imud) + + !if (Ann_Mud_Forehead_X%Array(imud) < Xend_PipeSection(NoPipeSections)) then + ! Ann_Mud_Forehead_X%Array(imud) = Xend_PipeSection(NoPipeSections) ! for error preventing + !endif + + !write(*,*) imud, 'Ann_MudDischarged_Volume%Array(imud)=' , Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) + + + enddo + + if (MudSystem%Ann_Mud_Forehead_X%Last() < MudSystem%Xend_PipeSection(MudSystem%NoPipeSections)) then + MudSystem%Ann_Mud_Forehead_X%Array(MudSystem%Ann_Mud_Forehead_X%Length()) = MudSystem%Xend_PipeSection(MudSystem%NoPipeSections) ! for error preventing + endif + +!========================ANNULUS END================= + !write(*,*) 'sum(Ann_MudDischarged_Volume%Array())=' , sum(Ann_MudDischarged_Volume%Array(:)) + +!========================================================= + + + !write(*,*) 'before======2' + ! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + !write(*,*) '2======before' + + +!========================Bottom Hole================= +imud=0 + do while (imud < MudSystem%Op_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%Op_Mud_Backhead_X%Array(imud)= MudSystem%Op_Mud_Forehead_X%Array(imud-1) + MudSystem%Op_Mud_Backhead_section%Array(imud)= MudSystem%Op_Mud_Forehead_section%Array(imud-1) + endif + !write(*,*) 'imud**=' , imud + MudSystem%DirectionCoef= (MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))- MudSystem%Op_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + !write(*,*) ' Op_EmptyVolume_inBackheadLocation%Array(1) =' , Op_EmptyVolume_inBackheadLocation%Array(1) + if ( MudSystem%Op_EmptyVolume_inBackheadLocation%Array(1) < 0.0) CALL ErrorStop1 ('Negative Empty volume') + + 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 + + + MudSystem%isection= MudSystem%Op_Mud_Backhead_section%Array(imud)+1 + MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Op_MudDischarged_Volume%Array(imud)- MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > F_Counts%BottomHoleIntervalCounts) then ! last pipe section(well exit) + !if( imud==1) KickDeltaVinAnnulus= Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space + MudSystem%Op_MudDischarged_Volume%Array(imud)= MudSystem%Op_MudDischarged_Volume%Array(imud)- MudSystem%Op_RemainedVolume_in_LastSection%Array(imud) + MudSystem%Op_Mud_Forehead_X%Array(imud)= MudSystem%Xend_OpSection(F_Counts%BottomHoleIntervalCounts) + MudSystem%Op_Mud_Forehead_section%Array(imud)= F_Counts%BottomHoleIntervalCounts + + if (MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveOpMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%OpSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Op_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%Op_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_OpSection(MudSystem%isection)- MudSystem%Xstart_OpSection(MudSystem%isection)))+ MudSystem%Xstart_OpSection(MudSystem%isection) + exit + else + MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)- MudSystem%OpSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + endif + + enddo + + endif +! for OP remove: + + if (MudSystem%Op_Mud_Forehead_X%Array(imud)== MudSystem%Xend_OpSection(F_Counts%BottomHoleIntervalCounts)) then + MudSystem%totalLength = MudSystem%Op_MudDischarged_Volume%Length() + do while(imud < MudSystem%totalLength) + + !imud = imud + 1 + call RemoveOpMudArrays(MudSystem%totalLength) + MudSystem%totalLength = MudSystem%totalLength - 1 + + + enddo + + exit ! + + endif + + + + + !if (Op_Mud_Forehead_X%Array(imud)== Xend_OpSection(F_Counts%BottomHoleIntervalCounts)) then + ! totalLength = Op_MudDischarged_Volume%Length() + ! do while(imud <= totalLength) + ! + ! imud = imud + 1 + ! call RemoveOpMudArrays(imud) + ! totalLength = totalLength - 1 + ! + ! + ! enddo + ! + ! exit ! + ! + !endif + + enddo + + !write(*,*) 'OpSection_VolumeCapacity sum=' , sum(OpSection_VolumeCapacity(:)) + + + +!========================Bottom Hole END================= + + + !write(*,*) 'after sorting==' + ! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + ! + ! ! + ! !do imud=1, st_MudDischarged_Volume%Length() + ! ! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud) + ! !enddo + ! + !write(*,*) '==after sorting' + + + ! write(*,*) 'after sorting st==' + ! + ! do imud=1, st_MudDischarged_Volume%Length() + ! write(*,*) 'st-plot:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)MudSystem%St_Density%Array(imud) + ! enddo + ! + !write(*,*) '==after sorting st' + + + + + !write(*,*) '**Ann_Kick_Saved_Final,Mud_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,MudSystem%MudVolume_InjectedFromAnn + + end subroutine Pump_and_TripIn + + + + + + + + + + + + subroutine ChokeLineMud ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + !USE CHOKEVARIABLES + !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure + !use CManifolds + use CDrillWatchVariables + !use CHOKEVARIABLES + !use CChokeManifoldVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + use PressureDisplayVARIABLESModule + Use CError + Use , intrinsic :: IEEE_Arithmetic + + + implicit none + + integer i,ii,error_occured + + error_occured = 0 + + + + + !write(*,*) 'begining chokeline==' + !write(*,*) 'Ann last:', Ann_MudDischarged_Volume%Last(), Ann_Density%Last() ,Ann_MudOrKick%Last() + ! + !do imud=1, ChokeLine_MudDischarged_Volume%Length() + ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud) + !enddo + + + + !write(*,*) 'Ann_Kick_Saved_Volume_Final,MudSystem%MudVolume_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,MudSystem%MudVolume_InjectedFromAnn + + !write(*,*) 'begining chokeline==' + + + + + + + + MudSystem%ChokeLineFlowRate = MUD(4)%Q + !WRITE (*,*) 'MUD(4)%Q', MUD(4)%Q + + + if (MudSystem%NewPipeFilling == 0) then ! .or. UtubeFilling==0) then + MudSystem%ChokeLineFlowRate= 0. + endif + + + do imud=1, MudSystem%ChokeLine_MudDischarged_Volume%Length()-2 + if ( MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then + write(*,*) 'error_location is 1' + error_occured = 1 + endif + enddo + + + + ! + !do imud=1, st_MudDischarged_Volume%Length() + ! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud) + !enddo + + + !========================CHOKE LINE ENTRANCE================= + + !if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume-((Qlost/60.0d0)*DeltaT_Mudline) ) == 0.0 ) then + if ( MudSystem%Ann_Kick_Saved_Volume > 1.0e-5 .and. ( MudSystem%MudVolume_InjectedFromAnn ) <= 1.0e-5 ) then + + !WRITE (*,*) 'only kick enters to chokeline, Casing pressure = ', PressureGauges(2) + + if (MudSystem%ChokeLine_MudOrKick%First() == 0) then + call MudSystem%ChokeLine_Density%AddToFirst (MudSystem%Ann_KickSaved_Density) + call MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (0.d0) + call MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + call MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1) + call MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + call MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1) + call MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%ChokeLine_MudOrKick%AddToFirst (MudSystem%Saved_Ann_MudOrKick) + + MudSystem%ChokeLineDensity_Old= MudSystem%Ann_KickSaved_Density + + endif + + MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ MudSystem%Ann_Kick_Saved_Volume !(gal) + + endif + + + do imud=1, MudSystem%ChokeLine_MudDischarged_Volume%Length()-2 + if ( MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then + write(*,*) 'error_location is 2' + + error_occured = 1 + + endif + enddo + + + + !if ( Ann_Kick_Saved_Volume == 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 ) then + if ( MudSystem%Ann_Kick_Saved_Volume <= 1.0e-5 .and. MudSystem%MudVolume_InjectedFromAnn > 1.0e-5 ) then + + !WRITE (*,*) 'only mud enters to chokeline' + + + if ((MudSystem%Ann_to_Choke_2mud == .false. .and. ABS(MudSystem%ChokeLineDensity_Old - MudSystem%Ann_MudSaved_Density) >= MudSystem%DensityMixTol) .or. MudSystem%ChokeLine_MudOrKick%First() /= 0) then ! new mud is pumped + call MudSystem%ChokeLine_Density%AddToFirst (MudSystem%Ann_MudSaved_Density) + call MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (0.0d0) + call MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + call MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1) + call MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + call MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1) + call MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%ChokeLine_MudOrKick%AddToFirst (0) + + MudSystem%ChokeLineDensity_Old= MudSystem%Ann_MudSaved_Density + endif + + !ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal) + MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ (MudSystem%MudVolume_InjectedFromAnn) !(gal) + + + + endif + + + + do imud=1, MudSystem%ChokeLine_MudDischarged_Volume%Length()-2 + if ( MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then + write(*,*) 'error_location is 3' + error_occured = 1 + + endif + enddo + + + !if ( Ann_Kick_Saved_Volume > 0.0 .and. (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() /= 0 ) then + if ( MudSystem%Ann_Kick_Saved_Volume > 1.0e-5 .and. (MudSystem%MudVolume_InjectedFromAnn) > 1.0e-5 .and. MudSystem%ChokeLine_MudOrKick%First() /= 0 ) then + + WRITE (*,*) 'Kick Enters Choke line Last Time' + + MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ MudSystem%Ann_Kick_Saved_Volume !(gal) + + + + call MudSystem%ChokeLine_Density%AddToFirst (MudSystem%Ann_MudSaved_Density) + !call ChokeLine_MudDischarged_Volume%AddToFirst (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) + call MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (MudSystem%MudVolume_InjectedFromAnn) + call MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + call MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1) + call MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + call MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1) + call MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%ChokeLine_MudOrKick%AddToFirst (0) + + MudSystem%ChokeLineDensity_Old= MudSystem%Ann_MudSaved_Density + + + + + + !ELSE if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() == 0 ) then + ELSE if ( MudSystem%Ann_Kick_Saved_Volume > 1.0e-5 .and. ( MudSystem%MudVolume_InjectedFromAnn ) > 1.0e-5 .and. MudSystem%ChokeLine_MudOrKick%First() == 0 ) then + WRITE (*,*) 'Kick Enters Choke line First Time' + + + + !ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal) + MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ ( MudSystem%MudVolume_InjectedFromAnn ) !(gal) + + + + + call MudSystem%ChokeLine_Density%AddToFirst (MudSystem%Ann_KickSaved_Density) + call MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (MudSystem%Ann_Kick_Saved_Volume) + call MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + call MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1) + call MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + call MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1) + call MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%ChokeLine_MudOrKick%AddToFirst (MudSystem%Saved_Ann_MudOrKick) + + MudSystem%ChokeLineDensity_Old= MudSystem%Ann_KickSaved_Density + + + endif + + do imud=1, MudSystem%ChokeLine_MudDischarged_Volume%Length()-2 + if ( MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then + write(*,*) 'error_location is 4' + error_occured = 1 + + endif + enddo + + if (error_occured == 1) then + + do imud=1, MudSystem%ChokeLine_MudDischarged_Volume%Length() + write(*,*) 'ChokeLine:', imud, MudSystem%ChokeLine_Density%Array(imud) ,MudSystem%ChokeLine_MudOrKick%Array(imud) + enddo + + endif + + +!========================================================== + + ! + !write(*,*) 'after add chokeline==' + ! + ! do imud=1, ChokeLine_MudDischarged_Volume%Length() + ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud) + ! enddo + ! + !write(*,*) 'after add chokeline==' + ! + ! + + +!=============== save Choke Mud data========================== + MudSystem%ChokeMudVolumeSum= 0.d0 + !Ann_MudSaved_Density= 0.d0 + !Ann_KickSaved_Density= 0.d0 + MudSystem%Choke_Saved_MudDischarged_Volume= 0.d0 + MudSystem%Choke_Kick_Saved_Volume= 0.d0 + MudSystem%Saved_Choke_MudOrKick= 0 + + + + + do imud=1, MudSystem%ChokeLine_MudDischarged_Volume%Length() + + MudSystem%ChokeMudVolumeSum= MudSystem%ChokeMudVolumeSum + MudSystem%ChokeLine_MudDischarged_Volume%Array(imud) + + if ( MudSystem%ChokeMudVolumeSum > MudSystem%ChokeLine_VolumeCapacity ) then + + IF (MudSystem%ChokeLine_MudOrKick%Array(imud) == 0) THEN + MudSystem%Choke_MudSaved_Density = MudSystem%ChokeLine_Density%Array(imud) + MudSystem%Choke_Saved_MudDischarged_Volume = MudSystem%ChokeMudVolumeSum - MudSystem%ChokeLine_VolumeCapacity + ELSEIF (MudSystem%ChokeLine_MudOrKick%Array(imud) > 0 .AND. MudSystem%ChokeLine_MudOrKick%Array(imud) <100) THEN ! 104= AIR + MudSystem%Choke_Kick_Saved_Volume = MudSystem%ChokeMudVolumeSum - MudSystem%ChokeLine_VolumeCapacity + MudSystem%Saved_Choke_MudOrKick= MudSystem%ChokeLine_MudOrKick%Array (imud) + MudSystem%Choke_KickSaved_Density= MudSystem%ChokeLine_Density%Array(imud) + END IF + + do ii= imud + 1, MudSystem%ChokeLine_MudDischarged_Volume%Length() + + IF (MudSystem%ChokeLine_MudOrKick%Array(ii) == 0) THEN + MudSystem%Choke_MudSaved_Density = ((MudSystem%Choke_MudSaved_Density * MudSystem%Choke_Saved_MudDischarged_Volume) + (MudSystem%ChokeLine_Density%Array(ii) * MudSystem%ChokeLine_MudDischarged_Volume%Array(ii))) / (MudSystem%Choke_Saved_MudDischarged_Volume + MudSystem%ChokeLine_MudDischarged_Volume%Array(ii)) + MudSystem%Choke_Saved_MudDischarged_Volume = MudSystem%Choke_Saved_MudDischarged_Volume + MudSystem%ChokeLine_MudDischarged_Volume%Array(ii) + ELSEIF (MudSystem%ChokeLine_MudOrKick%Array(ii) > 0 .AND. MudSystem%ChokeLine_MudOrKick%Array(ii) <100) THEN ! 104= AIR + MudSystem%Choke_Kick_Saved_Volume = MudSystem%Choke_Kick_Saved_Volume + MudSystem%ChokeLine_MudDischarged_Volume%Array(ii) + MudSystem%Saved_Choke_MudOrKick= MudSystem%ChokeLine_MudOrKick%Array (ii) + MudSystem%Choke_KickSaved_Density= MudSystem%ChokeLine_Density%Array(ii) + END IF + enddo + + + !WRITE (*,*) 'Choke_Saved_Mud_Volume, Choke_Kick_Saved_Volume', Choke_Saved_MudDischarged_Volume, Choke_Kick_Saved_Volume + exit ! exits do + + endif + + enddo +MudSystem%Choke_Saved_MudDischarged_Volume_Final= MudSystem%Choke_Saved_MudDischarged_Volume !+ Choke_Kick_Saved_Volume +MudSystem%Choke_Kick_Saved_Volume_Final= MudSystem%Choke_Kick_Saved_Volume +!====================================================================== + + + ! + !do imud=1, ChokeLine_MudDischarged_Volume%Length() + ! write(*,*) 'a)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud) + !enddo + + + !write(*,*) 'choke_Mud sum=' , sum(ChokeLine_MudDischarged_Volume%Array(:)) + !write(*,*) 'choke_cap=' , ChokeLine_VolumeCapacity + !write(*,*) 'Choke_Saved_Mud=' , Choke_Saved_MudDischarged_Volume_Final + !write(*,*) 'Choke_Saved_Kick=' , Choke_Kick_Saved_Volume_Final + + + +!========================Choke Line================= + +imud=0 + do while (imud < MudSystem%ChokeLine_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%ChokeLine_Mud_Backhead_X%Array(imud)= MudSystem%ChokeLine_Mud_Forehead_X%Array(imud-1) + MudSystem%ChokeLine_Mud_Backhead_section%Array(imud)= MudSystem%ChokeLine_Mud_Forehead_section%Array(imud-1) + endif + + + !DirectionCoef= (Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud))) & + ! / ABS(Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)= (BopStackSpecification%ChokeLineLength- MudSystem%ChokeLine_Mud_Backhead_X%Array(imud))* MudSystem%Area_ChokeLineFt !(ft^3) + + MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + if ( MudSystem%ChokeLine_MudDischarged_Volume%Array(imud) <= MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%ChokeLine_Mud_Forehead_section%Array(imud)= MudSystem%ChokeLine_Mud_Backhead_section%Array(imud) + MudSystem%ChokeLine_Mud_Forehead_X%Array(imud)= MudSystem%ChokeLine_Mud_Backhead_X%Array(imud)+ (MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_ChokeLineFt + ! 7.48 is for gal to ft^3 + + else + + MudSystem%isection= MudSystem%ChokeLine_Mud_Backhead_section%Array(imud)+1 + MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)= MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)- MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > 1) then ! last pipe section(Chokeline exit) + MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)= MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)- MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud) + MudSystem%ChokeLine_Mud_Forehead_X%Array(imud)= BopStackSpecification%ChokeLineLength + MudSystem%ChokeLine_Mud_Forehead_section%Array(imud)= 1 + if (MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call MudSystem%ChokeLine_MudDischarged_Volume%Remove (imud) + call MudSystem%ChokeLine_Mud_Backhead_X%Remove (imud) + call MudSystem%ChokeLine_Mud_Backhead_section%Remove (imud) + call MudSystem%ChokeLine_Mud_Forehead_X%Remove (imud) + call MudSystem%ChokeLine_Mud_Forehead_section%Remove (imud) + call MudSystem%ChokeLine_Density%Remove (imud) + call MudSystem%ChokeLine_RemainedVolume_in_LastSection%Remove (imud) + call MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Remove (imud) + call MudSystem%ChokeLine_MudOrKick%Remove (imud) + + endif + exit + endif + + MudSystem%xx= MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%ChokeLine_VolumeCapacity !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%ChokeLine_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%ChokeLine_Mud_Forehead_X%Array(imud)= MudSystem%xx * BopStackSpecification%ChokeLineLength + exit + else + MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)= MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)- MudSystem%ChokeLine_VolumeCapacity + MudSystem%isection= MudSystem%isection+ 1 + + + endif + + enddo + + endif + + enddo +!========================Choke Line END================= + + !do imud=1, ChokeLine_MudDischarged_Volume%Length() + ! write(*,*) 'b)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud) + !enddo + + MudSystem%ChokeOutletDensity= MudSystem%ChokeLine_Density%Last() ! used in MudSystem + + + + + + do i=1, MudSystem%ChokeLine_MudOrKick%Length() + !write(*,555) i,'Choke_Volume(i), type=' ,ChokeLine_MudDischarged_Volume%Array(i),ChokeLine_MudOrKick%Array(i) + + IF (IEEE_Is_NaN(MudSystem%ChokeLine_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in Choke Volume-Plot') + IF (MudSystem%ChokeLine_MudDischarged_Volume%Array(i)<=0.) call ErrorStop('Choke Volume= <=0' , MudSystem%ChokeLine_MudDischarged_Volume%Array(i)) + enddo + +555 FORMAT(I3,5X,A42,(f12.5),5X,I3) + + + !write(*,*) 'after sorting chokeline==' + !IF (ANY(ChokeLine_MudOrKick%Array(:) > 0)) THEN + ! do imud=1, ChokeLine_MudDischarged_Volume%Length() + ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud) + ! enddo + !END IF + + + !do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + !enddo + ! + !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + + + !write(*,*) '==after sorting chokeline' + + + end subroutine ChokeLineMud + + + + + +subroutine Choke_GasSound ! is called in subroutine CirculationCodeSelect + + +use CSounds + !Use GeoElements_FluidModule + !USE CMudPropertiesVariables + USE MudSystemVARIABLES + !USE Pumps_VARIABLES + !!USE CHOKEVARIABLES + !!USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure + !!use CManifolds + !use CDrillWatchVariables + !!use CHOKEVARIABLES + !!use CChokeManifoldVariables + !use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity + !USE sROP_Other_Variables + !USE sROP_Variables + !use KickVARIABLESModule + !use PressureDisplayVARIABLESModule + !Use CError + !Use , intrinsic :: IEEE_Arithmetic + + + + + + if ( MudSystem%ChokeLine_MudOrKick%Last() > 0 .AND. MudSystem%WellToChokeManifoldOpen == .true.) then + !WellToChokeManifoldWasOpen + + MudSystem%SoundGasThroughChoke = 100 !100:chon dar adadhaye kamtar az 100 seda ghaat mishavad. eslah shavad.5.8.98 !int (min(ChokeLineFlowRate/2. , 100.)) + print* , 'SoundGasThroughChoke1=', MudSystem%SoundGasThroughChoke + !WRITE (*,*) 'WellToChokeManifoldWasOpen-Sound', WellToChokeManifoldWasOpen + WRITE (*,*) 'WellToChokeManifoldOpen', MudSystem%WellToChokeManifoldOpen + else + MudSystem%SoundGasThroughChoke = 0 + print* , 'SoundGasThroughChoke2=', MudSystem%SoundGasThroughChoke + endif + !print* , 'SoundGasThroughChoke3=', SoundGasThroughChoke + + + + call SetSoundGasThroughChoke(MudSystem%SoundGasThroughChoke) + + + end subroutine Choke_GasSound \ No newline at end of file diff --git a/Equipments/MudSystem-old/Trip_Out_andPump.f90 b/Equipments/MudSystem-old/Trip_Out_andPump.f90 new file mode 100644 index 0000000..8e2b422 --- /dev/null +++ b/Equipments/MudSystem-old/Trip_Out_andPump.f90 @@ -0,0 +1,1364 @@ +subroutine TripOut_and_Pump ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + !USE CHOKEVARIABLES + !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure + !use CManifolds + use CDrillWatchVariables + !use CHOKEVARIABLES + !use CChokeManifoldVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + Use CShoeVariables + use CError + + implicit none + +integer i,ii,AddLocation, iloc_edited, iloc_changedTo2 +Real(8) ExcessMudVolume_Remained,SavedDensityForOp + +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + + MudSystem%StringFlowRate= MUD(2)%Q + MudSystem%AnnulusFlowRate= MUD(2)%Q + !write(*,*) 'MUD(2)%Q=====' , MUD(2)%Q + + + write(*,*) 'Trip Out' + + ! write(*,*) 'check point 1==' + ! + ! + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + ! + ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + ! + ! + !write(*,*) '==check point 1' + +!========================Horizontal PIPE ENTRANCE================= + + if (ABS(MudSystem%SuctionDensity_Old - MudSystem%Suction_Density_MudSystem) >= MudSystem%DensityMixTol) then ! new mud is pumped + + call MudSystem%Hz_Density%AddToFirst (MudSystem%Suction_Density_MudSystem) + call MudSystem%Hz_MudDischarged_Volume%AddToFirst (0.0d0) + call MudSystem%Hz_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(1)) + call MudSystem%Hz_Mud_Forehead_section%AddToFirst (1) + call MudSystem%Hz_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(1)) + call MudSystem%Hz_Mud_Backhead_section%AddToFirst (1) + call MudSystem%Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Hz_MudOrKick%AddToFirst (0) + + MudSystem%SuctionDensity_Old= MudSystem%Suction_Density_MudSystem + endif + +!========================Horizontal PIPE STRING================= + + MudSystem%Hz_MudDischarged_Volume%Array(1)= MudSystem%Hz_MudDischarged_Volume%Array(1)+ ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) + + + MudSystem%total_add = MudSystem%total_add + ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) + + + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + MudSystem%total_add= 0. + endif + + !write(*,*) ' total decrease(add to HZ)=' , total_add + !write(*,*) ' add to HZ=' , ((MudSystem%StringFlowRate/60.0d0)*DeltaT_Mudline) + + + +imud=0 + do while (imud < MudSystem%Hz_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%Hz_Mud_Backhead_X%Array(imud)= MudSystem%Hz_Mud_Forehead_X%Array(imud-1) + MudSystem%Hz_Mud_Backhead_section%Array(imud)= MudSystem%Hz_Mud_Forehead_section%Array(imud-1) + endif + + + MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_PipeSection(MudSystem%Hz_Mud_Backhead_section%Array(imud))- MudSystem%Hz_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_PipeSectionFt(MudSystem%Hz_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( MudSystem%Hz_MudDischarged_Volume%Array(imud) <= MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Hz_Mud_Forehead_section%Array(imud)= MudSystem%Hz_Mud_Backhead_section%Array(imud) + MudSystem%Hz_Mud_Forehead_X%Array(imud)= MudSystem%Hz_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%Hz_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%Hz_Mud_Backhead_section%Array(imud)) + + else + + + MudSystem%isection= MudSystem%Hz_Mud_Backhead_section%Array(imud)+1 + MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Hz_MudDischarged_Volume%Array(imud)- MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > 1) then ! (horizontal pipe exit) + MudSystem%Hz_MudDischarged_Volume%Array(imud)= MudSystem%Hz_MudDischarged_Volume%Array(imud)- MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud) + MudSystem%Hz_Mud_Forehead_X%Array(imud)= MudSystem%Xend_PipeSection(1) + MudSystem%Hz_Mud_Forehead_section%Array(imud)= 1 + + if (MudSystem%Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveHzMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Hz_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%Hz_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_PipeSection(MudSystem%isection)- MudSystem%Xstart_PipeSection(MudSystem%isection)))+ MudSystem%Xstart_PipeSection(MudSystem%isection) + exit + else + MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo +!========================Horizontal PIPE END================= + + + +!========================Utube1 Air Element Removing================= + + !if (UtubeMode1Activated== .true.) then ! StringUpdate == .true. + ! + ! StringDensity_Old= MudSystem%St_Density%Array(2) + ! + ! UtubeMode1Activated= .false. + !endif + +!========================Utube1 Air Element Removing================= + + +!========================Utube2 Removing from Annulus================= + + if (MudSystem%UtubeMode2Activated== .true.) then ! StringUpdate == .true. + MudSystem%TotalAddedVolume=0. + + if (MudSystem%Ann_MudOrKick%Last() == 104) then !movaghati. albate age merge anjam shode bashe moshkeli nist + call RemoveAnnulusMudArrays(MudSystem%Ann_MudOrKick%Length()) + endif + + MudSystem%UtubeMode2Activated= .false. + endif + + +!========================Utube2 Removing from Annulus End================= + +!========================New Pipe Filling================= + + if (MudSystem%AddedElementsToString > 0) then ! StringUpdate == .true. + + !NoPipeAdded= F_StringIntervalCounts - F_StringIntervalCountsOld + + + MudSystem%NewPipeFilling=0 + + IF (MudSystem%St_MudOrKick%First() == 104) then + MudSystem%St_MudDischarged_Volume%Array(1) = MudSystem%St_MudDischarged_Volume%Array(1) + sum(MudSystem%PipeSection_VolumeCapacity(2:1+MudSystem%AddedElementsToString)) ! new pipe is filled by air + else + call MudSystem%St_Density%AddToFirst (0.d0) + call MudSystem%St_MudDischarged_Volume%AddToFirst (sum(MudSystem%PipeSection_VolumeCapacity(2:1+MudSystem%AddedElementsToString))) + call MudSystem%St_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Forehead_section%AddToFirst (2) + call MudSystem%St_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.d0) + call MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.d0) + call MudSystem%St_MudOrKick%AddToFirst (104) + endif + + endif + + !F_StringIntervalCountsOld= F_StringIntervalCounts + + + + if (MudSystem%NewPipeFilling == 0) then ! 2= is the first element of string (1= is for Hz pipe) + + + MudSystem%LackageMudVolume= MudSystem%St_MudDischarged_Volume%Array(1) ! = Air element + + + !write(*,*) 'LackageMudVolume=' , LackageMudVolume + + + + if (ABS(MudSystem%St_Density%Array(2) - MudSystem%Hz_Density%Last()) >= MudSystem%DensityMixTol) then ! new mud is pumped + call MudSystem%St_Density%AddTo (2,MudSystem%Hz_Density%Last()) + call MudSystem%St_MudDischarged_Volume%AddTo (2,0.d0) + call MudSystem%St_Mud_Forehead_X%AddTo (2,MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Forehead_section%AddTo (2 , 2) + call MudSystem%St_Mud_Backhead_X%AddTo (2,MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Backhead_section%AddTo (2 ,2) + call MudSystem%St_RemainedVolume_in_LastSection%AddTo (2,0.d0) + call MudSystem%St_EmptyVolume_inBackheadLocation%AddTo (2,0.d0) + call MudSystem%St_MudOrKick%AddTo (2,0) + + !StringDensity_Old= Hz_Density%Last() + endif + + + MudSystem%St_MudDischarged_Volume%Array(2)= MudSystem%St_MudDischarged_Volume%Array(2)+ min( ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline), MudSystem%LackageMudVolume) !(gal) + + MudSystem%St_MudDischarged_Volume%Array(1)= MudSystem%St_MudDischarged_Volume%Array(1)- min( ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline), MudSystem%LackageMudVolume) ! air(gal) + + !LackageMudVolumeAfterFilling= sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts)) - sum(St_MudDischarged_Volume%Array(:)) + + MudSystem%LackageMudVolumeAfterFilling= MudSystem%St_MudDischarged_Volume%Array(1) ! last time it should be zero + + + + if (MudSystem%LackageMudVolumeAfterFilling == 0.) then + MudSystem%NewPipeFilling= 1 + call RemoveStringMudArrays(1) + MudSystem%St_Mud_Backhead_X%Array(1) = MudSystem%Xstart_PipeSection(2) + MudSystem%St_Mud_Backhead_section%Array(1) = 2 + endif + + endif + +!========================New Pipe Filling End================= + + + if (MudSystem%NewPipeFilling == 0) then + MudSystem%StringFlowRate= 0. + MudSystem%AnnulusFlowRate= 0. + endif + + MudSystem%StringFlowRateFinal= MudSystem%StringFlowRate + MudSystem%AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate + + +!========================STRING ENTRANCE================= + if (MudSystem%StringFlowRateFinal > 0.0 .and. ABS(MudSystem%St_Density%First() - MudSystem%Hz_Density%Last()) >= MudSystem%DensityMixTol) then ! new mud is pumped + !if (ABS(StringDensity_Old - Hz_Density%Last()) >= DensityMixTol) then ! new mud is pumped + call MudSystem%St_Density%AddToFirst (MudSystem%Hz_Density%Last()) + call MudSystem%St_MudDischarged_Volume%AddToFirst (0.0d0) + call MudSystem%St_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Forehead_section%AddToFirst (2) + call MudSystem%St_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(2)) + call MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%St_MudOrKick%AddToFirst (0) + + !StringDensity_Old= Hz_Density%Last() + endif + MudSystem%St_MudDischarged_Volume%Array(1)= MudSystem%St_MudDischarged_Volume%Array(1)+ ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) + +!=============== save String Mud data=========== + MudSystem%StMudVolumeSum= 0.d0 + !St_MudSaved_Density= 0.d0 + MudSystem%St_Saved_MudDischarged_Volume= 0.d0 + !Saved_St_MudOrKick= 0 + !Ann_to_Choke_2mud= .false. + + do imud=1, MudSystem%St_MudDischarged_Volume%Length() + MudSystem%StMudVolumeSum= MudSystem%StMudVolumeSum + MudSystem%St_MudDischarged_Volume%Array(imud) + if ( MudSystem%StMudVolumeSum > sum(MudSystem%PipeSection_VolumeCapacity(2:F_Counts%StringIntervalCounts)) ) then + !IF (St_MudOrKick%Array(imud) == 0) THEN + MudSystem%St_MudSaved_Density = MudSystem%St_Density%Array(imud) + MudSystem%St_Saved_MudDischarged_Volume = MudSystem%StMudVolumeSum - sum(MudSystem%PipeSection_VolumeCapacity(2:F_Counts%StringIntervalCounts)) + !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR + ! St_Kick_Saved_Volume = StMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! Saved_St_MudOrKick= St_MudOrKick%Array (imud) + ! St_KickSaved_Density= MudSystem%St_Density%Array(imud) + !END IF + + do ii= imud + 1, MudSystem%St_MudDischarged_Volume%Length() + !IF (St_MudOrKick%Array(ii) == 0) THEN + MudSystem%St_MudSaved_Density = ((MudSystem%St_MudSaved_Density * MudSystem%St_Saved_MudDischarged_Volume) + (MudSystem%St_Density%Array(ii) * MudSystem%St_MudDischarged_Volume%Array(ii))) / (MudSystem%St_Saved_MudDischarged_Volume + MudSystem%St_MudDischarged_Volume%Array(ii)) + MudSystem%St_Saved_MudDischarged_Volume = MudSystem%St_Saved_MudDischarged_Volume + MudSystem%St_MudDischarged_Volume%Array(ii) + + !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR + ! St_Kick_Saved_Volume = St_Kick_Saved_Volume + St_MudDischarged_Volume%Array(ii) + ! Saved_St_MudOrKick= St_MudOrKick%Array (ii) + ! St_KickSaved_Density= MudSystem%St_Density%Array(ii) + !END IF + enddo + + + !WRITE (*,*) 'St_Saved_Mud_Volume, St_Kick_Saved_Volume', St_Saved_MudDischarged_Volume, St_Kick_Saved_Volume + exit ! exits do + + endif + + enddo +MudSystem%St_Saved_MudDischarged_Volume_Final= MudSystem%St_Saved_MudDischarged_Volume + +IF (MudSystem%WellHeadIsOpen) MudSystem%MudVolume_InjectedToBH = MudSystem%St_Saved_MudDischarged_Volume_Final + +!====================================================================== + + +!========================STRING================= + +imud=0 + do while (imud < MudSystem%St_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%St_Mud_Backhead_X%Array(imud)= MudSystem%St_Mud_Forehead_X%Array(imud-1) + MudSystem%St_Mud_Backhead_section%Array(imud)= MudSystem%St_Mud_Forehead_section%Array(imud-1) + endif + + MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))- MudSystem%St_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_PipeSectionFt(MudSystem%St_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + if ( MudSystem%St_MudDischarged_Volume%Array(imud) <= MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%St_Mud_Forehead_section%Array(imud)= MudSystem%St_Mud_Backhead_section%Array(imud) + MudSystem%St_Mud_Forehead_X%Array(imud)= MudSystem%St_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%St_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%St_Mud_Backhead_section%Array(imud)) + ! 7.48 is for gal to ft^3 + + else + + MudSystem%isection= MudSystem%St_Mud_Backhead_section%Array(imud)+1 + MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= MudSystem%St_MudDischarged_Volume%Array(imud)- MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > F_Counts%StringIntervalCounts) then ! last pipe section(string exit) + MudSystem%St_MudDischarged_Volume%Array(imud)= MudSystem%St_MudDischarged_Volume%Array(imud)- MudSystem%St_RemainedVolume_in_LastSection%Array(imud) + MudSystem%St_Mud_Forehead_X%Array(imud)= MudSystem%Xend_PipeSection(F_Counts%StringIntervalCounts) + MudSystem%St_Mud_Forehead_section%Array(imud)= F_Counts%StringIntervalCounts + + if (MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveStringMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%St_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%St_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_PipeSection(MudSystem%isection)- MudSystem%Xstart_PipeSection(MudSystem%isection)))+ MudSystem%Xstart_PipeSection(MudSystem%isection) + exit + else + MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + + endif + + enddo + + endif + + enddo +!========================STRING END================= + + !write(*,*) ' a before==' + ! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + ! + ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + ! + ! + !write(*,*) '==== a before' + + iloc_changedTo2 = 0 + + IF (MudSystem%Op_MudOrKick%Last() /= 0 .and. MudSystem%Op_MudOrKick%Last()==MudSystem%Ann_MudOrKick%First()) then + MudSystem%iLoc=2 ! it may be 1,2,3 or more, all of them are kick + iloc_changedTo2= 1 + endif + + + + iloc_edited= 0 + !write(*,*) sum(Op_MudDischarged_Volume%Array(:)) , ((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) , Ann_MudDischarged_Volume%First() , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) + if (MudSystem%iLoc==2 .and. sum(MudSystem%Op_MudDischarged_Volume%Array(:))+((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline)+MudSystem%Ann_MudDischarged_Volume%First() < sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) ) then + MudSystem%iLoc = 1 + iloc_edited = 1 + !write(*,*) 'hellooooooo' + endif + + +!write(*,*) 'ann-cap:' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1 :F_StringIntervalCounts+F_AnnulusIntervalCounts) ) + + + !write(*,*) 'iloc====' , iloc + !MudVolume_InjectedToBH + + +!=============================Add PumpFlowRate to Bottom Hole ============================== + !if ( MudSystem%AnnulusFlowRate>0.0 ) then + if ( MudSystem%MudVolume_InjectedToBH > 0.0 ) then + + + if (KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the + AddLocation= MudSystem%Op_Density%Length()-MudSystem%iLoc+1+1 ! well, thus pumped mud should be placed above the kick + else + AddLocation= MudSystem%Op_Density%Length()+1 + endif + !write(*,*) 'AddLocation====' , AddLocation + if ( AddLocation== 0) CALL ErrorStop ('AddLocation=0') + + + if ( ABS(MudSystem%St_Density%Last() - MudSystem%Op_Density%Array(AddLocation-1)) >= MudSystem%DensityMixTol ) then + !write(*,*) 'new pocket**' + !write(*,*) 'MudSystem%St_Density%Last()=' , MudSystem%St_Density%Last() + !write(*,*) 'Op_Density%Array(AddLocation-1)=' , Op_Density%Array(AddLocation-1) + + + call MudSystem%Op_Density% AddTo (AddLocation,MudSystem%St_Density%Last()) + !call Op_MudDischarged_Volume%AddTo (AddLocation,((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)) + call MudSystem%Op_MudDischarged_Volume%AddTo (AddLocation,MudSystem%MudVolume_InjectedToBH) + call MudSystem%Op_Mud_Forehead_X%AddTo (AddLocation,MudSystem%Xstart_OpSection(1)) + call MudSystem%Op_Mud_Forehead_section%AddTo (AddLocation,1) + call MudSystem%Op_Mud_Backhead_X%AddTo (AddLocation,MudSystem%Xstart_OpSection(1)) + call MudSystem%Op_Mud_Backhead_section%AddTo (AddLocation,1) + call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (AddLocation,0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (AddLocation,0.0d0) + call MudSystem%Op_MudOrKick%AddTo (AddLocation,0) + else + !write(*,*) 'merge**' + !write(*,*) 'density before=' , Op_Density%Array(AddLocation-1) + !write(*,*) 'MudSystem%St_Density%Last() for mix=' , MudSystem%St_Density%Last() + + !Op_Density%Array(AddLocation-1)= (Op_Density%Array(AddLocation-1)*Op_MudDischarged_Volume%Array(AddLocation-1)+MudSystem%St_Density%Last()*((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline))/(Op_MudDischarged_Volume%Array(AddLocation-1)+((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)) + !Op_MudDischarged_Volume%Array(AddLocation-1)= Op_MudDischarged_Volume%Array(AddLocation-1) + ((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) + + MudSystem%Op_Density%Array(AddLocation-1)= (MudSystem%Op_Density%Array(AddLocation-1)*MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+MudSystem%St_Density%Last()*MudSystem%MudVolume_InjectedToBH)/(MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+MudSystem%MudVolume_InjectedToBH) + MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)= MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1) + MudSystem%MudVolume_InjectedToBH + !write(*,*) 'density after=' , Op_Density%Array(AddLocation-1) + + endif + + endif +!=======================Add PumpFlowRate to Bottom Hole- End ============================== + + !write(*,*) 'pump added-before add to ann==' + ! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + ! + ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + ! + ! + ! + !write(*,*) 'pump added====before add to ann' + + +!=============== save OP Mud data to transfer to the annulus enterance due to tripin or kick + MudSystem%OpMudVolumeSum= 0.d0 + !Op_MudSaved_Density= 0.d0 + !Op_KickSaved_Density= 0.d0 + MudSystem%Op_Saved_MudDischarged_Volume= 0.d0 + MudSystem%Op_Kick_Saved_Volume= 0.d0 + MudSystem%Saved_Op_MudOrKick= 0 + MudSystem%Op_NeededVolume_ToFill= 0.d0 + + + + + do imud=1, MudSystem%Op_MudDischarged_Volume%Length() + + MudSystem%OpMudVolumeSum= MudSystem%OpMudVolumeSum + MudSystem%Op_MudDischarged_Volume%Array(imud) + + if ( MudSystem%OpMudVolumeSum > sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) ) then !1st mode + + IF (MudSystem%Op_MudOrKick%Array(imud) == 0) THEN + MudSystem%Op_MudSaved_Density = MudSystem%Op_Density%Array(imud) + MudSystem%Op_Saved_MudDischarged_Volume = MudSystem%OpMudVolumeSum - sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) + ELSE + + MudSystem%Op_Kick_Saved_Volume = MudSystem%OpMudVolumeSum - sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) + MudSystem%Saved_Op_MudOrKick= MudSystem%Op_MudOrKick%Array (imud) + MudSystem%Op_KickSaved_Density= MudSystem%Op_Density%Array(imud) + MudSystem%iLoc= 2 + iloc_changedTo2= 2 + END IF + + do ii= imud + 1, MudSystem%Op_MudDischarged_Volume%Length() + IF (MudSystem%Op_MudOrKick%Array(ii) == 0) THEN + MudSystem%Op_MudSaved_Density = ((MudSystem%Op_MudSaved_Density * MudSystem%Op_Saved_MudDischarged_Volume) + (MudSystem%Op_Density%Array(ii) * MudSystem%Op_MudDischarged_Volume%Array(ii))) / (MudSystem%Op_Saved_MudDischarged_Volume + MudSystem%Op_MudDischarged_Volume%Array(ii)) + MudSystem%Op_Saved_MudDischarged_Volume = MudSystem%Op_Saved_MudDischarged_Volume + MudSystem%Op_MudDischarged_Volume%Array(ii) + ELSE + MudSystem%Op_Kick_Saved_Volume = MudSystem%Op_Kick_Saved_Volume + MudSystem%Op_MudDischarged_Volume%Array(ii) + MudSystem%Saved_Op_MudOrKick= MudSystem%Op_MudOrKick%Array (ii) + MudSystem%Op_KickSaved_Density= MudSystem%Op_Density%Array(ii) + MudSystem%iLoc= 2 + iloc_changedTo2= 3 + END IF + enddo + + exit ! exits do + + endif + + enddo + + if ( sum(MudSystem%Op_MudDischarged_Volume%Array(:)) < sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) ) then !2nd & 3rd mode + + MudSystem%Op_NeededVolume_ToFill= sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) - sum(MudSystem%Op_MudDischarged_Volume%Array(:)) + endif + + + ! + !write(*,*) 'Op_NeededVolume_ToFill=' , Op_NeededVolume_ToFill + !write(*,*) 'Op_Saved_MudDischarged_Volume=' , Op_Saved_MudDischarged_Volume + !write(*,*) 'Op_Kick_Saved_Volume=' , Op_Kick_Saved_Volume + ! + !write(*,*) 'op cap=' , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) + !write(*,*) ' op sum mud=' , sum(Op_MudDischarged_Volume%Array(:)) + + + + + +!====================================================================== + + + + +!========================Tripping Out- 1st & 3rd Mode==================== + + + + if ( (MudSystem%Op_Kick_Saved_Volume > 0.0 .or. MudSystem%Op_Saved_MudDischarged_Volume> 0.0) .or. & ! 1st Mode-Pump flow is more than trip out so fluid Level in Annulus Increases + (MudSystem%Op_NeededVolume_ToFill < ABS(MudSystem%DeltaVolumeAnnulusCapacity)) ) then !3rd Mode-fluid Level in Annulus Increases + + + !if ( Op_Kick_Saved_Volume > 0.0 .or. Op_Saved_MudDischarged_Volume> 0.0 ) write(*,*) 'trip out 1st mode' + + if ( MudSystem%Op_NeededVolume_ToFill > 0.0 .and. MudSystem%Op_NeededVolume_ToFill < ABS(MudSystem%DeltaVolumeAnnulusCapacity) ) then + ! write(*,*) 'trip out 3rd mode' + + MudSystem%NewVolume= 0.d0 ! for condition iloc=1 + + SavedDensityForOp= MudSystem%Ann_Density%Array(1) + + ExcessMudVolume_Remained= MudSystem%Op_NeededVolume_ToFill + + + imud=1 + + Do + + if(MudSystem%Ann_MudDischarged_Volume%Array(imud) < ExcessMudVolume_Remained) then + ExcessMudVolume_Remained= ExcessMudVolume_Remained- MudSystem%Ann_MudDischarged_Volume%Array(imud) + call MudSystem%Ann_MudDischarged_Volume%Remove (imud) + call MudSystem%Ann_Mud_Backhead_X%Remove (imud) + call MudSystem%Ann_Mud_Backhead_section%Remove (imud) + call MudSystem%Ann_Mud_Forehead_X%Remove (imud) + call MudSystem%Ann_Mud_Forehead_section%Remove (imud) + call MudSystem%Ann_Density%Remove (imud) + call MudSystem%Ann_RemainedVolume_in_LastSection%Remove (imud) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (imud) + call MudSystem%Ann_MudOrKick%Remove (imud) + + elseif(MudSystem%Ann_MudDischarged_Volume%Array(imud) > ExcessMudVolume_Remained) then + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- ExcessMudVolume_Remained + exit + + else !(Ann_MudDischarged_Volume%Array(imud) == ExcessMudVolume_Remained) + call MudSystem%Ann_MudDischarged_Volume%Remove (imud) + call MudSystem%Ann_Mud_Backhead_X%Remove (imud) + call MudSystem%Ann_Mud_Backhead_section%Remove (imud) + call MudSystem%Ann_Mud_Forehead_X%Remove (imud) + call MudSystem%Ann_Mud_Forehead_section%Remove (imud) + call MudSystem%Ann_Density%Remove (imud) + call MudSystem%Ann_RemainedVolume_in_LastSection%Remove (imud) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (imud) + call MudSystem%Ann_MudOrKick%Remove (imud) + exit + + endif + + enddo + + + !write(*,*) 'Op_NeededVolume_ToFill=' ,Op_NeededVolume_ToFill + !write(*,*) 'ABS(DeltaVolumeAnnulusCapacity)=' ,ABS(DeltaVolumeAnnulusCapacity) + !write(*,*) 'Op_MudOrKick%Last()=' ,Op_MudOrKick%Last() + !write(*,*) 'iloc=' ,iloc + !write(*,*) 'iloc_edited=' ,iloc_edited + + + endif + + + ! (MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) - DeltaVolumeOp will be added to annulus + + !if (iLoc == 1) then + MudSystem%MudSection= F_Counts%StringIntervalCounts+1 + MudSystem%BackheadX= MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1) + !elseif (iLoc == 2) then + ! MudSection= Kick_Forehead_section + ! BackheadX= Kick_Forehead_X + !endif + +!========================ANNULUS ENTRANCE==================== + !if (KickMigration_2SideBit == .FALSE.) then + ! if ( ABS(AnnulusSuctionDensity_Old - MudSystem%St_Density%Last()) >= DensityMixTol ) then ! new mud is pumped + ! call Ann_Density%AddTo (iLoc,MudSystem%St_Density%Last()) + ! call Ann_MudDischarged_Volume%AddTo (iLoc,0.0d0) + ! call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX) + ! call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection) + ! call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX) + ! call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection) + ! call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0) + ! call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0) + ! call Ann_MudOrKick%AddTo (iLoc,0) + ! call Ann_CuttingMud%AddTo (iLoc,0) + ! + ! AnnulusSuctionDensity_Old= MudSystem%St_Density%Last() + ! + ! MudIsChanged= .true. + ! endif + ! + ! Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+ ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) - ((2-iloc)*ABS(DeltaVolumePipe)) !(gal) + ! + !endif + + + + + MudSystem%Ann_Mud_Backhead_section%Array(1)= MudSystem%MudSection !it is needed to be updated for (a condition that one pipe is removed from Annulus due to trip out)- (and add pipe) + MudSystem%Ann_Mud_Backhead_X%Array(1)= MudSystem%BackheadX + + + + !iloc=1 : (2-iloc)=1 normal + !iloc=2 : (2-iloc)=0 kick influx or migration is in annulus + +!========================Same to Tripping In==================== + + !write(*,*) 'Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume=' , Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume + + + if (MudSystem%Op_Kick_Saved_Volume > 0.0 .and. MudSystem%Ann_MudOrKick%First() == 0) then !1st Mode + write(*,*) 'Kick influx enters Annulus' + call MudSystem%Ann_Density%AddToFirst (MudSystem%Op_KickSaved_Density) + call MudSystem%Ann_MudDischarged_Volume%AddToFirst (MudSystem%Op_Kick_Saved_Volume) + call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Forehead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1)) + call MudSystem%Ann_Mud_Backhead_section%AddToFirst (F_Counts%StringIntervalCounts+1) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call MudSystem%Ann_MudOrKick%AddToFirst (MudSystem%Saved_Op_MudOrKick) !<<<<<<<< + call MudSystem%Ann_CuttingMud%AddToFirst (0) + elseif (MudSystem%Op_Kick_Saved_Volume > 0.0 .and. MudSystem%Ann_MudOrKick%First() /= 0) then + MudSystem%Ann_MudDischarged_Volume%Array(1)= MudSystem%Ann_MudDischarged_Volume%Array(1) + MudSystem%Op_Kick_Saved_Volume + endif + + + + if ( MudSystem%Op_NeededVolume_ToFill > 0.0 .and. (MudSystem%Op_NeededVolume_ToFill < ABS(MudSystem%DeltaVolumeAnnulusCapacity)) .and. MudSystem%Op_MudOrKick%Last() == 0 .and. (MudSystem%iLoc==2 .or. iloc_edited==1)) then !3rd Mode + !write(*,*) 'checkpoint 0' + !! for avoid kick separation -Op_MudOrKick%Last() == 0: because of pump + MudSystem%NewVolume= ((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) ! =volume that should be added to iloc=2 in Ann + call RemoveOpMudArrays(MudSystem%Op_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann in %%1 section + if ( MudSystem%Ann_MudDischarged_Volume%Array(1) > ((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) ) then! 1st in Ann = kick ,, we expect: ((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)= OpMudVolLast + MudSystem%Ann_MudDischarged_Volume%Array(1)= MudSystem%Ann_MudDischarged_Volume%Array(1) - ((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())+ ((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) ! kick + else + call RemoveAnnulusMudArrays(1) !kick is removed + MudSystem%iLoc= 1 + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())+ ((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) + write(*,*) 'little expand' + ! including a little expand + endif + endif + + if (MudSystem%Op_Saved_MudDischarged_Volume> 0.0) then !1st Mode + MudSystem%NewDensity= MudSystem%Op_MudSaved_Density + !write(*,*) 'iloc,...' , iloc,((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline),Op_Saved_MudDischarged_Volume + if (MudSystem%iLoc==1) then + !write(*,*) 'checkpoint 1' + MudSystem%NewVolume= MudSystem%Op_Saved_MudDischarged_Volume + elseif (real(((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline)) - real(MudSystem%Op_Saved_MudDischarged_Volume) > 0.d0 ) then ! for avoid kick separation + !write(*,*) 'checkpoint 2' + MudSystem%NewVolume= ((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) !- Op_Saved_MudDischarged_Volume + call RemoveOpMudArrays(MudSystem%Op_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann + if ( MudSystem%Ann_MudDischarged_Volume%Array(1) > (((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) - MudSystem%Op_Saved_MudDischarged_Volume) ) then! 1st in Ann = kick + MudSystem%Ann_MudDischarged_Volume%Array(1)= MudSystem%Ann_MudDischarged_Volume%Array(1) - (((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) - MudSystem%Op_Saved_MudDischarged_Volume) + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())+ (((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) - MudSystem%Op_Saved_MudDischarged_Volume) !kick + else + call RemoveAnnulusMudArrays(1) !kick is removed + MudSystem%iLoc =1 + MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_Density%Length())+ (((MudSystem%AnnulusFlowRate/60.d0)*MudSystem%DeltaT_Mudline) - MudSystem%Op_Saved_MudDischarged_Volume) + write(*,*) 'little expand' + + ! including a little expand + endif + + + else ! iloc==2 , ((MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) == Op_Saved_MudDischarged_Volume + !write(*,*) 'checkpoint 3' + MudSystem%NewVolume= MudSystem%Op_Saved_MudDischarged_Volume ! it is normal mode + endif + + + endif + + !write(*,*) 'NewVolume=' ,NewVolume + + + if( MudSystem%Ann_Density%Length() == 1 .and. MudSystem%iLoc ==2 ) then + + write(*,*) '***errorb****==' + + write(*,*) 'iloc_edited=' , iloc_edited + write(*,*) 'iloc_changedTo2=' , iloc_changedTo2 + + write(*,*) 'Op_Capacity===' , sum(MudSystem%OpSection_VolumeCapacity(1:F_Counts%BottomHoleIntervalCounts)) + + WRITE (*,*) 'Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume',MudSystem%Op_Saved_MudDischarged_Volume, MudSystem%Op_Kick_Saved_Volume + + do imud=1, MudSystem%Op_MudDischarged_Volume%Length() + write(*,*) 'Op:', imud, MudSystem%Op_MudDischarged_Volume%Array(imud), MudSystem%Op_Density%Array(imud) ,MudSystem%Op_MudOrKick%Array(imud) + enddo + + do imud=1, MudSystem%Ann_MudDischarged_Volume%Length() + write(*,*) 'Ann:', imud, MudSystem%Ann_MudDischarged_Volume%Array(imud), MudSystem%Ann_Density%Array(imud) ,MudSystem%Ann_MudOrKick%Array(imud) + enddo + + + + write(*,*) '==***errorb****' + endif + + + + + + if ((ROP_Bit%RateOfPenetration==0 .and. abs(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%NewDensity)< MudSystem%DensityMixTol) & !%%1 section + .or. (ROP_Bit%RateOfPenetration>0. .and. MudSystem%Ann_CuttingMud%Array(MudSystem%iLoc)==1 .and. abs(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%NewDensity)< MudSystem%CuttingDensityMixTol) & + .or. (ROP_Bit%RateOfPenetration>0. .and. MudSystem%Ann_CuttingMud%Array(MudSystem%iLoc)==0 .and. MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged + !write(*,*) '%%1 section a)' + MudSystem%Ann_Density%Array(MudSystem%iLoc)= (MudSystem%Ann_Density%Array(MudSystem%iLoc)*MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewVolume) + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%NewVolume + MudSystem%Ann_Mud_Forehead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_Mud_Backhead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Backhead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_RemainedVolume_in_LastSection%Array(MudSystem%iLoc)= (0.0d0) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(MudSystem%iLoc)= (0.0d0) + else ! 2-Merging conditions are not meeted, so new pocket + !write(*,*) '%%1 section b)' + + call MudSystem%Ann_Density%AddTo (MudSystem%iLoc,MudSystem%NewDensity) + call MudSystem%Ann_MudDischarged_Volume%AddTo (MudSystem%iLoc,MudSystem%NewVolume) + call MudSystem%Ann_Mud_Forehead_X%AddTo (MudSystem%iLoc,MudSystem%BackheadX) + call MudSystem%Ann_Mud_Forehead_section%AddTo (MudSystem%iLoc,MudSystem%MudSection) + call MudSystem%Ann_Mud_Backhead_X%AddTo (MudSystem%iLoc,MudSystem%BackheadX) + call MudSystem%Ann_Mud_Backhead_section%AddTo (MudSystem%iLoc,MudSystem%MudSection) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (MudSystem%iLoc,0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystem%iLoc,0.0d0) + call MudSystem%Ann_MudOrKick%AddTo (MudSystem%iLoc,0) + call MudSystem%Ann_CuttingMud%AddTo (MudSystem%iLoc,0) + !write(*,*) 'd) annLength=' , Ann_Density%Length() + + endif + + + + +!========================Same to Tripping In - End==================== + + !write(*,*) 'b)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:)) + + !write(*,*) 'no======2' + ! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + ! + ! + ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + ! + ! + !write(*,*) '2======no' + +!=============== save Ann Mud data to transfer to the ChokeLine enterance + MudSystem%AnnMudVolumeSum= 0.d0 + !Ann_MudSaved_Density= 0.d0 + !Ann_KickSaved_Density= 0.d0 + MudSystem%Ann_Saved_MudDischarged_Volume= 0.d0 + MudSystem%Ann_Kick_Saved_Volume= 0.d0 + MudSystem%Saved_Ann_MudOrKick= 0 + MudSystem%Ann_to_Choke_2mud= .false. + + + + + do imud=1, MudSystem%Ann_MudDischarged_Volume%Length() + + MudSystem%AnnMudVolumeSum= MudSystem%AnnMudVolumeSum + MudSystem%Ann_MudDischarged_Volume%Array(imud) + + if ( MudSystem%AnnMudVolumeSum > sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) ) then + + IF (MudSystem%Ann_MudOrKick%Array(imud) == 0) THEN + MudSystem%Ann_MudSaved_Density = MudSystem%Ann_Density%Array(imud) + MudSystem%Ann_Saved_MudDischarged_Volume = MudSystem%AnnMudVolumeSum - sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) + ELSEIF (MudSystem%Ann_MudOrKick%Array(imud) > 0 .AND. MudSystem%Ann_MudOrKick%Array(imud) <100) THEN ! 104= AIR + MudSystem%Ann_Kick_Saved_Volume = MudSystem%AnnMudVolumeSum - sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) + MudSystem%Saved_Ann_MudOrKick= MudSystem%Ann_MudOrKick%Array (imud) + MudSystem%Ann_KickSaved_Density= MudSystem%Ann_Density%Array(imud) + END IF + + do ii= imud + 1, MudSystem%Ann_MudDischarged_Volume%Length() + IF (MudSystem%Ann_MudOrKick%Array(ii) == 0) THEN + MudSystem%Ann_MudSaved_Density = ((MudSystem%Ann_MudSaved_Density * MudSystem%Ann_Saved_MudDischarged_Volume) + (MudSystem%Ann_Density%Array(ii) * MudSystem%Ann_MudDischarged_Volume%Array(ii))) / (MudSystem%Ann_Saved_MudDischarged_Volume + MudSystem%Ann_MudDischarged_Volume%Array(ii)) + MudSystem%Ann_Saved_MudDischarged_Volume = MudSystem%Ann_Saved_MudDischarged_Volume + MudSystem%Ann_MudDischarged_Volume%Array(ii) + MudSystem%Ann_to_Choke_2mud= .true. + ELSEIF (MudSystem%Ann_MudOrKick%Array(ii) > 0 .AND. MudSystem%Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR + MudSystem%Ann_Kick_Saved_Volume = MudSystem%Ann_Kick_Saved_Volume + MudSystem%Ann_MudDischarged_Volume%Array(ii) + MudSystem%Saved_Ann_MudOrKick= MudSystem%Ann_MudOrKick%Array (ii) + MudSystem%Ann_KickSaved_Density= MudSystem%Ann_Density%Array(ii) + END IF + enddo + + exit ! exits do + + endif + + enddo + +MudSystem%Ann_Saved_MudDischarged_Volume_Final= MudSystem%Ann_Saved_MudDischarged_Volume +MudSystem%Ann_Kick_Saved_Volume_Final= MudSystem%Ann_Kick_Saved_Volume + !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:NoPipeSections)) + !write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + +IF (MudSystem%WellHeadIsOpen) MudSystem%MudVolume_InjectedFromAnn = MudSystem%Ann_Saved_MudDischarged_Volume_Final-((MudSystem%Qlost/60.0d0)*MudSystem%DeltaT_Mudline) + !NoGasPocket +!write(*,*) 'Ann_Saved_Mud_Vol,Ann_Kick_Saved_Vol=' , Ann_Saved_MudDischarged_Volume,Ann_Kick_Saved_Volume + +!====================================================================== + + + !write(*,*) 'Ann_Saved_Mud=' , Ann_Saved_MudDischarged_Volume +!======================== Annulus ==================== + + !MudIsChanged= .false. + +imud= 0 + + do while (imud < MudSystem%Ann_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%Ann_Mud_Backhead_X%Array(imud)= MudSystem%Ann_Mud_Forehead_X%Array(imud-1) + MudSystem%Ann_Mud_Backhead_section%Array(imud)= MudSystem%Ann_Mud_Forehead_section%Array(imud-1) + endif + + ! write(*,*) 'imud==' , imud + !write(*,*) '***)Ann_Mud_Backhead_section(imud)= ' , Ann_Mud_Backhead_section%Array(imud), Ann_density%Array(imud) + + + MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))- MudSystem%Ann_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( MudSystem%Ann_MudDischarged_Volume%Array(imud) <= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%Ann_Mud_Backhead_section%Array(imud) + MudSystem%Ann_Mud_Forehead_X%Array(imud)= MudSystem%Ann_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Backhead_section%Array(imud)) + ! 7.48 is for gal to ft^3 + + else + + MudSystem%isection= MudSystem%Ann_Mud_Backhead_section%Array(imud)+1 + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > MudSystem%NoPipeSections) then ! last pipe section(well exit) + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + MudSystem%Ann_Mud_Forehead_X%Array(imud)= MudSystem%Xend_PipeSection(MudSystem%NoPipeSections) + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%NoPipeSections + + if (MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveAnnulusMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%Ann_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_PipeSection(MudSystem%isection)- MudSystem%Xstart_PipeSection(MudSystem%isection)))+ MudSystem%Xstart_PipeSection(MudSystem%isection) + exit + else + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo + + if (MudSystem%Ann_Mud_Forehead_X%Last() < MudSystem%Xend_PipeSection(MudSystem%NoPipeSections)) then + MudSystem%Ann_Mud_Forehead_X%Array(MudSystem%Ann_Mud_Forehead_X%Length()) = MudSystem%Xend_PipeSection(MudSystem%NoPipeSections) ! for error preventing + endif + +!========================ANNULUS END================= + + + +!************************************************************************************************************************* + +!========================Tripping Out- 2nd Mode==================== + + + elseif ( MudSystem%Op_NeededVolume_ToFill > ABS(MudSystem%DeltaVolumeAnnulusCapacity) ) then !pump is off or Pump flow is less than trip out so fluid Level in Annulus decreases + !write(*,*) 'trip out 2nd mode' + + + SavedDensityForOp= MudSystem%Ann_Density%Array(1) +!========================ANNULUS ENTRANCE==================== + + ! <<< SIMILAR TO UTUBE 2 >>> + if ( MudSystem%Ann_Density%Last() /= 0.0 ) then ! new mud is pumped + call MudSystem%Ann_Density%Add (0.0d0) + call MudSystem%Ann_MudDischarged_Volume%Add (0.0d0) + call MudSystem%Ann_Mud_Forehead_X%Add (MudSystem%Xend_PipeSection(MudSystem%NoPipeSections)) + call MudSystem%Ann_Mud_Forehead_section%Add (MudSystem%NoPipeSections) + call MudSystem%Ann_Mud_Backhead_X%Add (MudSystem%Xstart_PipeSection(MudSystem%NoPipeSections)) + call MudSystem%Ann_Mud_Backhead_section%Add (MudSystem%NoPipeSections) + call MudSystem%Ann_RemainedVolume_in_LastSection%Add (0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%Add (0.0d0) + call MudSystem%Ann_MudOrKick%Add (104) + call MudSystem%Ann_CuttingMud%Add (0) + + !AnnulusSuctionDensity_Old= Hz_Density%Last() + endif + + MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%Ann_Mud_Forehead_section%Length())= MudSystem%NoPipeSections !it is needed to be updated for (a condition that one pipe is removed from Annulus due to trip out)- (and add pipe) + MudSystem%Ann_Mud_Forehead_X%Array(MudSystem%Ann_Mud_Forehead_X%Length())= MudSystem%Xend_PipeSection(MudSystem%NoPipeSections) + + + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_MudDischarged_Volume%Length())= MudSystem%Ann_MudDischarged_Volume%Last()+ (MudSystem%Op_NeededVolume_ToFill - ABS(MudSystem%DeltaVolumeAnnulusCapacity)) ! Op_NeededVolume_ToFill !ABS(DeltaVolumePipe) - ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) !(gal) + +!=================================================================== + + + + if ( (MudSystem%iLoc==2 .or. iloc_edited==1) .and. MudSystem%Op_MudOrKick%Last()==0 ) then ! for avoid kick separation + !write(*,*) 'here mud should be removed from Op last' + + if (abs(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%Op_Density%Last())< MudSystem%DensityMixTol) then + + MudSystem%Ann_Density%Array(MudSystem%iLoc)= (MudSystem%Ann_Density%Array(MudSystem%iLoc)*MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%Op_Density%Last()*MudSystem%Op_MudDischarged_Volume%Last())/(MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%Op_MudDischarged_Volume%Last()) + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+MudSystem%Op_MudDischarged_Volume%Last() ! OP_Last is mud(effect of pump added mud) + MudSystem%Ann_Mud_Forehead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_Mud_Backhead_X%Array(MudSystem%iLoc)= MudSystem%BackheadX + MudSystem%Ann_Mud_Backhead_section%Array(MudSystem%iLoc)= MudSystem%MudSection + MudSystem%Ann_RemainedVolume_in_LastSection%Array(MudSystem%iLoc)= (0.0d0) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(MudSystem%iLoc)= (0.0d0) + !write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + else ! 2-Merging conditions are not meeted, so new pocket + call MudSystem%Ann_Density%AddTo (MudSystem%iLoc,MudSystem%Op_Density%Last()) + call MudSystem%Ann_MudDischarged_Volume%AddTo (MudSystem%iLoc,MudSystem%Op_MudDischarged_Volume%Last()) + call MudSystem%Ann_Mud_Forehead_X%AddTo (MudSystem%iLoc,MudSystem%BackheadX) + call MudSystem%Ann_Mud_Forehead_section%AddTo (MudSystem%iLoc,MudSystem%MudSection) + call MudSystem%Ann_Mud_Backhead_X%AddTo (MudSystem%iLoc,MudSystem%BackheadX) + call MudSystem%Ann_Mud_Backhead_section%AddTo (MudSystem%iLoc,MudSystem%MudSection) + call MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (MudSystem%iLoc,0.0d0) + call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystem%iLoc,0.0d0) + call MudSystem%Ann_MudOrKick%AddTo (MudSystem%iLoc,0) + call MudSystem%Ann_CuttingMud%AddTo (MudSystem%iLoc,0) + endif + + MudSystem%Op_NeededVolume_ToFill= MudSystem%Op_NeededVolume_ToFill + MudSystem%Op_MudDischarged_Volume%Last() ! OP_Last is mud(effect of pump added mud) + + call RemoveOpMudArrays(MudSystem%Op_MudOrKick%Length()) + + + endif +!=================================================================== + + +!=============== save Ann Mud data to transfer to the ChokeLine enterance + !AnnMudVolumeSum= 0.d0 + !!Ann_MudSaved_Density= 0.d0 + !!Ann_KickSaved_Density= 0.d0 + MudSystem%Ann_Saved_MudDischarged_Volume= 0.d0 + MudSystem%Ann_Kick_Saved_Volume= 0.d0 + !Saved_Ann_MudOrKick= 0 + !Ann_to_Choke_2mud= .false. + + + + + !do imud=1, Ann_MudDischarged_Volume%Length() + ! + ! AnnMudVolumeSum= AnnMudVolumeSum + Ann_MudDischarged_Volume%Array(imud) + ! + ! if ( AnnMudVolumeSum > sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) ) then + ! + ! IF (Ann_MudOrKick%Array(imud) == 0) THEN + ! Ann_MudSaved_Density = Ann_Density%Array(imud) + ! Ann_Saved_MudDischarged_Volume = AnnMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! ELSEIF (Ann_MudOrKick%Array(imud) > 0 .AND. Ann_MudOrKick%Array(imud) <100) THEN ! 104= AIR + ! Ann_Kick_Saved_Volume = AnnMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! Saved_Ann_MudOrKick= Ann_MudOrKick%Array (imud) + ! Ann_KickSaved_Density= Ann_Density%Array(imud) + ! END IF + ! + ! do ii= imud + 1, Ann_MudDischarged_Volume%Length() + ! IF (Ann_MudOrKick%Array(ii) == 0) THEN + ! Ann_MudSaved_Density = ((Ann_MudSaved_Density * Ann_Saved_MudDischarged_Volume) + (Ann_Density%Array(ii) * Ann_MudDischarged_Volume%Array(ii))) / (Ann_Saved_MudDischarged_Volume + Ann_MudDischarged_Volume%Array(ii)) + ! Ann_Saved_MudDischarged_Volume = Ann_Saved_MudDischarged_Volume + Ann_MudDischarged_Volume%Array(ii) + ! Ann_to_Choke_2mud= .true. + ! ELSEIF (Ann_MudOrKick%Array(ii) > 0 .AND. Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR + ! Ann_Kick_Saved_Volume = Ann_Kick_Saved_Volume + Ann_MudDischarged_Volume%Array(ii) + ! Saved_Ann_MudOrKick= Ann_MudOrKick%Array (ii) + ! Ann_KickSaved_Density= Ann_Density%Array(ii) + ! END IF + ! enddo + ! + ! exit ! exits do + ! + ! endif + ! + !enddo + + + ! write(*,*) 'check point 2==' + ! + ! + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + ! + ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + ! + ! + !write(*,*) '==check point 2' + + + + + +MudSystem%Ann_Saved_MudDischarged_Volume_Final= MudSystem%Ann_Saved_MudDischarged_Volume +MudSystem%Ann_Kick_Saved_Volume_Final= MudSystem%Ann_Kick_Saved_Volume + !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + !write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + + !write(*,*) 'Ann_Saved_MudDischarged_Volume_Final=' , Ann_Saved_MudDischarged_Volume_Final + + + +IF (MudSystem%WellHeadIsOpen) MudSystem%MudVolume_InjectedFromAnn = MudSystem%Ann_Saved_MudDischarged_Volume_Final-((MudSystem%Qlost/60.0d0)*MudSystem%DeltaT_Mudline) + !! NoGasPocket > 0 .AND. + +!write(*,*) 'Ann_Saved_Mud_Vol,Ann_Kick_Saved_Vol=' , Ann_Saved_MudDischarged_Volume,Ann_Kick_Saved_Volume + + +!====================================================================== + +!========================ANNULUS==================== + ! <<< SIMILAR TO UTUBE 2 >>> + + !write(*,*) Ann_MudOrKick%Last(), 'DeltaVolumePipe , after volume=' ,ABS(DeltaVolumePipe), Ann_MudDischarged_Volume%Last() +imud= MudSystem%Ann_Mud_Forehead_X%Length() + 1 + + do while (imud > 1) + imud = imud - 1 + + if (imud< MudSystem%Ann_Mud_Forehead_X%Length()) then + MudSystem%Ann_Mud_Forehead_X%Array(imud)= MudSystem%Ann_Mud_Backhead_X%Array(imud+1) + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%Ann_Mud_Backhead_section%Array(imud+1) + endif + + +! <<< Fracture Shoe Lost + IF ( MudSystem%ShoeLost .and. Shoe%ShoeDepth < MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. Shoe%ShoeDepth >= MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then + !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)-((MudSystem%Qlost/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) + if (MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then + !write(*,*) 'mud is removed by shoe lost, imud=' , imud + call RemoveAnnulusMudArrays(imud) + imud= imud-1 + cycle + endif + MudSystem%LostInTripOutIsDone= .true. + ENDIF +! Fracture Shoe Lost >>> + + + + + + + + + !write(*,*) 'a)imud,Ann_Mud_Forehead_section=',imud,Ann_Mud_Forehead_section%Array(imud) + + MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Forehead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Forehead_section%Array(imud))) & + / ABS(MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Forehead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Forehead_section%Array(imud))) + ! +1 for string , -1 for annulus + + !write(*,*) 'b)imud,Forehead_X,Xstart_PipeSection=',imud,Ann_Mud_Forehead_X%Array(imud),Xstart_PipeSection(Ann_Mud_Forehead_section%Array(imud)) + + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Ann_Mud_Forehead_X%Array(imud)- MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Forehead_section%Array(imud)))* & + MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Forehead_section%Array(imud)) !(ft^3) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + if ( MudSystem%Ann_MudDischarged_Volume%Array(imud) <= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Ann_Mud_Backhead_section%Array(imud)= MudSystem%Ann_Mud_Forehead_section%Array(imud) + MudSystem%Ann_Mud_Backhead_X%Array(imud)= MudSystem%Ann_Mud_Forehead_X%Array(imud)- MudSystem%DirectionCoef*(MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Forehead_section%Array(imud)) + ! 7.48051948 is for gal to ft^3 + else + MudSystem%isection= MudSystem%Ann_Mud_Forehead_section%Array(imud)-1 + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection < F_Counts%StringIntervalCounts+1) then ! last pipe section(well exit) F_Counts%StringIntervalCounts+1 is the first section in Annulus + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + MudSystem%Ann_Mud_Backhead_X%Array(imud)= MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1) + MudSystem%Ann_Mud_Backhead_section%Array(imud)= F_Counts%StringIntervalCounts+1 + + if (MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveAnnulusMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Ann_Mud_Backhead_section%Array(imud)= MudSystem%isection + MudSystem%Ann_Mud_Backhead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xstart_PipeSection(MudSystem%isection)- MudSystem%Xend_PipeSection(MudSystem%isection)))+ MudSystem%Xend_PipeSection(MudSystem%isection) + exit + else + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection- 1 + + + endif + + enddo + + endif + + enddo +!========================ANNULUS END================= + + endif ! end of 1st &3rd & 2nd Mode + + +!************************************************************************************************************************* + + + + + + +!======================== Bottom Hole Entrance ========================== + !if (iloc == 1) then + if ( MudSystem%Op_NeededVolume_ToFill > 0.0 ) then ! it is needed for 2nd & 3rd mode + !write(*,*) 'op add for 2nd & 3rd mode done' + + + + if ( ABS(MudSystem%Op_Density%Last() - SavedDensityForOp ) >= MudSystem%DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Last()>42.) ) then ! 1-Merging conditions are not meeted, so new pocket + + call MudSystem%Op_Density%Add (SavedDensityForOp) + call MudSystem%Op_MudDischarged_Volume%Add (MudSystem%Op_NeededVolume_ToFill) + call MudSystem%Op_Mud_Forehead_X%Add (0.0d0) + call MudSystem%Op_Mud_Forehead_section%Add (1) + call MudSystem%Op_Mud_Backhead_X%Add (0.0d0) + call MudSystem%Op_Mud_Backhead_section%Add (1) + call MudSystem%Op_RemainedVolume_in_LastSection%Add (0.0d0) + call MudSystem%Op_EmptyVolume_inBackheadLocation%Add (0.0d0) + call MudSystem%Op_MudOrKick%Add (MudSystem%Ann_MudOrKick%Array(1)) + else ! 2-Pockets are Merged + + MudSystem%Op_Density%Array (MudSystem%Op_Density%Length())= (SavedDensityForOp*MudSystem%Op_NeededVolume_ToFill+MudSystem%Op_Density%Last()*MudSystem%Op_MudDischarged_Volume%Last())/(MudSystem%Op_MudDischarged_Volume%Last()+MudSystem%Op_NeededVolume_ToFill) + MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_Density%Length())= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_Density%Length()) + MudSystem%Op_NeededVolume_ToFill + MudSystem%Op_RemainedVolume_in_LastSection%Array (MudSystem%Op_Density%Length())= 0.0 + MudSystem%Op_EmptyVolume_inBackheadLocation%Array (MudSystem%Op_Density%Length())= 0.0 + + endif + + endif + + + + +!============================= Bottom Hole ============================== + +imud=0 + do while (imud < MudSystem%Op_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%Op_Mud_Backhead_X%Array(imud)= MudSystem%Op_Mud_Forehead_X%Array(imud-1) + MudSystem%Op_Mud_Backhead_section%Array(imud)= MudSystem%Op_Mud_Forehead_section%Array(imud-1) + endif + + MudSystem%DirectionCoef= (MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + + MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))- MudSystem%Op_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( MudSystem%Op_MudDischarged_Volume%Array(imud) <= MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Op_Mud_Forehead_section%Array(imud)= MudSystem%Op_Mud_Backhead_section%Array(imud) + MudSystem%Op_Mud_Forehead_X%Array(imud)= MudSystem%Op_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Backhead_section%Array(imud)) + ! 7.48051948 is for gal to ft^3 + + else + + MudSystem%isection= MudSystem%Op_Mud_Backhead_section%Array(imud)+1 + MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Op_MudDischarged_Volume%Array(imud)- MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > F_Counts%BottomHoleIntervalCounts) then ! last pipe section(well exit) + !if( imud==1) KickDeltaVinAnnulus= Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space + MudSystem%Op_MudDischarged_Volume%Array(imud)= MudSystem%Op_MudDischarged_Volume%Array(imud)- MudSystem%Op_RemainedVolume_in_LastSection%Array(imud) + MudSystem%Op_Mud_Forehead_X%Array(imud)= MudSystem%Xend_OpSection(F_Counts%BottomHoleIntervalCounts) + MudSystem%Op_Mud_Forehead_section%Array(imud)= F_Counts%BottomHoleIntervalCounts + + if (MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call MudSystem%Op_MudDischarged_Volume%Remove (imud) + call MudSystem%Op_Mud_Backhead_X%Remove (imud) + call MudSystem%Op_Mud_Backhead_section%Remove (imud) + call MudSystem%Op_Mud_Forehead_X%Remove (imud) + call MudSystem%Op_Mud_Forehead_section%Remove (imud) + call MudSystem%Op_Density%Remove (imud) + call MudSystem%Op_RemainedVolume_in_LastSection%Remove (imud) + call MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (imud) + call MudSystem%Op_MudOrKick%Remove (imud) + + endif + + exit + endif + + MudSystem%xx= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%OpSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Op_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%Op_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_OpSection(MudSystem%isection)- MudSystem%Xstart_OpSection(MudSystem%isection)))+ MudSystem%Xstart_OpSection(MudSystem%isection) + exit + else + MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)- MudSystem%OpSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo + + + +!========================Bottom Hole END================= + ! write(*,*) 'after sorting==' + !!! + ! do imud=1, Op_MudDischarged_Volume%Length() + ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) + ! enddo + ! + ! do imud=1, Ann_MudDischarged_Volume%Length() + ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) + ! enddo + !!! + !! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + !! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + !!! + !!! + !write(*,*) '==after sorting' + +!========================================================= + + + MudSystem%total_injected = MudSystem%total_injected + MudSystem%MudVolume_InjectedFromAnn + + if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + MudSystem%total_injected= 0. + endif + !write(*,*) ' MudSystem%MudVolume_InjectedFromAnn =' , MudSystem%MudVolume_InjectedFromAnn + + !write(*,*) ' total injected-tripout =' , total_injected + !write(*,*) ' injected-tripout =' , MudSystem%MudVolume_InjectedFromAnn + + + + + + + + end subroutine TripOut_and_Pump + + + diff --git a/Equipments/MudSystem-old/Utube1_and_Trip_In.f90 b/Equipments/MudSystem-old/Utube1_and_Trip_In.f90 new file mode 100644 index 0000000..3530fa2 --- /dev/null +++ b/Equipments/MudSystem-old/Utube1_and_Trip_In.f90 @@ -0,0 +1,532 @@ +SUBROUTINE Utube1_and_TripIn ! is called in subroutine CirculationCodeSelect string to annulus + + use UTUBEVARSModule + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + USE sROP_Variables + use CDrillWatchVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + Use CShoeVariables + Use CUnityOutputs + + implicit none + + write(*,*) 'Utube1 code' +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + MudSystem%UtubeMode1Activated= .true. + !write(*,*) 'QUTubeInput=' , QUTubeInput + !Qinput=5000. + MudSystem%StringFlowRate= QUTubeInput ! (gpm) + MudSystem%AnnulusFlowRate= QUTubeInput + MudSystem%StringFlowRateFinal= MudSystem%StringFlowRate + MudSystem%AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate +!=========================================== + + 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 MudSystem%St_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg) + ! call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! + ! call Ann_MudDischarged_Volume%AddToFirst (REAL(sum(F_Interval((F_StringIntervalCounts+F_BottomHoleIntervalCounts+1):F_IntervalsTotalCounts)%Volume))) !startup initial + ! call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1)) + ! call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1) + ! call Ann_Mud_Forehead_X%AddToFirst (Xend_PipeSection(NoPipeSections)) + ! call Ann_Mud_Forehead_section%AddToFirst (NoPipeSections) + ! call Ann_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg) + ! call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + !Hz_Density%Array(:)= 0.0 !commented + !Hz_MudOrKick%Array(:)= 104 !commented + + MudSystem%Hz_Density_Utube= 0.0 + MudSystem%Hz_MudOrKick_Utube= 104 + + MudSystem%FirstSetUtube1= 1 + endif + + + + +!========================Horizontal PIPE ENTRANCE================= + + !if (SuctionDensity_Old >= (ActiveDensity+0.05) .or. SuctionDensity_Old <= (ActiveDensity-0.05)) then ! new mud is pumped + ! !ImudCount= ImudCount+1 + ! !SuctionMud= ImudCount + ! call Hz_Density%AddToFirst (REAL(ActiveDensity)) !ActiveDensity : badan in moteghayer bayad avaz beshe + ! call Hz_MudDischarged_Volume%AddToFirst (0.0d0) + ! call Hz_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(1)) + ! call Hz_Mud_Forehead_section%AddToFirst (1) + ! call Hz_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1)) + ! call Hz_Mud_Backhead_section%AddToFirst (1) + ! call Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! call Hz_MudOrKick%AddToFirst (0) + ! + ! SuctionDensity_Old= ActiveDensity + !endif + +!========================Horizontal PIPE STRING================= + + !commented + +! 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()) +! imud = imud + 1 +! +! if (imud> 1) then +! Hz_Mud_Backhead_X%Array(imud)= Hz_Mud_Forehead_X%Array(imud-1) +! Hz_Mud_Backhead_section%Array(imud)= Hz_Mud_Forehead_section%Array(imud-1) +! endif +! +! +! DirectionCoef= (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) & +! / ABS(Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) +! ! +1 for string , -1 for annulus +! +! +! Hz_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))- Hz_Mud_Backhead_X%Array(imud))* & +! Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) !(ft^3) +! Hz_EmptyVolume_inBackheadLocation%Array(imud)= Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948 ! ft^3 to gal +! +! +! if ( Hz_MudDischarged_Volume%Array(imud) <= Hz_EmptyVolume_inBackheadLocation%Array(imud)) then +! Hz_Mud_Forehead_section%Array(imud)= Hz_Mud_Backhead_section%Array(imud) +! Hz_Mud_Forehead_X%Array(imud)= Hz_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Hz_MudDischarged_Volume%Array(imud)/7.48051948)/Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) +! ! 7.48 is for gal to ft^3 +! else +! +! isection= Hz_Mud_Backhead_section%Array(imud)+1 +! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_EmptyVolume_inBackheadLocation%Array(imud) +! +! do +! if (isection > 1) then ! (horizontal pipe exit) +! Hz_MudDischarged_Volume%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_RemainedVolume_in_LastSection%Array(imud) +! Hz_Mud_Forehead_X%Array(imud)= Xend_PipeSection(1) +! Hz_Mud_Forehead_section%Array(imud)= 1 +! if (Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string +! call Hz_MudDischarged_Volume%Remove (imud) +! call Hz_Mud_Backhead_X%Remove (imud) +! call Hz_Mud_Backhead_section%Remove (imud) +! call Hz_Mud_Forehead_X%Remove (imud) +! call Hz_Mud_Forehead_section%Remove (imud) +! call Hz_Density%Remove (imud) +! call Hz_RemainedVolume_in_LastSection%Remove (imud) +! call Hz_EmptyVolume_inBackheadLocation%Remove (imud) +! call Hz_MudOrKick%Remove (imud) +! +! endif +! exit +! endif +! +! xx= Hz_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal) +! +! if (xx<= 1.0) then +! Hz_Mud_Forehead_section%Array(imud)= isection +! Hz_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection) +! exit +! else +! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection) +! isection= isection+ 1 +! +! +! endif +! +! enddo +! +! endif +! +! enddo + + !commented + +!========================Horizontal PIPE END================= + +!========================STRING ENTRANCE================= + !write(*,*) 'a) MudSystem%St_Density%Length()=' , MudSystem%St_Density%Length() + + 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) 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 MudSystem%StringFlowRate', MudSystem%StringFlowRate + MudSystem%St_MudDischarged_Volume%Array(1)= MudSystem%St_MudDischarged_Volume%Array(1)+ ((MudSystem%StringFlowRate/60.d0)*MudSystem%DeltaT_Mudline) !(gal) + +imud=0 + do while (imud < MudSystem%St_Mud_Forehead_X%Length()) + imud = imud + 1 + + + if (imud> 1) then + MudSystem%St_Mud_Backhead_X%Array(imud)= MudSystem%St_Mud_Forehead_X%Array(imud-1) + MudSystem%St_Mud_Backhead_section%Array(imud)= MudSystem%St_Mud_Forehead_section%Array(imud-1) + endif + + MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_PipeSection(MudSystem%St_Mud_Backhead_section%Array(imud))- MudSystem%St_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_PipeSectionFt(MudSystem%St_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + if ( MudSystem%St_MudDischarged_Volume%Array(imud) <= MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%St_Mud_Forehead_section%Array(imud)= MudSystem%St_Mud_Backhead_section%Array(imud) + MudSystem%St_Mud_Forehead_X%Array(imud)= MudSystem%St_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%St_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%St_Mud_Backhead_section%Array(imud)) + ! 7.48 is for gal to ft^3 + else + + MudSystem%isection= MudSystem%St_Mud_Backhead_section%Array(imud)+1 + MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= MudSystem%St_MudDischarged_Volume%Array(imud)- MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > F_Counts%StringIntervalCounts) then ! last pipe section(string exit) F_Counts%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_Counts%StringIntervalCounts) + MudSystem%St_Mud_Forehead_section%Array(imud)= F_Counts%StringIntervalCounts + + if (MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveStringMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%St_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%St_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_PipeSection(MudSystem%isection)- MudSystem%Xstart_PipeSection(MudSystem%isection)))+ MudSystem%Xstart_PipeSection(MudSystem%isection) + exit + else + MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + + endif + + enddo + + endif + + enddo +!========================STRING END================= + +!========================== tripping in for OP remove =============================== + + !if (DeltaVolumeOp>0. .and. DeltaVolumeOp< Op_MudDischarged_Volume%Last()) then + ! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length())= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()) - DeltaVolumeOp + !else + ! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1)= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1) - (DeltaVolumeOp-Op_MudDischarged_Volume%Last()) + ! + ! call Op_MudDischarged_Volume%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Mud_Backhead_X%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Mud_Backhead_section%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Mud_Forehead_X%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Mud_Forehead_section%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Density%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_RemainedVolume_in_LastSection%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_EmptyVolume_inBackheadLocation%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_MudOrKick%Remove (Op_MudDischarged_Volume%Length()) + !endif + ! + +!============================= Bottom Hole ============================== + + !Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux +imud=0 + do while (imud < MudSystem%Op_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%Op_Mud_Backhead_X%Array(imud)= MudSystem%Op_Mud_Forehead_X%Array(imud-1) + MudSystem%Op_Mud_Backhead_section%Array(imud)= MudSystem%Op_Mud_Forehead_section%Array(imud-1) + endif + + + MudSystem%DirectionCoef= (MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + + MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))- MudSystem%Op_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( MudSystem%Op_MudDischarged_Volume%Array(imud) <= MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Op_Mud_Forehead_section%Array(imud)= MudSystem%Op_Mud_Backhead_section%Array(imud) + MudSystem%Op_Mud_Forehead_X%Array(imud)= MudSystem%Op_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Backhead_section%Array(imud)) + ! 7.48 is for gal to ft^3 + + else + + MudSystem%isection= MudSystem%Op_Mud_Backhead_section%Array(imud)+1 + MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Op_MudDischarged_Volume%Array(imud)- MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > F_Counts%BottomHoleIntervalCounts) then ! last pipe section(well exit) + if( imud==1) 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_Counts%BottomHoleIntervalCounts) + MudSystem%Op_Mud_Forehead_section%Array(imud)= F_Counts%BottomHoleIntervalCounts + + if (MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveOpMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%OpSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Op_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%Op_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_OpSection(MudSystem%isection)- MudSystem%Xstart_OpSection(MudSystem%isection)))+ MudSystem%Xstart_OpSection(MudSystem%isection) + exit + else + MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)- MudSystem%OpSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + endif + + enddo + + endif + + + if (MudSystem%Op_Mud_Forehead_X%Array(imud)== MudSystem%Xend_OpSection(F_Counts%BottomHoleIntervalCounts)) then + MudSystem%totalLength = MudSystem%Op_MudDischarged_Volume%Length() + do while(imud < MudSystem%totalLength) + + !imud = imud + 1 + call RemoveOpMudArrays(MudSystem%totalLength) + MudSystem%totalLength = MudSystem%totalLength - 1 + + + enddo + + exit ! + + endif + + !WRITE(*,*) imud,'Op_MudDischarged_Volume%Array(imud)' , Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) + + + + enddo + + + !write(*,*) 'Op_Mud_Forehead_X%Length()' , Op_Mud_Forehead_X%Length() + ! + ! WRITE(*,*) 'Xend_PipeSection(F_StringIntervalCounts)' , Xend_PipeSection(F_StringIntervalCounts) + ! WRITE(*,*) 'Op_Mud_Backhead_X%Array(1)' , Op_Mud_Backhead_X%Array(1) + ! WRITE(*,*) 'Op_Mud_Forehead_X%Array(1)' , Op_Mud_Forehead_X%Array(1) + ! WRITE(*,*) 'Op_Mud_Backhead_X%Array(2)' , Op_Mud_Backhead_X%Array(2) + ! WRITE(*,*) 'Op_Mud_Forehead_X%Array(2)' , Op_Mud_Forehead_X%Array(2) +!========================Bottom Hole END================= + + if (MudSystem%iLoc == 1) then + MudSystem%MudSection= F_Counts%StringIntervalCounts+1 + MudSystem%BackheadX= MudSystem%Xstart_PipeSection(F_Counts%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(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) + + MudSystem%AnnulusSuctionDensity_Old= MudSystem%St_Density%Last() + + MudSystem%MudIsChanged= .true. + endif + + 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 (MudSystem%DeltaVolumeOp > 0.0 .and. MudSystem%MudIsChanged== .false.) then !.and. DrillingMode== .false.) then ! trip in mode(loole paeen) + + !write(*,*) 'Tripping In' + + 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(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 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 (MudSystem%DeltaVolumeOp > 0.0 .and. MudSystem%MudIsChanged== .true. .and. ROP_Bit%RateOfPenetration==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 + + +!========================Tripping In - End==================== + + +!======================== ANNULUS ==================== + + MudSystem%MudIsChanged= .false. + +imud= 0 + + do while (imud < MudSystem%Ann_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%Ann_Mud_Backhead_X%Array(imud)= MudSystem%Ann_Mud_Forehead_X%Array(imud-1) + MudSystem%Ann_Mud_Backhead_section%Array(imud)= MudSystem%Ann_Mud_Forehead_section%Array(imud-1) + endif + + +! <<< Fracture Shoe Lost + 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) + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)-((MudSystem%Qlost/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) + if (MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then + !write(*,*) 'mud is removed by shoe lost, imud=' , imud + call RemoveAnnulusMudArrays(imud) + imud= imud-1 + cycle + endif + ENDIF +! Fracture Shoe Lost >>> + + + + + + + + + MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_PipeSection(MudSystem%Ann_Mud_Backhead_section%Array(imud))- MudSystem%Ann_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( MudSystem%Ann_MudDischarged_Volume%Array(imud) <= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%Ann_Mud_Backhead_section%Array(imud) + MudSystem%Ann_Mud_Forehead_X%Array(imud)= MudSystem%Ann_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Backhead_section%Array(imud)) + ! 7.48 is for gal to ft^3 + + else + + MudSystem%isection= MudSystem%Ann_Mud_Backhead_section%Array(imud)+1 + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > MudSystem%NoPipeSections) then ! last pipe section(well exit) + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + MudSystem%Ann_Mud_Forehead_X%Array(imud)= MudSystem%Xend_PipeSection(MudSystem%NoPipeSections) + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%NoPipeSections + + if (MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveAnnulusMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%Ann_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_PipeSection(MudSystem%isection)- MudSystem%Xstart_PipeSection(MudSystem%isection)))+ MudSystem%Xstart_PipeSection(MudSystem%isection) + exit + else + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo +!========================ANNULUS END================= + + !if ( WellisNOTFull == .false. ) then + ! write(*,*) 'MudSystem%AnnulusFlowRate==' , MudSystem%AnnulusFlowRate + ! call Set_FlowRate(real(100.*min(MudSystem%AnnulusFlowRate,PedalMeter)/(PedalMeter/10.), 8)) + ! + ! + !endif + + + +end subroutine Utube1_and_TripIn \ No newline at end of file diff --git a/Equipments/MudSystem-old/Utube2_and_Trip_In.f90 b/Equipments/MudSystem-old/Utube2_and_Trip_In.f90 new file mode 100644 index 0000000..8abe51e --- /dev/null +++ b/Equipments/MudSystem-old/Utube2_and_Trip_In.f90 @@ -0,0 +1,517 @@ +SUBROUTINE Utube2_and_TripIn ! is called in subroutine CirculationCodeSelect annulus to string + + use UTUBEVARSModule + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES + USE Pumps_VARIABLES + use CDrillWatchVariables + !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + Use CShoeVariables + + implicit none + + write(*,*) 'Utube2 code' + +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + + MudSystem%UtubeMode2Activated= .true. + write(*,*) 'QUtubeOutput=' , QUtubeOutput + !QUTubeInput=5000. + MudSystem%StringFlowRate= QUtubeOutput ! (gpm) + MudSystem%AnnulusFlowRate= QUtubeOutput + MudSystem%StringFlowRateFinal= MudSystem%StringFlowRate + MudSystem%AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate +!=========================================== + + 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 MudSystem%St_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg) + ! call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! + ! call Ann_MudDischarged_Volume%AddToFirst (REAL(sum(F_Interval((F_StringIntervalCounts+F_BottomHoleIntervalCounts+1):F_IntervalsTotalCounts)%Volume))) !startup initial + ! call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1)) + ! call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1) + ! call Ann_Mud_Forehead_X%AddToFirst (Xend_PipeSection(NoPipeSections)) + ! call Ann_Mud_Forehead_section%AddToFirst (NoPipeSections) + ! call Ann_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg) + ! call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + !Hz_Density%Array(:)= 0.0 + !Hz_MudOrKick%Array(:)= 104 + + MudSystem%Hz_Density_Utube= 0.0 + MudSystem%Hz_MudOrKick_Utube= 104 + + MudSystem%FirstSetUtube2= 1 + endif + + + + +!========================Horizontal PIPE ENTRANCE================= + + !if (SuctionDensity_Old >= (ActiveDensity+0.05) .or. SuctionDensity_Old <= (ActiveDensity-0.05)) then ! new mud is pumped + ! !ImudCount= ImudCount+1 + ! !SuctionMud= ImudCount + ! call Hz_Density%AddToFirst (REAL(ActiveDensity)) !ActiveDensity : badan in moteghayer bayad avaz beshe + ! call Hz_MudDischarged_Volume%AddToFirst (0.0d0) + ! call Hz_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(1)) + ! call Hz_Mud_Forehead_section%AddToFirst (1) + ! call Hz_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1)) + ! call Hz_Mud_Backhead_section%AddToFirst (1) + ! call Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + ! call Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + ! call Hz_MudOrKick%AddToFirst (0) + + ! deltaV= 0. + ! + ! SuctionDensity_Old= ActiveDensity + !endif + +!========================Horizontal PIPE STRING================= + + !commented + +! 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()) +! imud = imud + 1 +! +! if (imud> 1) then +! Hz_Mud_Backhead_X%Array(imud)= Hz_Mud_Forehead_X%Array(imud-1) +! Hz_Mud_Backhead_section%Array(imud)= Hz_Mud_Forehead_section%Array(imud-1) +! endif +! +! +! DirectionCoef= (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) & +! / ABS(Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) +! ! +1 for string , -1 for annulus +! +! +! Hz_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))- Hz_Mud_Backhead_X%Array(imud))* & +! Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) !(ft^3) +! Hz_EmptyVolume_inBackheadLocation%Array(imud)= Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948 ! ft^3 to gal +! +! +! if ( Hz_MudDischarged_Volume%Array(imud) <= Hz_EmptyVolume_inBackheadLocation%Array(imud)) then +! Hz_Mud_Forehead_section%Array(imud)= Hz_Mud_Backhead_section%Array(imud) +! Hz_Mud_Forehead_X%Array(imud)= Hz_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Hz_MudDischarged_Volume%Array(imud)/7.48051948)/Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) +! ! 7.48051948 is for gal to ft^3 +! else +! +! isection= Hz_Mud_Backhead_section%Array(imud)+1 +! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_EmptyVolume_inBackheadLocation%Array(imud) +! +! do +! if (isection > 1) then ! (horizontal pipe exit) +! Hz_MudDischarged_Volume%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_RemainedVolume_in_LastSection%Array(imud) +! Hz_Mud_Forehead_X%Array(imud)= Xend_PipeSection(1) +! Hz_Mud_Forehead_section%Array(imud)= 1 +! if (Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string +! call Hz_MudDischarged_Volume%Remove (imud) +! call Hz_Mud_Backhead_X%Remove (imud) +! call Hz_Mud_Backhead_section%Remove (imud) +! call Hz_Mud_Forehead_X%Remove (imud) +! call Hz_Mud_Forehead_section%Remove (imud) +! call Hz_Density%Remove (imud) +! call Hz_RemainedVolume_in_LastSection%Remove (imud) +! call Hz_EmptyVolume_inBackheadLocation%Remove (imud) +! call Hz_MudOrKick%Remove (imud) +! endif +! exit +! endif +! +! xx= Hz_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal) +! +! if (xx<= 1.0) then +! Hz_Mud_Forehead_section%Array(imud)= isection +! Hz_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection) +! exit +! else +! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection) +! isection= isection+ 1 +! +! +! endif +! +! enddo +! +! endif +! +! enddo + + !commented + +!========================Horizontal PIPE END================= + +!========================ANNULUS ENTRANCE==================== + + 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) + + MudSystem%AnnulusSuctionDensity_Old= MudSystem%Hz_Density_Utube + endif + +!========================ANNULUS==================== + + MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_MudDischarged_Volume%Length())= MudSystem%Ann_MudDischarged_Volume%Last()+ ((MudSystem%AnnulusFlowRate/60.)*MudSystem%DeltaT_Mudline) !(gal) + +imud= MudSystem%Ann_Mud_Forehead_X%Length() + 1 + + do while (imud > 1) + imud = imud - 1 + + if (imud< MudSystem%Ann_Mud_Forehead_X%Length()) then + MudSystem%Ann_Mud_Forehead_X%Array(imud)= MudSystem%Ann_Mud_Backhead_X%Array(imud+1) + MudSystem%Ann_Mud_Forehead_section%Array(imud)= MudSystem%Ann_Mud_Backhead_section%Array(imud+1) + endif + +! <<< Fracture Shoe Lost + IF ( MudSystem%ShoeLost .and. 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) + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)-((MudSystem%Qlost/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) + if (MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then + !write(*,*) 'mud is removed by shoe lost, imud=' , imud + call RemoveAnnulusMudArrays(imud) + imud= imud-1 + cycle + endif + ENDIF +! Fracture Shoe Lost >>> + + + 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 + + + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Ann_Mud_Forehead_X%Array(imud)- MudSystem%Xstart_PipeSection(MudSystem%Ann_Mud_Forehead_section%Array(imud)))* & + MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Forehead_section%Array(imud)) !(ft^3) + MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( MudSystem%Ann_MudDischarged_Volume%Array(imud) <= MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Ann_Mud_Backhead_section%Array(imud)= MudSystem%Ann_Mud_Forehead_section%Array(imud) + MudSystem%Ann_Mud_Backhead_X%Array(imud)= MudSystem%Ann_Mud_Forehead_X%Array(imud)- MudSystem%DirectionCoef*(MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Forehead_section%Array(imud)) + ! 7.48051948 is for gal to ft^3 + else + + MudSystem%isection= MudSystem%Ann_Mud_Forehead_section%Array(imud)-1 + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection < F_Counts%StringIntervalCounts+1) then ! last pipe section(well exit) F_Counts%StringIntervalCounts+1 is the first section in Annulus + MudSystem%Ann_MudDischarged_Volume%Array(imud)= MudSystem%Ann_MudDischarged_Volume%Array(imud)- MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + MudSystem%Ann_Mud_Backhead_X%Array(imud)= MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1) + MudSystem%Ann_Mud_Backhead_section%Array(imud)= F_Counts%StringIntervalCounts+1 + + if (MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveAnnulusMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Ann_Mud_Backhead_section%Array(imud)= MudSystem%isection + MudSystem%Ann_Mud_Backhead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xstart_PipeSection(MudSystem%isection)- MudSystem%Xend_PipeSection(MudSystem%isection)))+ MudSystem%Xend_PipeSection(MudSystem%isection) + exit + else + MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection- 1 + + + endif + + enddo + + endif + + enddo +!========================ANNULUS END================= + +!========================== tripping in for OP remove =============================== + + !if (DeltaVolumeOp>0. .and. DeltaVolumeOp< Op_MudDischarged_Volume%Last()) then + ! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length())= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()) - DeltaVolumeOp + !else + ! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1)= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1) - (DeltaVolumeOp-Op_MudDischarged_Volume%Last()) + ! + ! call Op_MudDischarged_Volume%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Mud_Backhead_X%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Mud_Backhead_section%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Mud_Forehead_X%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Mud_Forehead_section%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_Density%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_RemainedVolume_in_LastSection%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_EmptyVolume_inBackheadLocation%Remove (Op_MudDischarged_Volume%Length()) + ! call Op_MudOrKick%Remove (Op_MudDischarged_Volume%Length()) + !endif + ! + +!============================= Bottom Hole ============================== + + !Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux +imud=0 + do while (imud < MudSystem%Op_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + MudSystem%Op_Mud_Backhead_X%Array(imud)= MudSystem%Op_Mud_Forehead_X%Array(imud-1) + MudSystem%Op_Mud_Backhead_section%Array(imud)= MudSystem%Op_Mud_Forehead_section%Array(imud-1) + endif + + + MudSystem%DirectionCoef= (MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))) & + / ABS(MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))-MudSystem%Xstart_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))) + ! +1 for string , -1 for annulus + + + + MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%Xend_OpSection(MudSystem%Op_Mud_Backhead_section%Array(imud))- MudSystem%Op_Mud_Backhead_X%Array(imud))* & + MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Backhead_section%Array(imud)) !(ft^3) + MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( MudSystem%Op_MudDischarged_Volume%Array(imud) <= MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)) then + MudSystem%Op_Mud_Forehead_section%Array(imud)= MudSystem%Op_Mud_Backhead_section%Array(imud) + MudSystem%Op_Mud_Forehead_X%Array(imud)= MudSystem%Op_Mud_Backhead_X%Array(imud)+ MudSystem%DirectionCoef*(MudSystem%Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Backhead_section%Array(imud)) + ! 7.48051948 is for gal to ft^3 + + else + + MudSystem%isection= MudSystem%Op_Mud_Backhead_section%Array(imud)+1 + MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Op_MudDischarged_Volume%Array(imud)- MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection > F_Counts%BottomHoleIntervalCounts) then ! last pipe section(well exit) + if( imud==1) 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_Counts%BottomHoleIntervalCounts) + MudSystem%Op_Mud_Forehead_section%Array(imud)= F_Counts%BottomHoleIntervalCounts + + if (MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveOpMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%OpSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%Op_Mud_Forehead_section%Array(imud)= MudSystem%isection + MudSystem%Op_Mud_Forehead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xend_OpSection(MudSystem%isection)- MudSystem%Xstart_OpSection(MudSystem%isection)))+ MudSystem%Xstart_OpSection(MudSystem%isection) + exit + else + MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)- MudSystem%OpSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection+ 1 + + endif + + enddo + + endif + + if (MudSystem%Op_Mud_Forehead_X%Array(imud)== MudSystem%Xend_OpSection(F_Counts%BottomHoleIntervalCounts)) then + MudSystem%totalLength = MudSystem%Op_MudDischarged_Volume%Length() + do while(imud < MudSystem%totalLength) + + !imud = imud + 1 + call RemoveOpMudArrays(MudSystem%totalLength) + MudSystem%totalLength = MudSystem%totalLength - 1 + + + enddo + + exit ! + + endif + + !WRITE(*,*) imud,'Op_MudDischarged_Volume%Array(imud)' , Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) + + + + + + + enddo + + + !write(*,*) 'Op_Mud_Forehead_X%Length()' , Op_Mud_Forehead_X%Length() + ! + ! WRITE(*,*) 'Xend_PipeSection(F_StringIntervalCounts)' , Xend_PipeSection(F_StringIntervalCounts) + ! WRITE(*,*) 'Op_Mud_Backhead_X%Array(1)' , Op_Mud_Backhead_X%Array(1) + ! WRITE(*,*) 'Op_Mud_Forehead_X%Array(1)' , Op_Mud_Forehead_X%Array(1) + ! WRITE(*,*) 'Op_Mud_Backhead_X%Array(2)' , Op_Mud_Backhead_X%Array(2) + ! WRITE(*,*) 'Op_Mud_Forehead_X%Array(2)' , Op_Mud_Forehead_X%Array(2) +!========================Bottom Hole END================= + + + + + ! NO KICK + + + +!========================STRING ENTRANCE================= + + 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. 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_Counts%StringIntervalCounts)) + call MudSystem%St_Mud_Forehead_section%Add (F_Counts%StringIntervalCounts) + call MudSystem%St_Mud_Backhead_X%Add (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts)) + call MudSystem%St_Mud_Backhead_section%Add (F_Counts%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() + + MudSystem%MudIsChanged= .true. + endif + + 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=' , MudSystem%DeltaVolumeOp + if (MudSystem%DeltaVolumeOp > 0.0 .and. MudSystem%MudIsChanged== .false.) then !.and. DrillingMode== .false.) then ! trip in mode(loole paeen) + + !write(*,*) 'Tripping In' + + 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(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_Counts%StringIntervalCounts)) + MudSystem%St_Mud_Forehead_section%Array(MudSystem%St_Density%Length())= (F_Counts%StringIntervalCounts) + MudSystem%St_Mud_Backhead_X%Array(MudSystem%St_Density%Length())= (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts)) + MudSystem%St_Mud_Backhead_section%Array(MudSystem%St_Density%Length())= (F_Counts%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 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_Counts%StringIntervalCounts)) + call MudSystem%St_Mud_Forehead_section%Add (F_Counts%StringIntervalCounts) + call MudSystem%St_Mud_Backhead_X%Add (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts)) + call MudSystem%St_Mud_Backhead_section%Add (F_Counts%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 (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_Counts%StringIntervalCounts)) + MudSystem%St_Mud_Forehead_section%Array(MudSystem%St_Density%Length())= (F_Counts%StringIntervalCounts) + MudSystem%St_Mud_Backhead_X%Array(MudSystem%St_Density%Length())= (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts)) + MudSystem%St_Mud_Backhead_section%Array(MudSystem%St_Density%Length())= (F_Counts%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 + + +!========================Tripping In - End==================== + + +!======================== STRING ==================== + + MudSystem%MudIsChanged= .false. + + imud= MudSystem%St_Mud_Forehead_X%Length() + 1 + + do while (imud > 1) + imud = imud - 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 + + + 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 + + + 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 ( 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 + + MudSystem%isection= MudSystem%St_Mud_Backhead_section%Array(imud)-1 + MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= MudSystem%St_MudDischarged_Volume%Array(imud)- MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (MudSystem%isection < 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 (MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveStringMudArrays(imud) + endif + + exit + endif + + MudSystem%xx= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal) + + if (MudSystem%xx<= 1.0) then + MudSystem%St_Mud_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 + MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)- MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) + MudSystem%isection= MudSystem%isection- 1 + + endif + + enddo + + endif + + enddo +!========================STRING END================= + + + + +end subroutine Utube2_and_TripIn \ No newline at end of file diff --git a/Equipments/MudSystem/Circulation_Code_Select.f90 b/Equipments/MudSystem/Circulation_Code_Select.f90 index 1716767..a9a9e16 100644 --- a/Equipments/MudSystem/Circulation_Code_Select.f90 +++ b/Equipments/MudSystem/Circulation_Code_Select.f90 @@ -1,14 +1,14 @@ subroutine CirculationCodeSelect ! is called in subroutine Fluid_Flow_Solver - Use KickVariables + use KickVARIABLESModule Use MudSystemVARIABLES USE TD_DrillStemComponents Use CUnityInputs Use CUnityOutputs USE CKellyConnectionEnumVariables - USE UTUBEVARS + use UTUBEVARSModule use sROP_Variables - USE PressureDisplayVARIABLES + use PressureDisplayVARIABLESModule @@ -53,7 +53,7 @@ subroutine CirculationCodeSelect ! is called in subroutine Fluid_Flow_Solver if (TD_Vol%RemoveVolume > 0.) call DisconnectingPipe !! .and. Get_JointConnectionPossible() == .false.) call DisconnectingPipe - IF (KickFlux .AND. NOT(KickOffBottom)) THEN + IF (KickVARIABLES%KickFlux .AND. NOT(KickVARIABLES%KickOffBottom)) THEN call Kick_Influx endif @@ -61,13 +61,12 @@ subroutine CirculationCodeSelect ! is called in subroutine Fluid_Flow_Solver IF ( MudSystem%NewInfluxNumber > 0 ) THEN - !write(*,*) 'KickOffBottom , ROP=' , KickOffBottom , ROP_Bit%RateOfPenetration call Kick_Migration endif ! ============================ must be after migration ============================== - DO KickNumber= MudSystem%NewInfluxNumber-NoGasPocket+1 , MudSystem%NewInfluxNumber + DO KickNumber= MudSystem%NewInfluxNumber-KickVARIABLES%NoGasPocket+1 , MudSystem%NewInfluxNumber ! FINDING NEW KICK LOCATIONS: MudSystem%Ann_KickLoc= 0 MudSystem%Op_KickLoc= 0 @@ -96,7 +95,7 @@ subroutine CirculationCodeSelect ! is called in subroutine Fluid_Flow_Solver ! ============================ must be after migration-end =========================== - IF (ALLOCATED(GasPocketWeight%Array) .and. KickNumber == MudSystem%NewInfluxNumber .AND. NOT(KickOffBottom) .AND. MudSystem%WellHeadIsOpen) THEN + IF (ALLOCATED(GasPocketWeight%Array) .and. KickNumber == MudSystem%NewInfluxNumber .AND. NOT(KickVARIABLES%KickOffBottom) .AND. MudSystem%WellHeadIsOpen) THEN cycle diff --git a/Equipments/MudSystem/Disconnecting_Pipe.f90 b/Equipments/MudSystem/Disconnecting_Pipe.f90 index 832f9a1..5dc26fa 100644 --- a/Equipments/MudSystem/Disconnecting_Pipe.f90 +++ b/Equipments/MudSystem/Disconnecting_Pipe.f90 @@ -8,7 +8,7 @@ subroutine DisconnectingPipe ! is called in subroutine CirculationCodeSelect ! !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables - Use KickVariables + use KickVARIABLESModule USE TD_DrillStemComponents Use CKellyConnectionEnumVariables Use CUnityOutputs diff --git a/Equipments/MudSystem/Elements_Creation.f90 b/Equipments/MudSystem/Elements_Creation.f90 index 8b56155..d4f2273 100644 --- a/Equipments/MudSystem/Elements_Creation.f90 +++ b/Equipments/MudSystem/Elements_Creation.f90 @@ -13,7 +13,7 @@ subroutine ElementsCreation ! is called in subroutine Fluid_Flow_Solver ! !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables - Use KickVariables + use KickVARIABLESModule use CError implicit none @@ -208,7 +208,7 @@ ALLOCATE (MudSystem%Xstart_OpSection(F_Counts%BottomHoleIntervalCounts),MudSyste MudSystem%DeltaVolumePipe = INT(MudSystem%DeltaVolumePipe * 100000.d0) / 100000.d0 !DeltaVolumeAnnulusCapacity= ((Xend_PipeSection(F_Counts%StringIntervalCounts)-OldPosition))*Area_PipeSectionFt(NoPipeSections)* 7.48051948d0! ft^3 to gal - DrillStringSpeed = (MudSystem%Xend_PipeSection(F_Counts%StringIntervalCounts)-MudSystem%OldPosition) / 0.1 + KickVARIABLES%DrillStringSpeed = (MudSystem%Xend_PipeSection(F_Counts%StringIntervalCounts)-MudSystem%OldPosition) / 0.1 MudSystem%DeltaVolumeAnnulusCapacity= sum(MudSystem%PipeSection_VolumeCapacity(F_Counts%StringIntervalCounts+1:MudSystem%NoPipeSections)) - MudSystem%OldAnnulusCapacity diff --git a/Equipments/MudSystem/FillingWell_By_BellNipple.f90 b/Equipments/MudSystem/FillingWell_By_BellNipple.f90 index ab15d2e..ed83f05 100644 --- a/Equipments/MudSystem/FillingWell_By_BellNipple.f90 +++ b/Equipments/MudSystem/FillingWell_By_BellNipple.f90 @@ -11,7 +11,7 @@ subroutine FillingWell_By_BellNipple ! is called in subroutine CirculationCo !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables - Use KickVariables + use KickVARIABLESModule implicit none diff --git a/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90 b/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90 index 208b8d1..8852476 100644 --- a/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90 +++ b/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90 @@ -9,7 +9,7 @@ subroutine Kick_Expansion ! is called in subroutine CirculationCodeSelect USE sROP_Other_Variables USE sROP_Variables USE CReservoirVariables - USE KickVARIABLES + use KickVARIABLESModule implicit none @@ -132,7 +132,7 @@ subroutine Kick_Contraction ! is called in subroutine CirculationCodeSelect USE sROP_Other_Variables USE sROP_Variables USE CReservoirVariables - USE KickVARIABLES + use KickVARIABLESModule USE CError diff --git a/Equipments/MudSystem/Kick_Influx.f90 b/Equipments/MudSystem/Kick_Influx.f90 index 4c53852..910d904 100644 --- a/Equipments/MudSystem/Kick_Influx.f90 +++ b/Equipments/MudSystem/Kick_Influx.f90 @@ -8,7 +8,7 @@ subroutine Kick_Influx ! is called in subroutine CirculationCodeSelect !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables - Use KickVariables + use KickVARIABLESModule implicit none @@ -42,7 +42,7 @@ subroutine Kick_Influx ! is called in subroutine CirculationCodeSelect endif - MudSystem%Op_MudDischarged_Volume%Array(1)= MudSystem%Op_MudDischarged_Volume%Array(1)+ ((GasKickPumpFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) due to KickFlux + MudSystem%Op_MudDischarged_Volume%Array(1)= MudSystem%Op_MudDischarged_Volume%Array(1)+ ((KickVARIABLES%GasKickPumpFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) due to KickFlux !write(*,*) 'kick volume ok=' , Op_MudDischarged_Volume%Array(1) @@ -61,13 +61,13 @@ subroutine Kick_Influx ! is called in subroutine CirculationCodeSelect subroutine Instructor_CirculationMud_Edit ! is called in subroutine CirculationCodeSelect - Use KickVariables + use KickVARIABLESModule Use MudSystemVARIABLES USE TD_DrillStemComponents Use CUnityInputs Use CUnityOutputs USE CKellyConnectionEnumVariables - USE UTUBEVARS + use UTUBEVARSModule use sROP_Variables use sROP_Other_Variables use CDownHoleVariables @@ -121,18 +121,18 @@ subroutine Instructor_CirculationMud_Edit ! is called in subroutine Circulat subroutine ShoeLostSub ! is called in subroutine CirculationCodeSelect - Use KickVariables + use KickVARIABLESModule Use MudSystemVARIABLES USE TD_DrillStemComponents Use CUnityInputs Use CUnityOutputs USE CKellyConnectionEnumVariables - USE UTUBEVARS + use UTUBEVARSModule use sROP_Variables use sROP_Other_Variables use CDownHoleVariables use CShoeVariables - USE PressureDisplayVARIABLES + use PressureDisplayVARIABLESModule Use CWarningsVariables @@ -141,7 +141,7 @@ subroutine ShoeLostSub ! is called in subroutine CirculationCodeSelect MudSystem%ShoeLost= .false. MudSystem%Kickexpansion_DueToMudLost= .false. - MudSystem%ShoeMudPressure= PressureGauges(5) + MudSystem%ShoeMudPressure= PressureDisplayVARIABLES%PressureGauges(5) MudSystem%UGBOSuccessionCounter = MudSystem%UGBOSuccessionCounter + 1 diff --git a/Equipments/MudSystem/Kick_Migration.f90 b/Equipments/MudSystem/Kick_Migration.f90 index 753c44f..30d963b 100644 --- a/Equipments/MudSystem/Kick_Migration.f90 +++ b/Equipments/MudSystem/Kick_Migration.f90 @@ -9,7 +9,7 @@ subroutine Kick_Migration ! is called in subroutine CirculationCodeSelect USE sROP_Other_Variables USE sROP_Variables USE CReservoirVariables - USE KickVARIABLES + use KickVARIABLESModule implicit none @@ -39,9 +39,9 @@ subroutine Kick_Migration ! is called in subroutine CirculationCodeSelect !FirstSetKickMigration !write(*,*) 'NewInfluxNumber=' , NewInfluxNumber -DO KickNumber= MudSystem%NewInfluxNumber-NoGasPocket+1 , MudSystem%NewInfluxNumber +DO KickNumber= MudSystem%NewInfluxNumber-KickVARIABLES%NoGasPocket+1 , MudSystem%NewInfluxNumber !write(*,*) 'KickNumber=' , KickNumber - if (KickFlux .AND. NOT(KickOffBottom) .and. KickNumber == MudSystem%NewInfluxNumber) cycle + if (KickVARIABLES%KickFlux .AND. NOT(KickVARIABLES%KickOffBottom) .and. KickNumber == MudSystem%NewInfluxNumber) cycle if ( KickNumber == MudSystem%Ann_MudOrKick%Last() ) cycle ! when the last element in Annulus is kick, Migration is not called !write(*,*) 'Migration will be done for,KickNumber=' ,KickNumber diff --git a/Equipments/MudSystem/MudSystem.f90 b/Equipments/MudSystem/MudSystem.f90 index 9e89c59..49bebb8 100644 --- a/Equipments/MudSystem/MudSystem.f90 +++ b/Equipments/MudSystem/MudSystem.f90 @@ -1,8 +1,8 @@ module MudSystemModule USE MudSystemVARIABLES - USE PressureDisplayVARIABLES - USE FricPressDropVars + use PressureDisplayVARIABLESModule + USE FricPressDropVarsModule USE Fluid_Flow_Startup_Vars USE CMudPropertiesVariables USE CManifolds @@ -631,7 +631,7 @@ module MudSystemModule use CHOKEVARIABLES use CChokeManifoldVariables use CTanksVariables - Use KickVariables + use KickVARIABLESModule Use CHoistingVariables ! use CSimulationVariables @@ -778,19 +778,19 @@ module MudSystemModule !write(*,*) 'H83=' , H83 !write(*,*) 'DumpPump2=' , DumpPump2 !write(*,*) 'G83=' , G83 - PumpPressure1= jj2*(1-H82)*(1-DumpPump1)*G82* PressureGauges(1) - PumpPressure2= jj12*(1-H83)*(1-DumpPump2)*G83* PressureGauges(1) - PumpPressure3= jj13*(1-H84)*(1-DumpCementPump)*G84* PressureGauges(1) + PumpPressure1= jj2*(1-H82)*(1-DumpPump1)*G82* PressureDisplayVARIABLES%PressureGauges(1) + PumpPressure2= jj12*(1-H83)*(1-DumpPump2)*G83* PressureDisplayVARIABLES%PressureGauges(1) + PumpPressure3= jj13*(1-H84)*(1-DumpCementPump)*G84* PressureDisplayVARIABLES%PressureGauges(1) ! !write(*,*) 'jj2 , H82 , DumpPump1 , G82,PresCsureGauges(1)=' , jj2 , H82 , DumpPump1 , G82,PressureGauges(1) !write(*,*) '1)PumpPressure1=' , PumpPressure1 !write(*,*) 'PumpPressure2=' , PumpPressure2 - PumpToManifoldMudVol = 3.0 * 42.0 + FricPressDropVars%PumpToManifoldMudVol = 3.0 * 42.0 !PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP1_Q / ConvMinToSec * dt !PumpToManifoldDeltaPDueToCompressibility = PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol) IF(Mp1_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_82 .and. MP1_Q > 0.0) then - PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP1_Q / ConvMinToSec * dt - PumpPressure1= PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol) + FricPressDropVars%PumpToManifoldCompressedMudVol = FricPressDropVars%PumpToManifoldCompressedMudVol + MP1_Q / ConvMinToSec * dt + PumpPressure1= FricPressDropVars%PumpToManifoldCompressedMudVol / (MudCompressibility * FricPressDropVars%PumpToManifoldMudVol) write(*,*) '21)PumpPressure1=' , PumpPressure1 WRITE (*,*) ' valve 1 ', Manifold%Valve(1)%Status WRITE (*,*) ' valve 4 ', Manifold%Valve(4)%Status @@ -806,8 +806,8 @@ module MudSystemModule ENDIF IF(Mp2_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_83 .and. MP2_Q > 0.0 ) then - PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP2_Q / ConvMinToSec * dt - PumpPressure2= PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol) + FricPressDropVars%PumpToManifoldCompressedMudVol = FricPressDropVars%PumpToManifoldCompressedMudVol + MP2_Q / ConvMinToSec * dt + PumpPressure2= FricPressDropVars%PumpToManifoldCompressedMudVol / (MudCompressibility * FricPressDropVars%PumpToManifoldMudVol) write(*,*) '22)PumpPressure1=' , PumpPressure2 WRITE (*,*) ' -valve 1 ', Manifold%Valve(1)%Status WRITE (*,*) ' -valve 4 ', Manifold%Valve(4)%Status @@ -823,8 +823,8 @@ module MudSystemModule ENDIF IF(Cp_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_84 .AND. MP3_Q > 0.0 ) then - PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP3_Q / ConvMinToSec * dt - PumpPressure3= PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol) + FricPressDropVars%PumpToManifoldCompressedMudVol = FricPressDropVars%PumpToManifoldCompressedMudVol + MP3_Q / ConvMinToSec * dt + PumpPressure3= FricPressDropVars%PumpToManifoldCompressedMudVol / (MudCompressibility * FricPressDropVars%PumpToManifoldMudVol) ENDIF !***************************************************************************** !if(((Mp1_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_82) .or. ( PumpPressure1 >= MaxWorkingPressure1 ) & @@ -843,7 +843,7 @@ module MudSystemModule if(PumpsSpecification%MudPump1ReliefValveIsSet .and. MudSystem%Pump1BlownCount >= BlownThreshold) then write(*,*) 'valve 65 open, BLOWN' call ChangeValve(65, .TRUE.) - PumpToManifoldCompressedMudVol= 0.0 + FricPressDropVars%PumpToManifoldCompressedMudVol= 0.0 MudSystem%Pump1BlownCount = 0 !Pump1BlownStarted = .FALSE. !else @@ -871,7 +871,7 @@ module MudSystemModule if (PumpsSpecification%MudPump2ReliefValveIsSet .and. MudSystem%Pump2BlownCount >= BlownThreshold) then write(*,*) 'valve 66 open, BLOWN' call ChangeValve(66, .TRUE.) - PumpToManifoldCompressedMudVol= 0.0 + FricPressDropVars%PumpToManifoldCompressedMudVol= 0.0 MudSystem%Pump2BlownCount = 0 !Pump2BlownInTimeStep = 0 !Pump2BlownStarted = .FALSE. @@ -890,7 +890,7 @@ module MudSystemModule if (PumpsSpecification%CementPumpReliefValveIsSet .and. MudSystem%Pump3BlownCount >= BlownThreshold) then !write(*,*) 'valve 67 open, BLOWN' call ChangeValve(67, .TRUE.) - PumpToManifoldCompressedMudVol= 0.0 + FricPressDropVars%PumpToManifoldCompressedMudVol= 0.0 MudSystem%Pump3BlownCount = 0 !else ! PumpPressure3= 6000. !psi @@ -904,7 +904,7 @@ module MudSystemModule MudSystem%Pump1BlownCount = MudSystem%Pump1BlownCount + 1 if(MudSystem%Pump1BlownCount >= BlownThreshold) then call ChangeValve(65, .TRUE.) - PumpToManifoldCompressedMudVol= 0.0 + FricPressDropVars%PumpToManifoldCompressedMudVol= 0.0 call Activate_Pump1Failure() MudSystem%Pump1OffFailure= .true. MudSystem%Pump1BlownCount = 0 @@ -918,7 +918,7 @@ module MudSystemModule MudSystem%Pump2BlownCount = MudSystem%Pump2BlownCount + 1 if(MudSystem%Pump2BlownCount >= BlownThreshold) then call ChangeValve(66, .TRUE.) - PumpToManifoldCompressedMudVol= 0.0 + FricPressDropVars%PumpToManifoldCompressedMudVol= 0.0 call Activate_Pump2Failure() MudSystem%Pump2OffFailure= .true. MudSystem%Pump2BlownCount = 0 @@ -932,7 +932,7 @@ module MudSystemModule MudSystem%Pump3BlownCount = MudSystem%Pump3BlownCount + 1 if(MudSystem%Pump3BlownCount >= BlownThreshold) then call ChangeValve(67, .TRUE.) - PumpToManifoldCompressedMudVol= 0.0 + FricPressDropVars%PumpToManifoldCompressedMudVol= 0.0 call Activate_Pump3Failure() MudSystem%Pump3OffFailure= .true. MudSystem%Pump3BlownCount = 0 @@ -1571,7 +1571,7 @@ module MudSystemModule if (K79 == 1) then - MudSystem%PressureGauge75= PressureGauges(1) !String to Gauge75 + MudSystem%PressureGauge75= PressureDisplayVARIABLES%PressureGauges(1) !String to Gauge75 elseif (K82 == 1 .and. k83 == 0 .and. k84 == 0 .and. k78 == 0) then MudSystem%PressureGauge75= PumpPressure1 @@ -1603,7 +1603,7 @@ module MudSystemModule if (L79 == 1) then - MudSystem%PressureGauge76= PressureGauges(1) !String to Gauge76 + MudSystem%PressureGauge76= PressureDisplayVARIABLES%PressureGauges(1) !String to Gauge76 elseif (L82 == 1 .and. L83 == 0 .and. L84 == 0 .and. L78 == 0) then MudSystem%PressureGauge76= PumpPressure1 @@ -2221,16 +2221,29 @@ module MudSystemModule if (StudentStation%PitGainLossZero) then + DrillingWatch%PitGainLose= 0.d0 !DrillWatch MudSystem%RefrencePitVolume_DrillWatch= MudSystem%ActiveTankVolume/42. !(bbl) !DrillWatch !********************************************* + DataDisplayConsole%PitGainLossGauge= 0. !MFF Indicator MudSystem%RefrencePitVolume= MudSystem%ActiveTankVolume/42. !(bbl) !MFF Indicator + endif + + + + + + + !!====================================================================== !! MUD FLOW-FILL INDICATOR -!!====================================================================== - IF (DataDisplayConsole%MFFIPowerSwitch==1 ) THEN !.and. IsPortable==.false. +!!====================================================================== + + IF (DataDisplayConsole%MFFIPowerSwitch==1 ) THEN !.and. IsPortable==.false. + + !====================TotalStrokes Reset and Calculate====================== if (DataDisplayConsole%MFFIResetTotalStrokes == 1) then IF (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN @@ -2507,22 +2520,22 @@ module MudSystemModule MudSystem%ReserveTankDensity= MudProperties%ReserveDensity ! update from student input end subroutine - subroutine SetupMudSystem() - use CPathChangeEvents - use CMudPropertiesVariables - implicit none + ! subroutine SetupMudSystem() + ! use CPathChangeEvents + ! use CMudPropertiesVariables + ! implicit none - call BeforeTraverse%Add(InitialVarsBeforePathsChanges) - call AfterTraverse%Add(AfterPathsChanges) - call OnPathOpen%Add(WhenPathOpen) + ! call BeforeTraverse%Add(InitialVarsBeforePathsChanges) + ! call AfterTraverse%Add(AfterPathsChanges) + ! call OnPathOpen%Add(WhenPathOpen) - call OnActiveMudVolumeChange%Add(ActiveMudVolumeChanged) - call OnActiveDensityChange%Add(ActiveDensityChanged) - call OnReserveMudVolumeChange%Add(ReserveMudVolumeChanged) - call OnReserveDensityChange%Add(ReserveDensityChanged) + ! call OnActiveMudVolumeChange%Add(ActiveMudVolumeChanged) + ! call OnActiveDensityChange%Add(ActiveDensityChanged) + ! call OnReserveMudVolumeChange%Add(ReserveMudVolumeChanged) + ! call OnReserveDensityChange%Add(ReserveDensityChanged) - end subroutine + ! end subroutine subroutine AfterPathsChanges() implicit none diff --git a/Equipments/MudSystem/MudSystemStartup.f90 b/Equipments/MudSystem/MudSystemStartup.f90 index 3ecc160..3a09bf9 100644 --- a/Equipments/MudSystem/MudSystemStartup.f90 +++ b/Equipments/MudSystem/MudSystemStartup.f90 @@ -4,7 +4,7 @@ use CTanksVariables USE CMudPropertiesVariables Use GeoElements_FluidModule - Use KickVariables + use KickVARIABLESModule Use CUnityOutputs Use CShoeVariables USE Pumps_VARIABLES @@ -82,7 +82,7 @@ MudSystem%FluidFlowCounter = 0 !KickVolumeinAnnulus= 0.0 MudSystem%KickDeltaVinAnnulus= 0.0 - GasKickPumpFlowRate= 0.0 + KickVARIABLES%GasKickPumpFlowRate= 0.0 MudSystem%FirstMudSet= 0 MudSystem%FirstSetUtube1=0 @@ -122,7 +122,7 @@ MudSystem%FluidFlowCounter = 0 USE CBopStackVariables USE CPumpsVariables use CTanksVariables - USE KickVariables + use KickVARIABLESModule implicit none @@ -141,7 +141,7 @@ MudSystem%FluidFlowCounter = 0 MudSystem%DeltaT_Mudline=0.1 !second - GasKickPumpFlowRate= 0. + KickVARIABLES%GasKickPumpFlowRate= 0. MudSystem%BellNippleVolume= 0. MudSystem%BellNippleDensity= 0. MudSystem%MudBucketVolume= 0. diff --git a/Equipments/MudSystem/Plot_Final_Mud_Elements.f90 b/Equipments/MudSystem/Plot_Final_Mud_Elements.f90 index 83a2dee..e7ec89d 100644 --- a/Equipments/MudSystem/Plot_Final_Mud_Elements.f90 +++ b/Equipments/MudSystem/Plot_Final_Mud_Elements.f90 @@ -14,9 +14,9 @@ subroutine PlotFinalMudElements ! is called in subroutine CirculationCodeSel !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables - Use KickVariables + use KickVARIABLESModule USE CKellyConnectionEnumVariables - USE UTUBEVARS + use UTUBEVARSModule use CLog1 Use CError Use , intrinsic :: IEEE_Arithmetic @@ -269,13 +269,13 @@ endif !============================ UTUBE ============================= !IF (UtubePossibility== .true. .and. Get_KellyConnection() /= KELLY_CONNECTION_STRING .and. WellHeadIsOpen) THEN - IF (MudSystem%UtubePossibility== .true. .and. TD_StConn%FluidStringConnectionMode==0 .and. MudSystem%WellHeadIsOpen .AND. NoGasPocket == 0) THEN + IF (MudSystem%UtubePossibility== .true. .and. TD_StConn%FluidStringConnectionMode==0 .and. MudSystem%WellHeadIsOpen .AND. KickVARIABLES%NoGasPocket == 0) THEN CALL WellPressureDataTransfer !WRITE (*,*) ' U-Tube Done 1' CALL Utube !WRITE (*,*) ' U-Tube Done 2' - if (QUtubeInput> 0.0) call Utube1_and_TripIn - if (QUtubeOutput> 0.0) call Utube2_and_TripIn + if (UTUBEVARS%QUtubeInput> 0.0) call Utube1_and_TripIn + if (UTUBEVARS%QUtubeOutput> 0.0) call Utube2_and_TripIn END IF !========================== UTUBE- end ========================= diff --git a/Equipments/MudSystem/Pump_and_Trip_In.f90 b/Equipments/MudSystem/Pump_and_Trip_In.f90 index 95c0902..11e87d8 100644 --- a/Equipments/MudSystem/Pump_and_Trip_In.f90 +++ b/Equipments/MudSystem/Pump_and_Trip_In.f90 @@ -13,7 +13,7 @@ subroutine Pump_and_TripIn ! is called in subroutine CirculationCodeSelect !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables - Use KickVariables + use KickVARIABLESModule Use CShoeVariables use CError @@ -410,7 +410,7 @@ imud=0 if ( MudSystem%MudVolume_InjectedToBH > 0.0 ) then - if (KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the + if (KickVARIABLES%KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the AddLocation= MudSystem%Op_Density%Length()-MudSystem%iLoc+1+1 ! well, thus pumped mud should be placed above the kick else AddLocation= MudSystem%Op_Density%Length()+1 @@ -1183,8 +1183,8 @@ imud=0 !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables - Use KickVariables - USE PressureDisplayVARIABLES + use KickVARIABLESModule + use PressureDisplayVARIABLESModule Use CError Use , intrinsic :: IEEE_Arithmetic @@ -1597,8 +1597,8 @@ use CSounds !use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity !USE sROP_Other_Variables !USE sROP_Variables - !Use KickVariables - !USE PressureDisplayVARIABLES + !use KickVARIABLESModule + !use PressureDisplayVARIABLESModule !Use CError !Use , intrinsic :: IEEE_Arithmetic diff --git a/Equipments/MudSystem/Trip_Out_andPump.f90 b/Equipments/MudSystem/Trip_Out_andPump.f90 index 552a0ce..2defaab 100644 --- a/Equipments/MudSystem/Trip_Out_andPump.f90 +++ b/Equipments/MudSystem/Trip_Out_andPump.f90 @@ -13,7 +13,7 @@ subroutine TripOut_and_Pump ! is called in subroutine CirculationCodeSelect !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables - Use KickVariables + use KickVARIABLESModule Use CShoeVariables use CError @@ -427,7 +427,7 @@ imud=0 if ( MudSystem%MudVolume_InjectedToBH > 0.0 ) then - if (KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the + if (KickVARIABLES%KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the AddLocation= MudSystem%Op_Density%Length()-MudSystem%iLoc+1+1 ! well, thus pumped mud should be placed above the kick else AddLocation= MudSystem%Op_Density%Length()+1 diff --git a/Equipments/MudSystem/Utube1_and_Trip_In.f90 b/Equipments/MudSystem/Utube1_and_Trip_In.f90 index 2355530..b7aa404 100644 --- a/Equipments/MudSystem/Utube1_and_Trip_In.f90 +++ b/Equipments/MudSystem/Utube1_and_Trip_In.f90 @@ -1,6 +1,6 @@ SUBROUTINE Utube1_and_TripIn ! is called in subroutine CirculationCodeSelect string to annulus - Use UTUBEVARS + use UTUBEVARSModule Use GeoElements_FluidModule USE CMudPropertiesVariables USE MudSystemVARIABLES @@ -19,8 +19,8 @@ SUBROUTINE Utube1_and_TripIn ! is called in subroutine CirculationCodeSelect MudSystem%UtubeMode1Activated= .true. !write(*,*) 'QUTubeInput=' , QUTubeInput !Qinput=5000. - MudSystem%StringFlowRate= QUTubeInput ! (gpm) - MudSystem%AnnulusFlowRate= QUTubeInput + MudSystem%StringFlowRate= UTUBEVARS%QUTubeInput ! (gpm) + MudSystem%AnnulusFlowRate= UTUBEVARS%QUTubeInput MudSystem%StringFlowRateFinal= MudSystem%StringFlowRate MudSystem%AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate !=========================================== @@ -258,7 +258,7 @@ imud=0 !============================= Bottom Hole ============================== - !Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux + !Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((KickVARIABLES%GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux imud=0 do while (imud < MudSystem%Op_Mud_Forehead_X%Length()) imud = imud + 1 diff --git a/Equipments/MudSystem/Utube2_and_Trip_In.f90 b/Equipments/MudSystem/Utube2_and_Trip_In.f90 index a32a615..4ba0011 100644 --- a/Equipments/MudSystem/Utube2_and_Trip_In.f90 +++ b/Equipments/MudSystem/Utube2_and_Trip_In.f90 @@ -1,6 +1,6 @@ SUBROUTINE Utube2_and_TripIn ! is called in subroutine CirculationCodeSelect annulus to string - Use UTUBEVARS + use UTUBEVARSModule Use GeoElements_FluidModule USE CMudPropertiesVariables USE MudSystemVARIABLES @@ -17,10 +17,10 @@ SUBROUTINE Utube2_and_TripIn ! is called in subroutine CirculationCodeSelect !===========================================================WELL============================================================ MudSystem%UtubeMode2Activated= .true. - write(*,*) 'QUtubeOutput=' , QUtubeOutput + write(*,*) 'QUtubeOutput=' , UTUBEVARS%QUtubeOutput !QUTubeInput=5000. - MudSystem%StringFlowRate= QUtubeOutput ! (gpm) - MudSystem%AnnulusFlowRate= QUtubeOutput + MudSystem%StringFlowRate= UTUBEVARS%QUtubeOutput ! (gpm) + MudSystem%AnnulusFlowRate= UTUBEVARS%QUtubeOutput MudSystem%StringFlowRateFinal= MudSystem%StringFlowRate MudSystem%AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate !=========================================== @@ -270,7 +270,7 @@ imud= MudSystem%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 + !Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((KickVARIABLES%GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux imud=0 do while (imud < MudSystem%Op_Mud_Forehead_X%Length()) imud = imud + 1 diff --git a/FluidFlow-old/Annulus_Property_Calculator.f90 b/FluidFlow-old/Annulus_Property_Calculator.f90 new file mode 100644 index 0000000..3ddb313 --- /dev/null +++ b/FluidFlow-old/Annulus_Property_Calculator.f90 @@ -0,0 +1,45 @@ +SUBROUTINE AnnulusPropertyCalculator (md, den, pre, tem) + + !!! This subroutine gets location of a guage or an observation point and determines information of that point such as pressure, density, velocity and temperature later. + use PressureDisplayVARIABLESModule + USE Fluid_Flow_Startup_Vars + USE MudSystemVARIABLES + USE FricPressDropVarsModule + USE CDrillWatchVariables + + IMPLICIT NONE + INTEGER, intent(in) :: md ! input + REAL(8) :: TVD + real(8), intent(inout) :: den ! output + real(8), intent(inout) :: pre ! output + real(8), intent(inout) :: tem ! output + + + INTEGER :: ilocal + + CALL TVD_Calculator(md * 1.d0 , TVD) + + IF (md <= INT(FinalFlowEl(AnnulusFirstEl)%StartX)) THEN !! mouse pointer is in the annulus space + DO ilocal = AnnulusFirstEl , AnnulusLastEl + IF (INT(FinalFlowEl(ilocal)%EndX) <= md) EXIT + END DO + + ELSE IF (md > INT(FinalFlowEl(NumbEl)%EndX)) THEN ! mouse pointer is in the open hole space + DO ilocal = OpenholeFirstEl , NumbEl + IF (INT(FinalFlowEl(ilocal)%EndX) <= md) EXIT + END DO + + ELSE + WRITE (*,*) ' Error in calculating annulus observation point ' + END IF + pre = FinalFlowEl(ilocal)%StartPress - (FinalFlowEl(ilocal)%StartX - md) * FinalFlowEl(ilocal)%dPdLfric & + - (FinalFlowEl(ilocal)%StartTVD - TVD) * FinalFlowEl(ilocal)%dPdLGrav + !write(*,*) ' md, ilocal', md, ilocal + !WRITE (*,*) ' FlowEl dPdLfric , dPdLGrav', FlowEl(ilocal)%dPdLfric , FlowEl(ilocal)%dPdLGrav + + den = FinalFlowEl(ilocal)%Density + + !tem = 500 + + + END SUBROUTINE \ No newline at end of file diff --git a/FluidFlow-old/Annulus_and_Openhole_Pressure_Distribution.f90 b/FluidFlow-old/Annulus_and_Openhole_Pressure_Distribution.f90 new file mode 100644 index 0000000..56478cb --- /dev/null +++ b/FluidFlow-old/Annulus_and_Openhole_Pressure_Distribution.f90 @@ -0,0 +1,337 @@ +SUBROUTINE PressureAnnAndOHDistribution + + !! Record of revisions + !! Date Programmer Discription of change + !! ------ ------------ ----------------------- + !! 1396/07/30 Sheikh Original code + !! + + USE FricPressDropVarsModule + USE MudSystemVARIABLES + use PressureDisplayVARIABLESModule + USE GeoElements_FluidModule + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule + USE CMudPropertiesVariables + USE TD_WellGeometry + USE CReservoirVariables + use MudSystemModule + USE CHOKEVARIABLES + USE CChokeManifoldVariables + USE VARIABLES + USE CError + USE , INTRINSIC :: IEEE_ARITHMETIC + + + IMPLICIT NONE + + INTEGER :: i , j , k , l + INTEGER :: ifric + REAL :: Fraction + + + KBOP = 0.0 + + + +IF (WellHeadOpen .OR. NoGasPocket == 0) THEN !! (mud circulation is normal wellhead may be open or closed) OR (kick is in the well and well head is open) + + + !!!!! Determining flow rate in each section + i = AnnulusFirstEl + j = OpenholeFirstEl - 1 + + !!!!!!!!!!!!!!!!!!!!!!!!! flowrates due to external sources like pump and tripping + !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(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 = MudSystem%AnnulusFlowRate + (DeltaVolumePipe * ConvMinToSec / dt) + !END IF + + 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 = - 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 - MudSystem%Qlost + END IF + END IF + + + !!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!! initial guess flowrates for opening BOP or choke line + IF (WellHeadWasOpen == .FALSE. .AND. NoGasPocket > 0 .AND. KickIteration == 1) THEN + IF (ChokeKroneckerDelta == 1) THEN ! flow on choke line + IF (TotalOpenChokeArea < 0.01 * Choke%ChokeAreaFullyOpen) THEN + WRITE (*,*) 'density , TotalOpenChokeArea' , DownHole%Density, TotalOpenChokeArea + TotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen + END IF + Kchoke = (ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * TotalOpenChokeArea)**2)) * 4.0 ! *4.d0: seyyed gofte + GasPocketFlowInduced%Array(:) = MIN((0.6 / NoGasPocket * SQRT(PressureGauges(2) / Kchoke)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) + WRITE (*,*) ' PressureGauges(2) , Kchoke' , PressureGauges(2) , Kchoke + WRITE (*,*) 'Initial guess after opening choke =', GasPocketFlowInduced%Array(1) + + WRITE (*,*) ' valve 49 ', Manifold%Valve(49)%Status + WRITE (*,*) ' valve 47 ', Manifold%Valve(47)%Status + WRITE (*,*) ' valve 26 ', Manifold%Valve(26)%Status + WRITE (*,*) ' valve 30 ', Manifold%Valve(30)%Status + WRITE (*,*) ' valve 34 ', Manifold%Valve(34)%Status + WRITE (*,*) ' valve 63 ', Manifold%Valve(63)%Status + WRITE (*,*) ' valve 28 ', Manifold%Valve(28)%Status + WRITE (*,*) ' valve 33 ', Manifold%Valve(33)%Status + WRITE (*,*) ' valve 62 ', Manifold%Valve(62)%Status + WRITE (*,*) ' valve 36 ', Manifold%Valve(36)%Status + WRITE (*,*) ' valve 38 ', Manifold%Valve(38)%Status + + ELSE ! flow through bell nipple + k = NoHorizontalEl + NoStringEl + NoAnnulusEl + KBOP = FlowEl(AnnulusLastEl)%Density / ((2.0 * 89158.0) * (0.26 * 0.61 * ShearRam%MinimumOpenArea_InBOP)**2) + GasPocketFlowInduced%Array(:) = MIN((0.1 / NoGasPocket * SQRT(PressureGauges(6) / KBOP)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) + WRITE (*,*) 'PressureGauges(6), KBOP', PressureGauges(6), KBOP + WRITE (*,*) 'Initial guess after opening BOP =', GasPocketFlowInduced%Array(1) + END IF + END IF + !!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!!!!! flowrates due to expansion of gas pockets or kick influx + !i = AnnulusFirstEl + !j = OpenholeFirstEl - 1 + IF (NoGasPocket > 0) THEN + DO l = 1 , NoGasPocket !GasPocketFlowEl + k = GasPocketFlowEl(l , 1) + !WRITE (*,*) 'GasPocketFlowEl(l , 1)', l, k, j + IF (k == 0) CALL ERRORSTOP('GasPocketFlowEl(l , 1) == 0', l) + + IF (k >= OpenholeFirstEl) THEN ! gas pocket is in open hole only + FlowEl(k : NumbEl)%FlowRate = FlowEl(k : NumbEl)%FlowRate + GasPocketFlowInduced%Array(l) ! openhole elements above pocket + FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate = FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus and choke line elements + ELSE IF (k < OpenholeFirstEl) THEN ! gas pocket is in annulus ond/or choke line only + FlowEl(k : OpenholeFirstEl - 1)%FlowRate = FlowEl(k : OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus or choke line elements above pocket + END IF + END DO + END IF + !IF (ChokeKroneckerDelta == 1 .AND. ABS(FlowEl(i + NoAnnulusEl)%FlowRate / 600.0 - Ann_Saved_MudDischarged_Volume_Final) > 0.05) THEN + ! WRITE (*,*) 'Difference between flowrates', FlowEl(i + NoAnnulusEl + 1)%FlowRate / 600.0, Ann_Saved_MudDischarged_Volume_Final + !END IF + + !!!!!!!!!!!!!!!!!!!!!!!!! + !!!!! END - Determining flow rate in each section + + !!!!!!!!!!!!!!!!!!!!!!!!! effect of surge and swab on frictional pressure drop direction + DO l = AnnulusFirstEl , OpenholeFirstEl - 1 + IF (FlowEl(l)%FlowRate < 0.0) THEN + FlowEl(l)%FrictionDirection = -1 + IF (FlowEl(l)%FlowRate > -1.0 * PressFlowrateTolerance .AND. ALLOCATED(GasPocketWeight%Array)) FlowEl(l)%FlowRate = - PressFlowrateTolerance + ELSE + FlowEl(l)%FrictionDirection = 1 + IF (FlowEl(l)%FlowRate < PressFlowrateTolerance .AND. ALLOCATED(GasPocketWeight%Array)) FlowEl(l)%FlowRate = PressFlowrateTolerance + END IF + END DO + !!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!!!!! Calculating Back Pressure, in well to pit path back pressure = 0 + ! in well to choke manifold path back pressure is equal to pressure before choke not casing pressure + IF (ChokeKroneckerDelta == 1) THEN + + IF (FlowEl(OpenholeFirstEl - 1)%FlowRate < 0.0) THEN + WRITE (*,*) ' Negative choke flowrate' + 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) + 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 (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 + !WRITE (*,*) 'Total Open Choke Area Percent' , TotalOpenChokeArea / 4.0 * ChokeAreaFullyOpen + ELSE + BackPressure = 0.0 + END IF + IF (IEEE_IS_NaN(BackPressure)) CALL ErrorStop('NaN in calculating back pressure' , FlowEl(j)%FlowRate) + !write(*,*) 'BackPressure=' , BackPressure + + !!!!!!!!!!!!!!!!!!!!!!!!! when flow passes through choke manifold, solution process may be unstable + IF (ChokeKroneckerDelta == 1) THEN ! thus we should stabilize solution + IF (TotalOpenChokeArea > 0.5 * Choke%ChokeAreaFullyOpen) THEN + KickCorrectionUnderRelaxation = 0.6 + ELSE IF (TotalOpenChokeArea > 0.1 * Choke%ChokeAreaFullyOpen) THEN + KickCorrectionUnderRelaxation = 0.5 + ELSE ! TotalOpenChokeArea < 0.1 * ChokeAreaFullyOpen + KickCorrectionUnderRelaxation = 0.4 + END IF + ELSE + KickCorrectionUnderRelaxation = 0.6 + END IF + !!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!!!!! calculating frictional pressure drop in annulus, chooke line and open hole elements + DO ifric = AnnulusFirstEl , NumbEl + CALL FricPressDrop(ifric) + !WRITE (*,*) ' element No, FlowRate , Density, FricPressLoss', ifric, FlowEl(ifric)%FlowRate, FlowEl(ifric)%Density, FlowEl(ifric)%FricPressLoss + IF (IEEE_IS_NaN(FlowEl(ifric)%FricPressLoss)) THEN + WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl + WRITE (*,*) 'Ann/Op start, end, density, Q, mu, Type' , FlowEl(ifric)%StartX, FlowEl(ifric)%EndX, FlowEl(ifric)%Density, FlowEl(ifric)%FlowRate, FlowEl(ifric)%mueff, FlowEl(ifric)%MaterialType + CALL ErrorStop('NaN in calculating pressure drop' , ifric) + END IF + + END DO + !IF (ChokeKroneckerDelta == 1) THEN + !WRITE (*,*) ' velocity and flowrate', FlowEl(i)%vel, FlowEl(i)%flowrate + !WRITE (*,*) ' Theta600, Theta300', FlowEl(i)%Theta600 , FlowEl(i)%Theta300 + !WRITE (*,*) ' kIndex , nIndex', FlowEl(i)%kIndex, FlowEl(i)%nIndex + !WRITE (*,*) ' last el. mueff, gen. Rey.', i, FlowEl(i)%mueff, FlowEl(i)%GenRe + !END IF + + !!!!!!!!!!!!!!!!!!!!!!!!! Pressure distribution in annulus + j = OpenholeFirstEl - 1 + FlowEl(OpenholeFirstEl - 1)%EndPress = BackPressure + FlowEl(OpenholeFirstEl - 1)%StartPress = FlowEl(OpenholeFirstEl - 1)%EndPress + FlowEl(OpenholeFirstEl - 1)%FricPressLoss + FlowEl(OpenholeFirstEl - 1)%StaticPressDiff + + !write(*,*) 'FlowEl(j)%StartPress=' ,j, FlowEl(j)%StartPress + !write(*,*) 'FlowEl(j)%Length=' ,j, FlowEl(j)%Length, FlowEl(j)%EndX + !write(*,*) 'FlowEl(i)%dPdLFric=' ,i, FlowEl(i)%dPdLFric + + DO l = OpenholeFirstEl - 2 , AnnulusFirstEl , -1 + !WRITE (*,*) '123' + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%FricPressLoss + FlowEl(l)%StaticPressDiff + !WRITE(*,*) "ANNULUS: bottom , top Pressure", l , FlowEl(l)%StartPress , FlowEl(l)%EndPress , FlowEl(l)%fricPressLoss + !WRITE(*,*) "ANNULUS: Start , End X", FlowEl(l)%StartX , FlowEl(l)%EndX + + + !write(*,*) 'FlowEl(i)%StartPress=' ,i, FlowEl(i)%StartPress + !WRITE (*,*) ' FlowEl(i)%GenRe, FlowEl(i)%ReCritLam ' , FlowEl(i)%GenRe , FlowEl(i)%ReCritLam + END DO + + + !!!!!!!!!!!!!!!!! Pressure distribution in Open Hole + FlowEl(NumbEl)%EndPress = FlowEl(AnnulusFirstEl)%StartPress + FlowEl(NumbEl)%StartPress = FlowEl(NumbEl)%EndPress + FlowEl(NumbEl)%FricPressLoss + FlowEl(NumbEl)%StaticPressDiff + !WRITE (*,*) 'op top and op down' , FlowEl(NumbEl)%EndPress, FlowEl(j + 1)%StartPress + !write(*,*) 'FlowEl(NumbEl)%dPdLFric=' , FlowEl(NumbEl)%dPdLFric + !write(*,*) 'FlowEl(NumbEl)%dPdLGrav=' , FlowEl(NumbEl)%dPdLGrav + + DO l = NumbEl - 1 , OpenholeFirstEl , -1 + !WRITE(*,*) ' ope' + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + !IF (FlowEl(i)%FlowRate < 0.0d0) THEN + ! FlowEl(i)%StartPress = FlowEl(i)%EndPress - FlowEl(i)%FricPressLoss + FlowEl(i)%StaticPressDiff + !ELSE + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%FricPressLoss + FlowEl(l)%StaticPressDiff + !WRITE (*,*) ' Length, static, frictional open' , FlowEl(i)%Length, FlowEl(i)%StaticPressDiff, FlowEl(i)%FricPressLoss + + !END IF + END DO + +ELSE ! wellhead is closed and kick is in the well + !WRITE (*,*) ' well head is closed' + k = GasPocketFlowEl(NoGasPocket , 1) + !WRITE (*,*) 'k, Pocket Press', k, GasPocketOldPress%Array(NoGasPocket) - StandardPress + i = AnnulusFirstEl + j = OpenholeFirstEl - 1 + FlowEl(k)%StartPress = GasPocketOldPress%Array(NoGasPocket) - StandardPress + FlowEl(k)%EndPress = GasPocketOldPress%Array(NoGasPocket) - StandardPress + IF (k > OpenholeFirstEl - 1) THEN ! Top pocket StartX is in Open hole + !WRITE (*,*) 'here 1' + DO l = k - 1 , OpenholeFirstEl , -1 ! below elements in openhole + !WRITE (*,*) 'here 1-1' + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff + END DO + + DO l = k + 1 , NumbEl ! Above elements in openhole + !WRITE (*,*) 'here 1-2' + FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress + FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff + END DO + + FlowEl(AnnulusFirstEl)%StartPress = FlowEl(NumbEl)%EndPress + FlowEl(AnnulusFirstEl)%EndPress = FlowEl(AnnulusFirstEl)%StartPress - FlowEl(AnnulusFirstEl)%StaticPressDiff + + DO l = AnnulusFirstEl + 1 , OpenholeFirstEl - 1 + FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress + FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff + END DO + + ELSE ! Top pocket StartX is in annulus or choke line + + DO l = k - 1 , AnnulusFirstEl , -1 ! below elements in annnulus + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff + END DO + + DO l = k + 1 , OpenholeFirstEl - 1 ! Above elements in annulus + FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress + FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff + END DO + + FlowEl(NumbEl)%EndPress = FlowEl(AnnulusFirstEl)%StartPress + FlowEl(NumbEl)%StartPress = FlowEl(NumbEl)%EndPress + FlowEl(NumbEl)%StaticPressDiff + + DO l = NumbEl - 1 , OpenholeFirstEl , -1 + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff + END DO + + END IF + + ! + ! !WRITE (*,*) ' first annulus bottom pressure ' , FlowEl(NoHorizontalEl + NoStringEl + 1)%StartPress + ! !WRITE (*,*) ' last OpenHole bottom pressure' , FlowEl(NumbEl)%StartPress + ! !WRITE (*,*) ' Gas Pocket pressure' , GasPocket%NewPress +END IF + + !!!!!!!!!!!!!!!!!!!!!! checking pressure for preventing NaN in pressures + DO l = OpenholeFirstEl - 1 , AnnulusFirstEl , -1 ! annulus or choke elements + !WRITE (*,*) 'start, end' , FlowEl(i)%StartX, FlowEl(i)%EndX + IF (IEEE_IS_NaN(FlowEl(l)%EndPress)) THEN + WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl + WRITE (*,*) 'Ann/Ch start, end, density, Q, mu' , FlowEl(l)%StartX, FlowEl(l)%EndX, FlowEl(l)%Density, FlowEl(l)%FlowRate, FlowEl(l)%mueff, FlowEl(l)%MaterialType + CALL ERRORSTOP('NaN in EndPress', l) + END IF + END DO + + DO l = NumbEl , OpenholeFirstEl - 1 , -1 ! op elements + !WRITE (*,*) 'start, end' , FlowEl(i)%StartX, FlowEl(i)%EndX + IF (IEEE_IS_NaN(FlowEl(l)%EndPress)) THEN + WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl + WRITE (*,*) 'Op start, end, density, Q, mu' , FlowEl(l)%StartX, FlowEl(l)%EndX, FlowEl(l)%Density, FlowEl(l)%FlowRate, FlowEl(l)%mueff, FlowEl(l)%MaterialType + CALL ERRORSTOP('NaN in EndPress', l) + END IF + END DO + !!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!! + BottomHolePress = FlowEl(OpenholeFirstEl)%StartPress + !DO i = 1 , NoGasPocket + ! WRITE (*,*) ' Pocket, Pressure, Vol, Flow Induced, FlowElPress', i, REAL(GasPocketNewPress%Array(i)), REAL(GasPocketNewVol%Array(i)), GasPocketFlowInduced%Array(i), FlowEl(GasPocketFlowEl(i , 1))%StartPress + !END DO + !WRITE (*,*) ' BottomHolePress =' , BottomHolePress + !!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !IF (ChokeKroneckerDelta == 1) THEN + ! 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 + !END IF + + !IF (GasPocket%ElementNo == 0) THEN + ! KickUnknownVector(2) = BottomHolePress + !!ELSE + !! KickUnknownVector(2) = FlowEl(GasPocket%ElementNo)%StartPress + !END IF + !IF (WellHeadOpen) + ! GasPocket%NewPress = KickUnknownVector(2) + !END IF + !WRITE (*,*) 'Ann End' +END SUBROUTINE \ No newline at end of file diff --git a/FluidFlow-old/Flow_Startup.f90 b/FluidFlow-old/Flow_Startup.f90 new file mode 100644 index 0000000..f7704a7 --- /dev/null +++ b/FluidFlow-old/Flow_Startup.f90 @@ -0,0 +1,118 @@ +SUBROUTINE FlowStartup + Use ConfigurationVariables + USE Fluid_Flow_Startup_Vars + USE CStringConfigurationVariables + USE CMudPropertiesVariables + USE FricPressDropVarsModule + use KickVARIABLESModule + USE MudSystemVARIABLES + use PressureDisplayVARIABLESModule + USE CShoeVariables + USE TD_DrillStemComponents + USE TD_WellGeometry, pi3 => pi + USE CPathGenerationVariables + USE CWellSurveyDataVariables + Use CHOKEVARIABLES, pi4 => pi + + + IMPLICIT NONE + + INTEGER :: i + + PressureGauges(:) = 0.0 + + KickSinglePocket = Reservoir%MakeKickSinglePacket + IF (KickSinglePocket) THEN + MaxGasPocket = 1 + ELSE + MaxGasPocket = 4 + END IF + MaxChokeDensityChange = 25.0 ! [ppg/min] + ChokeMinDensity = 2.0 + + ChokeDensity = MudProperties%ActiveDensity + + MinKickVol = 0.5 ! USGal + + SecondaryKickVol = 0.0 + SecondaryKickWeight = 0.0 + + NoGasPocket = 0 ! No Kick + WellHeadOpen = .TRUE. + WellHeadWasOpen = .TRUE. + BackPressure = 0.0 + GasKickPumpFlowRate = 0.0 + DownHole%KickVolume = 0.0 + DownHole%InfluxRate = 0.0 + ExitMass = 0.0 + MinAllowableKickVol = 1.0 * (42.0 / Convft3toUSgal) ! 1 bbl * 42 gal/bbl / 7.48 gal/ft^3 = ... ft^3 + StCompressedMudVol = 0.0 + AnnCompressedMudVol = 0.0 + KickFlux = .FALSE. + KickOffBottom = .FALSE. + KickWasExitingThroughChoke = .FALSE. + FloatValveOpen = .TRUE. + + Choke%ChokeAreaFullyOpen = 123.0 / 64.0 ! fully open area is 123/64 in^2 = 0.01334635 ft^2 + ChokeBypassArea = PI / 4.0 * BopStackSpecification%ChokeLineId**2 + BHPSafetyMargin = 150.0 + AChBHPTol = 15.0 + + + ManChoke1Plug = 0 + ManChoke2Plug = 0 + ManChoke1Washout = 0 + ManChoke2Washout = 0 + BitJetsPlugged = 0 + BitJetsWashedOut = 0 + CasingPressure_DataDisplayMalF = 0 + + SoundSpeed = 1530.0 / Convfttom + PressureTimeStepDelay(1) = INT(2.0 * SUM(Configuration%StringConfiguration%StringConfigurations(2:)%ComponentLength) / SoundSpeed / dt) + PressureTimeStepDelay(2) = INT(PathGeneration%Items(SIZE(PathGeneration%Items))%MeasuredDepth / SoundSpeed / dt) + PressureTimeStepDelay(3) = INT(Shoe%ShoeDepth / SoundSpeed / dt) + + !WRITE (*,*) SUM(StringConfigurations(2:)%ComponentLength), PathGenerations(SIZE(PathGenerations))%TotalVerticalDepth!, WellSurveyData(SIZE(WellSurveyData))%TotalVerticalDepth + !WRITE (*,*) PathGenerations(SIZE(PathGenerations))%MeasuredDepth!, WellSurveyData(SIZE(WellSurveyData))%MeasuredDepth + WRITE (*,*) 'time step delay', PressureTimeStepDelay + + DO i = 1 , PressureTimeStepDelay(1) + CALL PumpPressureDelay%AddToFirst(0.0) + END DO + + DO i = 1 , PressureTimeStepDelay(2) + CALL BottomHolePressureDelay%AddToFirst(REAL(0.052 * MudProperties%ActiveDensity * PathGeneration%Items(SIZE(PathGeneration%Items))%TotalVerticalDepth)) + END DO + + DO i = 1 , PressureTimeStepDelay(3) + CALL ShoePressureDelay%AddToFirst(REAL(0.052 * MudProperties%ActiveDensity * Shoe%ShoeDepth)) + END DO + + + !!!!!!! Methane Information + GasType(1)%CritPress = 673.0 + GasType(1)%CritTemp = 344.0 + GasType(1)%MolarWt = 16.04 + GasType(1)%StDensity = 0.04238 + GasType(1)%GasConstant = RUniversal / GasType(1)%MolarWt + + !!!!!!!! H2S Information + GasType(2)%CritPress = 1306.0 + GasType(2)%CritTemp = 673.0 + GasType(2)%MolarWt = 34.08 + GasType(2)%StDensity = 0.09087 + GasType(2)%GasConstant = RUniversal / GasType(2)%MolarWt + + !!!!!!!! CO2 Information + GasType(3)%CritPress = 1072.0 + GasType(3)%CritTemp = 548.0 + GasType(3)%MolarWt = 44.01 + !GasType(3)%StDensity = 00 + GasType(3)%GasConstant = RUniversal / GasType(2)%MolarWt + + !!!!!!!! Mud density and viscosity + Theta600Refrence = MudProperties%ActiveThetaSixHundred + Theta300Refrence = MudProperties%ActiveThetaThreeHundred + DensityRefrence = MudProperties%ActiveDensity + + END SUBROUTINE \ No newline at end of file diff --git a/FluidFlow-old/Flow_Startup_VARIABLES.f90 b/FluidFlow-old/Flow_Startup_VARIABLES.f90 new file mode 100644 index 0000000..f47a842 --- /dev/null +++ b/FluidFlow-old/Flow_Startup_VARIABLES.f90 @@ -0,0 +1,64 @@ +MODULE Fluid_Flow_Startup_Vars + + !!! In this module constants and conversion factors are stated + + + REAL , PARAMETER :: RUniversal = 10.73159 ! [psia.ft^3/(lbmole.R)] + REAL , PARAMETER :: RUniversalSI = 8.314 * 10**6 ! [Pa.cm^3/(mole.K)] + REAL , PARAMETER :: PI = 3.141593 ! Pi number + REAL , PARAMETER :: StandardPress = 14.7 ! [psia] + REAL , PARAMETER :: StandardTemp = 519.67 ! 60 F [R] , Temp F = Temp R + 459.67 + REAL , PARAMETER :: dt = 0.1 ! time step = 0.1 [s] + REAL , PARAMETER :: GasDensityRefrence = 28.96 ! molar weight of air [lbm/lbmole] + + !! Tolerance and convergence or error criteria + REAL , PARAMETER :: UTubePressTolerance = 4 ! minimum pressure tolerance between two arms of U tube for which calculations will stop [psi] + !REAL , PARAMETER :: PressDensityTolerance = 2 ! Pressure Density Tolerance: for flow elements with density below this amount (usually gas pockets), + ! frictional and gravitional pressure gradients are neglected [ppg] + REAL , PARAMETER :: PressLengthTolerance = 0.0 ! Pressure Length Tolerance: for flow elements with length below this amount, + ! frictional and gravitional pressure gradients are neglected [ft] + REAL , PARAMETER :: PressFlowrateTolerance = 0.2 ! Pressure Flowrate Tolerance: for flow elements with flowrates below this amount, + ! frictional pressure gradients are neglected [gpm] + REAL , PARAMETER :: KickConvergenceTolerance = 0.05 ! absolute value of maximum error in calculation of gas kick pressure and flowrate + + !!!!!!!!!!!!!!!!!! Conversion factors + REAL , PARAMETER :: Convlbftolbm = 32.174 ! 1 lbf = 32.174 lbm*ft/s^2 + REAL , PARAMETER :: Convft3toUSgal = 7.48052 ! 1 ft^3 = 7.48052 US gal + REAL , PARAMETER :: Convfttom = 0.3048 ! 1 ft = 0.3048 m + REAL , PARAMETER :: Convfttoinch = 12.0 ! 1 ft = 12 inch + REAL , PARAMETER :: Convdaytohour = 24.0 ! 1 day = 24 hour + REAL , PARAMETER :: Convhourtomin = 60.0 ! 1 hour = 60 min + REAL , PARAMETER :: Convmintosec = 60.0 ! 1 min = 60 sec + REAL , PARAMETER :: ConvpsitoPa = 6894.76 ! 1 psi = 6894.76 pa + REAL , PARAMETER :: ConvRtoK = 0.555556 ! 1 R = 0.555556 K + REAL , PARAMETER :: Convpcftogpcm3 = 0.0160185 ! 1 lbm/ft^3 = 0.0160185 gr/cm^3 + !!!!!!!!!!!!!!!!! + + !!!!!!! Bit data !!!!!! + ! Type :: BitDataType + LOGICAL :: BitTrue ! bit may be present (.TRUE.) or may be absent(.FALSE.) + REAL :: BitNozzleArea ! area of a nozzle + INTEGER :: BitNozzleNum ! Number of bit nozzles + REAL :: BitNozzDia ! nozzle diameter in 1/32 in + REAL :: BitTotNozzArea ! Total bit area + REAL :: BitCd ! Discharge coefficient + REAL :: BitPressLoss ! bit pressure loss [psi] + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + REAL :: Theta600Refrence , Theta300Refrence ! Fann data (Theta600 and Theta300) of active tank (input from panel) + REAL :: DensityRefrence ! Density of active tank mud (input from panel) [gpm] + ! End Type BitDataType + ! Type(BitDataType)::BitData + + TYPE, PUBLIC :: GasData + REAL :: CritPress ! critical pressure [psia] + REAL :: CritTemp ! critical temperature [R] + REAL :: MolarWt ! molar weight [lbm/lbmole] + REAL :: StDensity ! density at standard pressure (14.7 psi) and temperature (60 F = 520 Ra) [lbm/ft^3] + REAL :: GasConstant ! Gas constant = RUniversal/MolarWt [psia.ft^3/(R.lbm)] + END TYPE GasData + TYPE(GasData) :: GasType(3) ! 1 = methane , 2 = Hydrogen sulfide , 3 = Carbon dioxid + + + END MODULE + \ No newline at end of file diff --git a/FluidFlow-old/FluidFlowMain.f90 b/FluidFlow-old/FluidFlowMain.f90 new file mode 100644 index 0000000..a91cc79 --- /dev/null +++ b/FluidFlow-old/FluidFlowMain.f90 @@ -0,0 +1,147 @@ +module FluidFlowMain + implicit none + public + contains +! + ! subroutine FluidFlow_Setup() + ! ! use CSimulationVariables + ! implicit none + ! !call OnSimulationInitialization%Add(FluidFlow_Init) + ! call OnSimulationStop%Add(FluidFlow_Stop) + ! call OnFluidFlowStart%Add(FluidFlow_Start) + ! call OnFluidFlowStep%Add(FluidFlow_Step) + ! !call OnFluidFlowOutput%Add(FluidFlow_Output) + ! call OnFluidFlowMain%Add(FluidFlowMainBody) + ! end subroutine + + ! subroutine FluidFlow_Stop + ! implicit none + ! !WRITE (*,*) ' fluid flow done_Stop' + ! call DEALLOCATE_ARRAYS_NormalCirculation() + ! CALL DeallocateFlowTypes + ! end subroutine FluidFlow_Stop + + subroutine FluidFlow_Init + USE Fluid_Flow_Startup_Vars + implicit none + !WRITE (*,*) ' fluid flow done_Start' + CALL NormalCirculation_StartUp() + CALL FlowStartup + + Call TD_StartUp + Call TD_WellReadData + Call TD_WellElementsReadData + Call TD_DrillStemReadData + Call TD_PipePropertiesReadData + end subroutine FluidFlow_Init + + subroutine FluidFlow_Step + implicit none + integer :: i, FlowDuration, SimulationStateOld + integer,dimension(8) :: FlowStartTime,FlowEndTime + + !WRITE (*,*) ' fluid flow done_Step' + !call Fluid_Flow_Solver + + + + + + + CALL DATE_AND_TIME(values=FlowStartTime) + call Fluid_Flow_Solver + + CALL DATE_AND_TIME(values=FlowEndTime) + + FlowDuration = 3600000 * (FlowEndTime(5) - FlowStartTime(5)) + 60000 * (FlowEndTime(6) - FlowStartTime(6)) + 1000 * (FlowEndTime(7) - FlowStartTime(7)) + (FlowEndTime(8) - FlowStartTime(8)) + + WRITE (*,*) 'FlowDuration (ms)=' , FlowDuration + + end subroutine FluidFlow_Step + + !subroutine FluidFlow_Output + ! implicit none + !end subroutine FluidFlow_Output + +! subroutine FluidFlowMainBody +! ! +! use ifport +! use ifmt +! ! use CSimulationVariables +! USE Fluid_Flow_Startup_Vars +! !use general_info, only : reset_data +! !use well_info +! !use drilling_info +! use CLog1 +! ! +! implicit none + + !integer :: i, FlowDuration, SimulationStateOld + !integer,dimension(8) :: FlowStartTime,FlowEndTime + ! + ! + !CALL NormalCirculation_StartUp() + !CALL FlowStartup + ! + !Call TD_StartUp + !Call TD_WellReadData + !Call TD_WellElementsReadData + !Call TD_DrillStemReadData + !Call TD_PipePropertiesReadData + ! + ! + !LoopSimulation: do + ! !WRITE (*,*) ' fluid flow done 0' + !! + ! CALL DATE_AND_TIME(values=FlowStartTime) + ! !WRITE (*,*) 'FlowStartTime=', FlowStartTime + !! + ! call Fluid_Flow_Solver + ! + !! + ! CALL DATE_AND_TIME(values=FlowEndTime) + !! + ! !WRITE (*,*) ' fluid flow done 1' + ! + ! + ! + ! FlowDuration = 3600000 * (FlowEndTime(5) - FlowStartTime(5)) + 60000 * (FlowEndTime(6) - FlowStartTime(6)) + 1000 * (FlowEndTime(7) - FlowStartTime(7)) + (FlowEndTime(8) - FlowStartTime(8)) + ! + ! + ! !call Log_1('FlowDuration=', FlowDuration) + ! !WRITE (*,*) 'FlowDuration (ms)=' , FlowDuration + ! + ! if ((100 - FlowDuration) > 0) then + ! !WRITE (*,*) 'fluid flow done 2' + ! call sleepqq(100 - FlowDuration) + ! !WRITE (*,*) ' fluid flow done 3' + ! + ! end if + ! !WRITE (*,*) ' fluid flow done 4' + ! + ! + ! + ! !WRITE (*,*) "FlowDuration", FlowDuration + ! !if(IsStopped) then + ! ! EXIT LoopSimulation + ! !ENDIF + ! !write(*,*) 'IsStopped=' , IsStopped + ! + ! if(IsStopped) then + ! !write(*,*) '44444444444' + ! + ! call DEALLOCATE_ARRAYS_NormalCirculation() + ! CALL DeallocateFlowTypes + ! call Quit() + ! end if + ! ! + ! ! if(IsStopped) exit LoopSimulation + ! ! + !end do LoopSimulation + !!call DEALLOCATE_ARRAYS_NormalCirculation() + !!CALL DeallocateFlowTypes + ! +! + ! end subroutine FluidFlowMainBody + +end module FluidFlowMain \ No newline at end of file diff --git a/FluidFlow-old/Fluid_Flow_Solver.f90 b/FluidFlow-old/Fluid_Flow_Solver.f90 new file mode 100644 index 0000000..4f75657 --- /dev/null +++ b/FluidFlow-old/Fluid_Flow_Solver.f90 @@ -0,0 +1,58 @@ +subroutine Fluid_Flow_Solver + + Use GeoElements_FluidModule + use UTUBEVARSModule + use KickVARIABLESModule + use PressureDisplayVARIABLESModule + USE FricPressDropVarsModule + USE MudSystemVARIABLES + USE Fluid_Flow_Startup_Vars + USE CError + + implicit none + INTEGER :: FlowDuration + Integer :: qwer + integer,dimension(8) :: FlowStartTime,FlowEndTime + + !WRITE (*,*) ' fluid flow pointer 1' + CALL TD_MainCalculations + + Call MeshGeneration_FluidModule + + !WRITE (*,*) ' fluid flow pointer 2' + + MudSystem%FluidFlowCounter = MudSystem%FluidFlowCounter + 1 + + call CirculationCodeSelect + + + CALL WellPressureDataTransfer + + CALL FormationInformationCalculator + + DO KickIteration = 1 , 40 + + !WRITE (*,*) ' Kick Iteration', KickIteration + + CALL PressureAnnAndOHDistribution + + IF (NoGasPocket > 0) THEN + !KickCorrectionVector(:) = 1. + CALL GasKickCalculator + END IF + + IF (NoGasPocket == 0 .OR. NOT(WellHeadOpen)) EXIT + IF(MAXVAL(ABS(KickVandPFunction(:))) < KickConvergenceTolerance) EXIT + !IF(MAXVAL(ABS(KickCorrectionVector(:))) < KickConvergenceTolerance) EXIT + + + END DO + + CALL PressureHorizAndStringDistribution + + IF (KickIteration == 41) THEN + WRITE (*,*) ' KickCorrectionVector ' , KickCorrectionVector + WRITE (*,*) ' Kick Jacobian = ', KickJacobian + END IF + +end subroutine \ No newline at end of file diff --git a/FluidFlow-old/Frictional_Press_Drop_Calc.f90 b/FluidFlow-old/Frictional_Press_Drop_Calc.f90 new file mode 100644 index 0000000..c1659e8 --- /dev/null +++ b/FluidFlow-old/Frictional_Press_Drop_Calc.f90 @@ -0,0 +1,230 @@ +SUBROUTINE FricPressDrop(iloc) + + + + !! Record of revisions + !! Date Programmer Discription of change + !! ------ ------------ ----------------------- + !! 1396/07/23 Sheikh Original code + !! + + + + USE FricPressDropVarsModule + USE CMudPropertiesVariables + USE Fluid_Flow_Startup_Vars + USE CError + + IMPLICIT NONE + + INTEGER :: iloc + REAL :: TauZero + TauZero = 12.0 + !ActiveRheologyModel = Herschel_Bulkley_RheologyModel + + ! 0 = Power Law , 1 = Bingham Plastic , 2 = Newtonian + !TotFricPressLoss = 0.0 + + FlowEl(iloc)%alpha = 1 ! assume that all elements have annulus geometry + FlowEl(iloc)%dPdLfric = 0.0 + FlowEl(iloc)%f = 0.0 + FlowEl(iloc)%FlowRate = ABS(FlowEl(iloc)%FlowRate) + + + + IF ((FlowEl(iloc)%FlowRate >= PressFlowrateTolerance) & + .AND. (FlowEl(iloc)%MaterialType /= 1) & ! not gas kick + .AND. (ABS(FlowEl(iloc)%Length) >= PressLengthTolerance) & + .AND. (FlowEl(iloc)%MaterialType /= 4)) THEN ! not air + + IF (FlowEl(iloc)%Id==0) THEN + FlowEl(iloc)%alpha = 0 + END IF + + FlowEl(iloc)%muPlastic = FlowEl(iloc)%Theta600 - FlowEl(iloc)%Theta300 ! cp + FlowEl(iloc)%YieldP = 2.0 * FlowEl(iloc)%Theta300 - FlowEl(iloc)%Theta600 ! lbf/100ft**2 + FlowEl(iloc)%nIndex = 3.32 * log10(FlowEl(iloc)%Theta600 / FlowEl(iloc)%Theta300) + FlowEl(iloc)%kIndex = 510.0 * FlowEl(iloc)%Theta300 / (511.0**FlowEl(iloc)%nIndex) ! rabete fv2 + IF (MudProperties%ActiveRheologyModel == Herschel_Bulkley_RheologyModel .AND. FlowEl(iloc)%alpha == 0) THEN + FlowEl(iloc)%kIndex = 1.066 * FlowEl(iloc)%Theta300 / (511.0**FlowEl(iloc)%nIndex) + ELSE IF (MudProperties%ActiveRheologyModel == Herschel_Bulkley_RheologyModel .AND. FlowEl(iloc)%alpha == 1) THEN + FlowEl(iloc)%nIndex = 3.32 * log10((FlowEl(iloc)%Theta600 - TauZero) / (FlowEl(iloc)%Theta300 - TauZero)) + FlowEl(iloc)%kIndex = 1.066 * (FlowEl(iloc)%Theta300 - TauZero) / (511.0**FlowEl(iloc)%nIndex) + END IF + + + + + ! Calculating velocity + FlowEl(iloc)%vel = 0.408 * FlowEl(iloc)%FlowRate / (FlowEl(iloc)%Od**2 - FlowEl(iloc)%Id**2) ! velocity in ft/s + !FlowEl(iloc)%vel = 24.51 * FlowEl(iloc)%FlowRate / (FlowEl(iloc)%Od**2 - FlowEl(iloc)%Id**2) ! velocity in ft/min + + !IF (FlowModel == Bingham_RheologyModel) THEN ! Bingham Plastic + ! FlowEl(iloc)%Gf = (2. + FlowEl(iloc)%alpha) / 2. + !ELSE IF (FlowModel == PowerLow_RheologyModel) THEN + ! FlowEl(iloc)%Gf = ((3. - FlowEl(iloc)%alpha) * FlowEl(iloc)%nIndex + 1.) / FlowEl(iloc)%nIndex / (4. - FlowEl(iloc)%alpha) * (2. + FlowEl(iloc)%alpha) / 2. + !END IF + + !FlowEl(iloc)%gammaW = 1.6 * FlowEl(iloc)%Gf * FlowEl(iloc)%vel / FlowEl(iloc)%Dhyd + + !IF (FlowModel == Bingham_RheologyModel) THEN ! Bingham Plastic + ! FlowEl(iloc)%tauW = 1.067 * ((4. - FlowEl(iloc)%alpha) / (3. - FlowEl(iloc)%alpha) * FlowEl(iloc)%YieldP + FlowEl(iloc)%muPlastic * FlowEl(iloc)%gammaW) + ! !FlowEl(iloc)%tauW = 1.067*(FlowEl(iloc)%YieldP+FlowEl(iloc)%muPlastic*FlowEl(iloc)%gammaW) + !ELSE IF (FlowModel == PowerLow_RheologyModel) THEN ! Power law + ! FlowEl(iloc)%tauW = 1.067 * FlowEl(iloc)%kIndex * FlowEl(iloc)%gammaW**FlowEl(iloc)%nIndex + !END IF + + ! Calculating effective or apparent viscosity + IF (MudProperties%ActiveRheologyModel == Bingham_RheologyModel) THEN ! Bingham Plastic + FlowEl(iloc)%mueff = FlowEl(iloc)%muPlastic + 5. * FlowEl(iloc)%YieldP * FlowEl(iloc)%Dhyd / FlowEl(iloc)%vel + !write(*,*) 'pointer1' , FlowEl(iloc)%muPlastic , FlowEl(iloc)%YieldP , FlowEl(iloc)%Dhyd , FlowEl(iloc)%vel + ELSE IF (MudProperties%ActiveRheologyModel == PowerLaw_RheologyModel .OR. MudProperties%ActiveRheologyModel == Herschel_Bulkley_RheologyModel) THEN ! Power Law + FlowEl(iloc)%Gf = ((3. - FlowEl(iloc)%alpha) * FlowEl(iloc)%nIndex + 1.0) / FlowEl(iloc)%nIndex / (4.0 - FlowEl(iloc)%alpha) * (2.0 + FlowEl(iloc)%alpha) / 2.0 + FlowEl(iloc)%mueff = (FlowEl(iloc)%kIndex) / (1. + FlowEl(iloc)%alpha / 2.) * ((96. * FlowEl(iloc)%vel / FlowEl(iloc)%Dhyd)**(FlowEl(iloc)%nIndex - 1)) * FlowEl(iloc)%Gf**FlowEl(iloc)%nIndex + !write(*,*) 'pointer2' , FlowEl(iloc)%kIndex ,FlowEl(iloc)%alpha , FlowEl(iloc)%vel ,FlowEl(iloc)%Dhyd,FlowEl(iloc)%nIndex ,FlowEl(iloc)%Gf ,FlowEl(iloc)%nIndex + END IF + + FlowEl(iloc)%gammaW = 96.0 * FlowEl(iloc)%Gf * FlowEl(iloc)%vel / FlowEl(iloc)%Dhyd + + FlowEl(iloc)%tauW = ((4.0 - FlowEl(iloc)%alpha) / (3.0 - FlowEl(iloc)%alpha))**FlowEl(iloc)%nIndex * TauZero + FlowEl(iloc)%kIndex * FlowEl(iloc)%gammaW**FlowEl(iloc)%nIndex + + + ! Calculating Reynolds number + IF (FlowEl(iloc)%Od == FlowEl(iloc)%Dhyd) THEN + FlowEl(iloc)%GenRe = 928. * FlowEl(iloc)%density * FlowEl(iloc)%vel * FlowEl(iloc)%Dhyd / FlowEl(iloc)%mueff + ELSE + FlowEl(iloc)%GenRe = 757. * FlowEl(iloc)%density * FlowEl(iloc)%vel * FlowEl(iloc)%Dhyd / FlowEl(iloc)%mueff + END IF + + !FlowEl(iloc)%GenRe = 2997 * FlowEl(iloc)%density * FlowEl(iloc)%vel**2 / 19.36 / FlowEl(iloc)%tauW + + ! Calculating friction factor + IF (MudProperties%ActiveRheologyModel == Bingham_RheologyModel) THEN ! Bingham Plastic + IF (FlowEl(iloc)%GenRe <= 2000.0) THEN ! laminar regime + FlowEl(iloc)%f = 16.0 / FlowEl(iloc)%GenRe + ELSE IF (FlowEl(iloc)%GenRe >= 4000.0) THEN ! turbulent regime + FlowEl(iloc)%a = 0.0791 + FlowEl(iloc)%b = 0.25 + FlowEl(iloc)%f = FlowEl(iloc)%a / FlowEl(iloc)%GenRe**FlowEl(iloc)%b + ELSE !! transition from laminar to turbulent regime + FlowEl(iloc)%a = 0.0791 + FlowEl(iloc)%b = 0.25 + FlowEl(iloc)%f = (4000.0 - FlowEl(iloc)%GenRe) / 2000.0 * 16. / FlowEl(iloc)%GenRe & + + (FlowEl(iloc)%GenRe - 2000.0) / 2000.0 * FlowEl(iloc)%a / FlowEl(iloc)%GenRe**FlowEl(iloc)%b + END IF + + ELSE IF (MudProperties%ActiveRheologyModel == PowerLaw_RheologyModel) THEN ! Power law + FlowEl(iloc)%ReCritLam = 3470. - 1370. * FlowEl(iloc)%nIndex + FlowEl(iloc)%ReCritTurb = 4270. - 1370. * FlowEl(iloc)%nIndex + + IF (FlowEl(iloc)%GenRe <= FlowEl(iloc)%ReCritLam) THEN ! laminar regime + FlowEl(iloc)%f = 16.0 / FlowEl(iloc)%GenRe / (1 - 0.184 * FlowEl(iloc)%alpha) + ELSE IF (FlowEl(iloc)%GenRe >= FlowEl(iloc)%ReCritTurb) THEN ! turbulent regime + FlowEl(iloc)%a = (log10(FlowEl(iloc)%nIndex) + 3.93) / 50. + FlowEl(iloc)%b = (1.75 - log10(FlowEl(iloc)%nIndex)) / 7. + FlowEl(iloc)%f = FlowEl(iloc)%a / FlowEl(iloc)%GenRe**FlowEl(iloc)%b + ELSE + FlowEl(iloc)%a = (log10(FlowEl(iloc)%nIndex) + 3.93) / 50. + FlowEl(iloc)%b = (1.75 - log10(FlowEl(iloc)%nIndex)) / 7. + FlowEl(iloc)%f = (FlowEl(iloc)%ReCritTurb - FlowEl(iloc)%GenRe) / 800.0 * 16. / FlowEl(iloc)%GenRe & + + (FlowEl(iloc)%GenRe - FlowEl(iloc)%ReCritLam) / 800.0 * FlowEl(iloc)%a / FlowEl(iloc)%GenRe**FlowEl(iloc)%b + END IF + + END IF + + !WRITE (*,*) 'fric press drop', iloc + !WRITE (*,*) 'Length', ABS(REAL(FlowEl(iloc)%Length)) + !WRITE (*,*) 'FlowRate', FlowEl(iloc)%FlowRate + !WRITE (*,*) 'Theta600 , Theta300', FlowEl(iloc)%Theta600 , FlowEl(iloc)%Theta300 + !WRITE (*,*) 'Dhyd', FlowEl(iloc)%Dhyd + !WRITE (*,*) 'GenRe', FlowEl(iloc)%GenRe + !WRITE (*,*) 'f', FlowEl(iloc)%f + + + + + END IF + + ! Frictional pressure loss gradient calculation + ! FlowEl(iloc)%dPdLfric = 1.076 * FlowEl(iloc)%f * FlowEl(iloc)%vel**2 * FlowEl(iloc)%density / 10**5 / FlowEl(iloc)%Dhyd + FlowEl(iloc)%dPdLfric = FlowEl(iloc)%f * (FlowEl(iloc)%vel)**2 * FlowEl(iloc)%density / 25.81 / FlowEl(iloc)%Dhyd + FlowEl(iloc)%FricPressLoss = FlowEl(iloc)%dPdLfric * ABS(REAL(FlowEl(iloc)%Length)) + + IF (FlowEl(iloc)%FrictionDirection == -1) THEN + FlowEl(iloc)%FlowRate = - FlowEl(iloc)%FlowRate + FlowEl(iloc)%dPdLfric = - FlowEl(iloc)%dPdLfric + FlowEl(iloc)%FricPressLoss = - FlowEl(iloc)%FricPressLoss + END IF + + + + !END DO + + +END SUBROUTINE FricPressDrop + + +SUBROUTINE PartialDerivativeFricToFlowRate(iloc) + + USE FricPressDropVarsModule + USE CMudPropertiesVariables + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule + USE CError + + + IMPLICIT NONE + + INTEGER :: iloc + + FlowEl(iloc)%FricToQPartialDiff = 0.0 + !FlowEl(iloc)%FlowRate = ABS(FlowEl(iloc)%FlowRate) + + + IF ((ABS(FlowEl(iloc)%FlowRate) >= PressFlowrateTolerance) & + .AND. (FlowEl(iloc)%MaterialType /= 1) & ! not gas kick + .AND. (ABS(FlowEl(iloc)%Length) >= PressLengthTolerance) & + .AND. (FlowEl(iloc)%MaterialType /= 4)) THEN ! not air + + IF (MudProperties%ActiveRheologyModel == PowerLaw_RheologyModel) THEN ! Power law + !IF (FlowEl(iloc)%Flowrate == 0.0) THEN + ! FlowEl(iloc)%Flowrate = 10.0 + ! CALL FricPressDrop(iloc) + !END IF + IF (FlowEl(iloc)%GenRe <= FlowEl(iloc)%ReCritLam) THEN ! laminar flow + FlowEl(iloc)%FricToQPartialDiff = FlowEl(iloc)%FricPressLoss / FlowEl(iloc)%FlowRate * FlowEl(iloc)%nIndex + + ELSE IF (FlowEl(iloc)%GenRe >= FlowEl(iloc)%ReCritTurb) THEN ! turbulent flow + FlowEl(iloc)%FricToQPartialDiff = FlowEl(iloc)%FricPressLoss / FlowEl(iloc)%FlowRate & + * (2. - FlowEl(iloc)%b * (2. - FlowEl(iloc)%nIndex)) + + ELSE ! transition from laminar to turbulent + FlowEl(iloc)%FricToQPartialDiff = FlowEl(iloc)%FricPressLoss / FlowEl(iloc)%FlowRate & + * (2. + (2. - FlowEl(iloc)%nIndex) & + * ((FlowEl(iloc)%a * FlowEl(iloc)%GenRe**(1. - FlowEl(iloc)%b) - 16.) / 800. / FlowEl(iloc)%f - 1.)) + END IF + + ELSE IF (MudProperties%ActiveRheologyModel == Bingham_RheologyModel) THEN ! Bingham Plastic + IF (FlowEl(iloc)%GenRe <= 2000.0 .OR. FlowEl(iloc)%f == 0.0) THEN ! laminar flow if f = 0.0, we have no flow in first time flowing + FlowEl(iloc)%FricToQPartialDiff = (16. * FlowEl(iloc)%muPlastic * REAL(FlowEl(iloc)%Length) * 2.224 * (10.)**(-3)) & + / (25.81 * 928. * (1 - 0.184 * FlowEl(iloc)%alpha) * FlowEl(iloc)%Dhyd**2 * FlowEl(iloc)%Area) + + ELSE IF (FlowEl(iloc)%GenRe >= 4000.0) THEN ! turbulent flow + FlowEl(iloc)%FricToQPartialDiff = FlowEl(iloc)%FricPressLoss / FlowEl(iloc)%FlowRate & + * (2. - FlowEl(iloc)%b * (2. - FlowEl(iloc)%muPlastic / FlowEl(iloc)%mueff)) + + ELSE ! transition from laminar to turbulent + FlowEl(iloc)%FricToQPartialDiff = FlowEl(iloc)%FricPressLoss / FlowEl(iloc)%FlowRate & + * (2. + (2. - FlowEl(iloc)%muPlastic / FlowEl(iloc)%mueff) & + * ((FlowEl(iloc)%a * FlowEl(iloc)%GenRe**(1. - FlowEl(iloc)%b) - 16.) / 2000. / FlowEl(iloc)%f - 1.)) + END IF + END IF + END IF + + + IF (FlowEl(iloc)%FricToQPartialDiff < 0.0) THEN + !WRITE (*,*) ' iloc, Re, FricPressLoss, FricToQPartialDiff' , iloc, FlowEl(iloc)%GenRe, FlowEl(iloc)%FricPressLoss, FlowEl(iloc)%FricToQPartialDiff + !CALL ERRORSTOP('Error in Calculating FricToQPartialDiff') + END IF + +END SUBROUTINE PartialDerivativeFricToFlowRate \ No newline at end of file diff --git a/FluidFlow-old/Horizontal_and_String_Pressure_Distribution.f90 b/FluidFlow-old/Horizontal_and_String_Pressure_Distribution.f90 new file mode 100644 index 0000000..c05dd9b --- /dev/null +++ b/FluidFlow-old/Horizontal_and_String_Pressure_Distribution.f90 @@ -0,0 +1,799 @@ +SUBROUTINE PressureHorizAndStringDistribution + + + !! Record of revisions + !! Date Programmer Discription of change + !! ------ ------------ ----------------------- + !! 1396/07/30 Sheikh Original code + !! + + USE FricPressDropVarsModule + use PressureDisplayVARIABLESModule + USE MudSystemVARIABLES + USE GeoElements_FluidModule + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule + USE CMudPropertiesVariables + USE CDataDisplayConsoleVariables !, StandPipePressureDataDisplay=> ChokeControlPanel%StandPipePressure + USE CDataDisplayConsoleVariables !, CasingPressureDataDisplay=> CasingPressure + USE CDrillWatchVariables + USE CShoeVariables + USE CDownHoleVariables! , OperationScenarioCommon%ElevatorConnection => DownHole%CasingPressure + USE TD_WellGeometry + USE CManifolds + USE VARIABLES + USE CError + use UTUBEVARSModule + USE CKellyConnectionEnumVariables + USE Pumps_VARIABLES + USE , INTRINSIC :: IEEE_ARITHMETIC + Use TD_DrillStemComponents + Use sROP_Variables + + + + IMPLICIT NONE + + INTEGER :: i , j , l + INTEGER :: ifric + INTEGER :: OldCasingPressure + REAL :: PressBelowFloatValve , PressAboveFloatValve ![psi] + REAL :: PumpMinDischargedVol = 0.0050 ! [gal] + REAL :: FloatValveBottomToUpAreaRatio = 1.1 ![-] + REAL :: ZeroHeight , StaticHeadOnBit + REAL(8) :: ShoeTVD + !REAL(8) , DIMENSION(5) :: MDObserve , TVDObserve , StPressObserve , AnnPressObserve , NomMD + + ExitMass = 0.0 + BitPressLoss = 0.0 + + WellHeadWasOpen = WellHeadOpen + WellToChokeManifoldWasOpen = MudSystem%WellToChokeManifoldOpen + KickWasExitingThroughChoke = .FALSE. + + + 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 = MudSystem%StringFlowRate ! pump flow rate [gpm] + END IF + + !WRITE (*,*) 'a)A/B P Bit', StaticHeadOnBit , FlowEl(AnnulusFirstEl)%StartPress , SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + !IF (FloatValveIn == .FALSE.) FloatValveOpen = .TRUE. + FloatValveWasOpen = FloatValveOpen + + PressBelowFloatValve = FlowEl(AnnulusFirstEl)%StartPress + + StMudVol = SUM(FlowEl(1 : StringLastEl)%Volume) * Convft3toUSGal + StDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * StMudVol) + + AnnMudVol = SUM(FlowEl(AnnulusFirstEl : NumbEl)%Volume) * Convft3toUSGal + !StCompressedMudVol = StCompressedMudVol + REAL(St_Saved_MudDischarged_Volume_Final) + !WRITE (*,*) 'St_Saved_MudDischarged_Volume_Final', REAL(St_Saved_MudDischarged_Volume_Final) + !StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol) + !PressAboveFloatValve = StDeltaPDueToCompressibility + SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) !!FlowEl(StringLastEl)%EndPress + + !IF (NoGasPocket > 0) THEN ! mud exprience no comressibility + !IF (KickVolume > 2.0) THEN + IF ( (DownHole%KickVolume > 2.0) .or. (NoGasPocket>1) .or. (any(FlowEl(OpenholeFirstEl:NumbEl)%Materialtype==1)) .or. (ROP_bit%RateofPenetration > 0.0) ) THEN + AnnCompressedMudVol = 0.0 + AnnDeltaPDueToCompressibility = 0.0 + + ELSE IF (WellHeadOpen) THEN + AnnDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * AnnMudVol) + + AnnCompressedMudVol = BackPressure / AnnDeltaPtoDeltaVCompressibility + AnnDeltaPDueToCompressibility = AnnCompressedMudVol / (MudCompressibility * AnnMudVol) + + 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(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(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol)) THEN ! float valve remains open + FloatValveOpen = .TRUE. + + 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 + DO ifric = 1 , StringLastEl + CALL FricPressDrop(ifric) + !WRITE (*,*) ' element No, FlowRate , Density, FricPressLoss', ifric, FlowEl(ifric)%FlowRate, FlowEl(ifric)%Density, FlowEl(ifric)%FricPressLoss + IF (IEEE_IS_NaN(FlowEl(ifric)%FricPressLoss)) THEN + WRITE (*,*) 'Hz/St start, end, density, Q, mu, Type' , FlowEl(ifric)%StartX, FlowEl(ifric)%EndX, FlowEl(ifric)%Density, FlowEl(ifric)%FlowRate, FlowEl(ifric)%mueff, FlowEl(ifric)%MaterialType + CALL ErrorStop('NaN in calculating pressure drop' , ifric) + END IF + END DO + END IF + + !!!!!!!!!!!!!!! + + + !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 + 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(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN + + 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 * (MudSystem%MudVolume_InjectedToBH * ConvMinToSec / dt)**2 + !WRITE (*,*) 'BitPressLoss', BitPressLoss + END IF + + StCompressedMudVol = BitPressLoss / StDeltaPtoDeltaVCompressibility + + ELSE + MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((StDeltaPDueToCompressibility + SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff - PressBelowFloatValve - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & + / StDeltaPtoDeltaVCompressibility ) * 1.d0)) + 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(MudSystem%St_Saved_MudDischarged_Volume_Final) + StDeltaPDueToCompressibility = StCompressedMudVol * StDeltaPtoDeltaVCompressibility + MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((StDeltaPDueToCompressibility - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & + / (StDeltaPtoDeltaVCompressibility + AnnDeltaPtoDeltaVCompressibility)) * 1.d0) + 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 + + !WRITE (*,*) 'WellHeadOpen', WellHeadOpen + !WRITE (*,*) ' StCompressedMudVol, StDeltaPDueToCompressibility',StCompressedMudVol, StDeltaPDueToCompressibility + !WRITE (*,*) ' AnnCompressedMudVol, AnnDeltaPDueToCompressibility',AnnCompressedMudVol, AnnDeltaPDueToCompressibility + END IF + + + + FlowEl(StringLastEl)%EndPress = FlowEl(AnnulusFirstEl)%StartPress + BitPressLoss + FloatValveMinOpenPressure + !WRITE (*,*) 'BitPressLoss=', BitPressLoss + FlowEl(StringLastEl)%StartPress = FlowEl(StringLastEl)%EndPress + FlowEl(StringLastEl)%FricPressLoss - FlowEl(StringLastEl)%StaticPressDiff + DO i = StringLastEl - 1 , StringFirstEl , -1 + FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss - FlowEl(i)%StaticPressDiff + !WRITE(*,*) "STRING: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress + !WRITE(*,*) "STRING: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX + END DO + + !FlowEl(NoHorizontalEl)%EndPress = FlowEl(StringFirstEl)%StartPress - FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD + !WRITE (*,*) '- FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD1=', - FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD + !FlowEl(NoHorizontalEl)%StartPress = FlowEl(NoHorizontalEl)%EndPress + FlowEl(StringLastEl)%FricPressLoss + !DO i = NoHorizontalEl - 1 , 1 , -1 + ! FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + ! FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss + ! !WRITE(*,*) "HORIZONTAL: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress + ! !WRITE(*,*) "HORIZONTAL: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX + !END DO + + !!!!!!!!!!!!!!!!!!!!!!!!!!!! Float valve was open and remains open + + 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 + MudSystem%MudVolume_InjectedToBH = 0.d0 + END IF + + + IF (PressBelowFloatValve >= PressAboveFloatValve .AND. KickFlux) THEN + FloatValveOpen = .FALSE. + IF (FloatValveOpen /= FloatValveWasOpen) THEN ! float valve was open and now closed + WRITE (*,*) 'Float valve was open and now closed' + WRITE (*,*) 'PressAboveFloatValve=', PressAboveFloatValve + WRITE (*,*) 'PressBelowFloatValve=', PressBelowFloatValve + END IF + + END IF + + IF (FloatValveOpen) THEN + MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , 0.1 * REAL((PressAboveFloatValve - PressBelowFloatValve - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & + / StDeltaPtoDeltaVCompressibility ) * 1.d0) + MudSystem%MudVolume_InjectedToBH = MIN(MudSystem%MudVolume_InjectedToBH , StCompressedMudVol) + !WRITE (*,*) 'MudVolume_InjectedToBH (No Pump)', MudVolume_InjectedToBH + + StCompressedMudVol = StCompressedMudVol - MudSystem%MudVolume_InjectedToBH + StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol) + !WRITE (*,*) 'StDeltaPDueToCompressibility(No Pump)', StDeltaPDueToCompressibility + + END IF + + IF (NoGasPocket == 0 .AND. WellHeadOpen == .FALSE.) THEN !*********** + FlowEl(AnnulusFirstEl : NumbEl)%StartPress = FlowEl(AnnulusFirstEl : NumbEl)%StartPress + AnnDeltaPDueToCompressibility + FlowEl(AnnulusFirstEl : NumbEl)%EndPress = FlowEl(AnnulusFirstEl : NumbEl)%EndPress + AnnDeltaPDueToCompressibility + END IF + + + + IF (FloatValveOpen) THEN + FlowEl(StringLastEl)%EndPress = MAX(FlowEl(AnnulusFirstEl)%StartPress , SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + 0.052 * FlowEl(StringFirstEl)%Density * FlowEl(StringFirstEl)%StartTVD) + ELSE + FlowEl(StringLastEl)%EndPress = StDeltaPDueToCompressibility + SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + END IF + + FlowEl(StringLastEl)%StartPress = FlowEl(StringLastEl)%EndPress - FlowEl(StringLastEl)%StaticPressDiff + DO i = StringLastEl - 1 , StringFirstEl , -1 + FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss - FlowEl(i)%StaticPressDiff + !WRITE(*,*) "STRING: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress + !WRITE(*,*) "STRING: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX + END DO + + !FlowEl(NoHorizontalEl)%EndPress = FlowEl(StringFirstEl)%StartPress - FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD + !WRITE (*,*) '- FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD2=', - FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD + !FlowEl(NoHorizontalEl)%StartPress = FlowEl(NoHorizontalEl)%EndPress + FlowEl(StringLastEl)%FricPressLoss + !DO i = NoHorizontalEl - 1 , 1 , -1 + ! FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + ! FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss + ! !WRITE(*,*) "HORIZONTAL: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress + ! !WRITE(*,*) "HORIZONTAL: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX + !END DO + + + !WRITE (*,*) ' StCompressedMudVol, StDeltaPDueToCompressibility',StCompressedMudVol, StDeltaPDueToCompressibility + !WRITE (*,*) ' AnnCompressedMudVol, AnnDeltaPDueToCompressibility',AnnCompressedMudVol, AnnDeltaPDueToCompressibility + !!!!!!!!!!!!!!!!!!!!!!!!!!!! Float valve was open (close) and maybe remains open (close) or maybe closed + + ELSE IF(FloatValveWasOpen == .FALSE. .AND. REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN + FloatValveOpen = .FALSE. + MudSystem%MudVolume_InjectedToBH = 0.d0 + + StCompressedMudVol = StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) + StDeltaPDueToCompressibility = StCompressedMudVol * StDeltaPtoDeltaVCompressibility + PressAboveFloatValve = SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + StDeltaPDueToCompressibility + + + + + IF (PressAboveFloatValve > FloatValveBottomToUpAreaRatio * PressBelowFloatValve) THEN ! float valve was open and now closed + FloatValveOpen = .TRUE. + WRITE (*,*) 'Float valve was closed and now opened' + WRITE (*,*) 'PressAboveFloatValve=', PressAboveFloatValve + WRITE (*,*) 'PressBelowFloatValve=', PressBelowFloatValve + END IF + + + FlowEl(StringLastEl)%EndPress = PressAboveFloatValve + FlowEl(StringLastEl)%StartPress = FlowEl(StringLastEl)%EndPress - FlowEl(StringLastEl)%StaticPressDiff + DO i = StringLastEl - 1 , StringFirstEl , -1 + FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + FlowEl(i)%StartPress = FlowEl(i)%EndPress - FlowEl(i)%StaticPressDiff + !WRITE(*,*) "STRING: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress + !WRITE(*,*) "STRING: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX + END DO + + + + + END IF + + 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 + !WRITE (*,*) 'Density , StartX= , StartPress', FlowEl(NoHorizontalEl)%Density , FlowEl(StringFirstEl)%StartTVD + ELSE IF (WellHeadOpen) THEN + FlowEl(NoHorizontalEl)%EndPress = FlowEl(StringFirstEl)%StartPress - 2.0 * 0.052 * FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD + END IF + + FlowEl(NoHorizontalEl)%StartPress = FlowEl(NoHorizontalEl)%EndPress + FlowEl(NoHorizontalEl)%FricPressLoss + DO i = NoHorizontalEl - 1 , 1 , -1 + FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss + !WRITE(*,*) "HORIZONTAL: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress + !WRITE(*,*) "HORIZONTAL: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX + END DO + + + !WRITE (*,*) 'MudVolume_InjectedToBH==', MudVolume_InjectedToBH + !WRITE (*,*) 'Ann_Saved_MudDischarged_Volume_Final==', Ann_Saved_MudDischarged_Volume_Final + +!!!!!!!!!!!!!!!!!!!!! Pressure distribution in string and horizontal pump to string line + + + IF (RamLine%ShearBop_Situation_forTD == 1) THEN + FlowEl(1 : NoHorizontalEl)%EndPress = 0.0 + FlowEl(1 : NoHorizontalEl)%StartPress = 0.0 + FlowEl(1 : NoHorizontalEl)%FricPressLoss = 0.0 + END IF + +!!!!!!!!!!!!!!!!!!!!!!!!! + + + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + + + !IF (NoGasPocket == 0 .AND. WellHeadOpen) THEN + ! FlowEl(1 : NoHorizontalEl + NoStringEl)%EndPress = FlowEl(1 : NoHorizontalEl + NoStringEl)%EndPress + StDeltaPDueToCompressibility + AnnDeltaPDueToCompressibility + ! FlowEl(1 : NoHorizontalEl + NoStringEl)%StartPress = FlowEl(1 : NoHorizontalEl + NoStringEl)%StartPress + StDeltaPDueToCompressibility + AnnDeltaPDueToCompressibility + ! FlowEl(NoHorizontalEl + NoStringEl +1 : NumbEl)%EndPress = FlowEl(NoHorizontalEl + NoStringEl +1 : NumbEl)%EndPress + AnnDeltaPDueToCompressibility + ! FlowEl(NoHorizontalEl + NoStringEl + 1 : NumbEl)%StartPress = FlowEl(NoHorizontalEl + NoStringEl + 1 : NumbEl)%StartPress + AnnDeltaPDueToCompressibility + !ELSE + !IF (NoGasPocket == 0 .AND. WellHeadOpen == .FALSE.) THEN + ! FlowEl(1 : StringLastEl)%EndPress = FlowEl(1 : StringLastEl)%EndPress + StDeltaPDueToCompressibility + 30.0 ! badan eslah shavad + ! FlowEl(1 : StringLastEl)%StartPress = FlowEl(1 : NoHorizontalEl + NoStringEl)%StartPress + StDeltaPDueToCompressibility + 30.0 + ! FlowEl(AnnulusFirstEl : NumbEl)%EndPress = FlowEl(AnnulusFirstEl : NumbEl)%EndPress + AnnDeltaPDueToCompressibility + ! FlowEl(AnnulusFirstEl : NumbEl)%StartPress = FlowEl(AnnulusFirstEl : NumbEl)%StartPress + AnnDeltaPDueToCompressibility + !END IF + + + 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) + ! !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 (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) + ! 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) + ! ! 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) + ! MudSystem%MudVolume_InjectedFromAnn = 0.d0 + ! END IF + !StCompressedMudVol = MAX(StCompressedMudVol - REAL(MudVolume_InjectedToBH) , 0.0) + !AnnCompressedMudVol = MAX(AnnCompressedMudVol - REAL(MudSystem%MudVolume_InjectedFromAnn) , 0.0) + !StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol) + !AnnDeltaPDueToCompressibility = AnnCompressedMudVol / (MudCompressibility * AnnMudVol) + END IF + + + !MudVolume_InjectedToBH = 0.0 + !MudVolume_InjectedToBH = St_Saved_MudDischarged_Volume_Final + !WRITE (*,*) 'CompMudVol, DeltaP, MudVolumeInjected' + !WRITE (*,*) StCompressedMudVol, StDeltaPDueToCompressibility, REAL(MudVolume_InjectedToBH) + !WRITE (*,*) AnnCompressedMudVol, AnnDeltaPDueToCompressibility, REAL(MudSystem%MudVolume_InjectedFromAnn) + !WRITE (*,*) 'Press above/Below Float valve ', FlowEl(NoHorizontalEl + NoStringEl)%EndPress , FlowEl(NoHorizontalEl + NoStringEl + 1)%StartPress + !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) + + + !DO i = NumbEl , NumbEl - NoOpenHoleEl + 1 , -1 ! op elements + ! WRITE (*,*) 'el no, start, end' , i, FlowEl(i)%StartPress, FlowEl(i)%EndPress + !END DO + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!! Kick Information Reports + + +!!!!!!!!!!!!!!!!! 1- Stand pipe pressure gauge PressureGauges(1) + + !ElementTrueDepth = STpipeGauge_Height/Convfttom + !DistancetoRefrence = -170.7 ! 165 ft after pump and 100 ft before string + i = 1 + DO WHILE (NOT(FlowEl(i)%EndX >= -170 .AND. FlowEl(i)%StartX <= -170)) + i = i + 1 + IF (i > NoHorizontalEl) EXIT + END DO + 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. + + DO j = PressureTimeStepDelay(1) , 1 , -1 + IF (NOT(IEEE_IS_NaN(PumpPressureDelay%Array(j)))) THEN + PressureGauges(1) = INT(PumpPressureDelay%Array(j)) + EXIT + END IF + END DO + + !PressureGauges(1) = INT(PumpPressureDelay%Array(PressureTimeStepDelay(1))) + + IF (i > NoHorizontalEl) THEN + WRITE (*,*) ' Error in calculating standpipe pressure ' + END IF + + IF (PressureGauges(1) < 0) THEN + !CALL Set_StandPipePressure(real(PressureGauges(1) , 8)) ! for display console + PressureGauges(1) = 0.0 + !CALL Set_StandPipePressure(0.0d0) !StandPipePressureGauge = 0 + END IF + DownHole%DrillPipePressure = real(PressureGauges(1), 8) + !WRITE (*,*) 'Drillpipe Pressure', PressureGauges(1) + +!!!!!!!!!!!!!!!!! 2- Casing pressure gauge PressureGauge(2) + !WRITE (*,*) 'here 1', (WelltoPitsOpen == .FALSE. .AND. WellToChokeManifoldOpen) , (Valve(26)%Status == .TRUE. .AND. Valve(47)%Status == .TRUE. .AND. Valve(49)%Status == .TRUE.), BackPressure + !WRITE (*,*) Valve(26)%Status , Valve(47)%Status , Valve(49)%Status + !WRITE (*,*) (Valve(26)%Status == .TRUE.) , (Valve(47)%Status == .TRUE.) , (Valve(49)%Status == .TRUE.) + + !!! 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 (MudSystem%WellToChokeManifoldOpen .OR. MudSystem%WellToChokeLineGauge) THEN + !WRITE (*,*) 'Here 1' + CALL CasingPressureDelay%AddToFirst(FlowEl(NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWellToChokeEl)%EndPress) + CALL CasingPressureDelay%Remove(PressureTimeStepDelay(1) + 1) + + DO j = 1 , PressureTimeStepDelay(1) + IF (NOT(IEEE_IS_NaN(CasingPressureDelay%Array(j)))) THEN + PressureGauges(2) = INT(CasingPressureDelay%Array(j)) + EXIT + END IF + END DO + + !PressureGauges(2) = INT(CasingPressureDelay%Array(1)) + IF (ANY(PUMP(:)%PowerFailMalf == 1)) THEN + DO j = PressureTimeStepDelay(1) , 1 , -1 + IF (NOT(IEEE_IS_NaN(CasingPressureDelay%Array(j)))) THEN + PressureGauges(2) = INT(CasingPressureDelay%Array(j)) + EXIT + END IF + END DO + END IF + + + + + !IF (ANY(PUMP(:)%PowerFailMalf == 1)) PressureGauges(2) = INT(CasingPressureDelay%Array(PressureTimeStepDelay(1))) + + ELSE !IF (ChokeLineGaugeToTanks) THEN + PressureGauges(2) = 0 + !WRITE (*,*) 'Here 2' + END IF + + + !WRITE (*,*) 'GaugePoint(2)%Pressure =' , GaugePoint(2)%Pressure + !IF (PressureGauges(2) < 0) THEN + ! PressureGauges(2) = 0.0 + !END IF + CALL Set_CasingPressure(real(PressureGauges(2) , 8)) ! for display console + Downhole%CasingPressure = real(PressureGauges(2) , 8) + !IF (PressureGauges(2) > 3000.0) THEN + ! !CALL Error(' High Casing Pressure') + !END IF + !WRITE (*,*) 'Casing Pressure=' , PressureGauges(2) + + + +!!!!!!!!!!!!!!!!! 3- Bottom Hole Pressure PressureGauge(3) + + CALL BottomHolePressureDelay%AddToFirst(FlowEl(OpenholeFirstEl)%StartPress) + CALL BottomHolePressureDelay%Remove(PressureTimeStepDelay(2) + 1) + !PressureGauges(3) = INT(BottomHolePressureDelay%Array(PressureTimeStepDelay(2))) + + DO j = PressureTimeStepDelay(2) , 1 , -1 + IF (NOT(IEEE_IS_NaN(BottomHolePressureDelay%Array(j)))) THEN + PressureGauges(3) = INT(BottomHolePressureDelay%Array(j)) + EXIT + END IF + END DO + + + BottomHolePress = BottomHolePressureDelay%Array(PressureTimeStepDelay(2)) + + DownHole%BottomHolePressure = REAL(PressureGauges(3) , 8) +!!!!!!!!!!!!!!!!! 4- Under Bit Pressure PressureGauges(4) + + PressureGauges(4) = FlowEl(AnnulusFirstEl)%StartPress + +!!!!!!!!!!!!!!!!! + + +!!!!!!!!!!!!!!!!! 5- Casing Shoe Pressure PressureGauges(5) + + !IF (ShoeDepth <= FlowEl(NoHorizontalEl + NoStringEl + 1)%StartX) THEN + DO ShoeFlowElNo = AnnulusFirstEl , NumbEl + IF (FlowEl(ShoeFlowElNo)%StartX >= Shoe%ShoeDepth .AND. FlowEl(ShoeFlowElNo)%EndX < Shoe%ShoeDepth) EXIT + END DO + CALL TVD_Calculator(Shoe%ShoeDepth , ShoeTVD) + + IF (ShoeFlowElNo > NumbEl) THEN + WRITE (*,*) 'ShoeDepth =', Shoe%ShoeDepth + DO i = AnnulusFirstEl , NumbEl + WRITE (*,*) 'i, StartX, EndX', i, FlowEl(i)%StartX, FlowEl(i)%EndX + END DO + + CALL ErrorSTOP ('Error in finding location of shoe') + END IF + + !ELSE + ! WRITE (*,*) ' Error in calculating shoe pressure ' + !END IF + + CALL ShoePressureDelay%AddToFirst(REAL(FlowEl(ShoeFlowElNo)%StartPress & + - (FlowEl(ShoeFlowElNo)%StartX - Shoe%ShoeDepth) * FlowEl(ShoeFlowElNo)%dPdLfric & + - (FlowEl(ShoeFlowElNo)%StartTVD - ShoeTVD) * FlowEl(ShoeFlowElNo)%dPdLGrav)) + CALL ShoePressureDelay%Remove(PressureTimeStepDelay(3) + 1) + + !FlowrateNearShoe = FlowEl(ShoeFlowElNo)%FlowRate + DO j = PressureTimeStepDelay(3) , 1 , -1 + IF (NOT(IEEE_IS_NaN(ShoePressureDelay%Array(j)))) THEN + PressureGauges(5) = INT(ShoePressureDelay%Array(j)) + EXIT + END IF + END DO + + + !PressureGauges(5) = INT(ShoePressureDelay%Array(PressureTimeStepDelay(3))) + DownHole%ShoePressure = real(PressureGauges(5), 8) + + + + !IF (PressureGauges(5) >= FormationLostPressure) WRITE (*,*) 'Near Shoe Flowrate', FlowEl(ShoeFlowElNo)%FlowRate + + MudSystem%ShoeMudViscosity = FlowEl(ShoeFlowElNo)%MuEff + MudSystem%ShoeMudDensity = FlowEl(ShoeFlowElNo)%Density + + !WRITE (*,*) 'Drillstring speed (ft/s)' , DrillStringSpeed + !WRITE (*,*) 'shoe mud speed ', FlowEl(ShoeFlowElNo - 1)%vel + !WRITE (*,*) 'Shoe pressure (psi)', ShoePressureDelay%Array(1) + + + + +!!!!!!!!!!!!!!!!! + +!!!!!!!!! 6- Pressure Before Bop + + PressureGauges(6) = FlowEl(NoHorizontalEl + NoStringEl + NoAnnulusEl)%EndPress + +!!!!!!!!!!!!!!!!! +101 FORMAT(4X, I2, 8X, (F8.1), 12X, (F8.3), 7X, (F8.2)) + + !WRITE (*,*) ' Pump Pressure Delay', PumpPressureDelay%Array(1) + !WRITE (*,*) ' Bottom Hole Pressure Delay', BottomHolePressureDelay%Array(1) + !WRITE (*,*) ' Shoe Pressure Delay', ShoePressureDelay%Array(1) + + !IF (ALLOCATED(GasPocketWeight%Array) .AND. ChokeKroneckerDelta == 1) THEN + !WRITE (*,*) 'Pocket No , Gas Pocket (psia) , Volume (gal) , Flow Induced (gpm) ' + + !DO i = 1 , NoGasPocket + ! WRITE (*,101) i, GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * ConvFt3toUSGal, GasPocketFlowInduced%Array(i) + !END DO + ! WRITE (*,*) 'Kchoke =', Kchoke, FlowEl(OpenholeFirstEl - 1)%FlowRate + + !DO i = 1 , NoGasPocket + ! WRITE (*,*) 'Gas Kick Vol (gal)=' , GasPocketNewVol%Array(i) * ConvFt3toUSGal , GasPocketDeltaVol%Array(i) * ConvFt3toUSGal , GasPocketNewPress%Array(i) + !END DO + + !WRITE (*,*) 'BHP (psig)=', BottomHolePress + + IF (ChokeKroneckerDelta == 1) THEN + !WRITE (*,*) 'Casing Pressure' , PressureGauges(2) + !WRITE (*,*) 'Below Bit' , FlowEl(AnnulusFirstEl)%StartPress + !WRITE (*,*) 'Above Bit' , FlowEl(StringLastEl)%EndPress + !WRITE (*,*) 'Pump Pressure' , PressureGauges(1) + + + + !WRITE (*,*) ' Kick Iteration', KickIteration + !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 + !write(*,*) 'BackPressure=' , BackPressure + + !WRITE (*,*) ' Kick Jacobian ', REAL(KickJacobian) + !WRITE (*,*) ' KickVandPFunction = ' , REAL(-KickVandPFunction) + !WRITE (*,*) ' Kick Unknown Vector = ' , REAL(KickUnknownVector) + !WRITE (*,*) 'SUM(StaticPressDiff) , SUM(FricPressLoss)', SUM(FlowEl(GasPocketElementNo(1) : i)%FricPressLoss) , SUM(FlowEl(GasPocketElementNo(1) : i)%StaticPressDiff) + !WRITE (*,*) 'Drillpipe, casing pressure', PressureGauges(1), PressureGauges(2) + END IF + + !IF (NoWelltoChokeEl > 0 .AND. FlowEl(OpenholeFirstEl - 1)%MaterialType == 1 .AND. WellHeadOpen) THEN ! kick is last element in choke line and does not exit. + ! KickWasExitingThroughChoke = .TRUE. + ! GasPocketDensity%Array(NoGasPocket) = (GasPocketweight%Array(NoGasPocket) / GasPocketModifiedVol%Array(NoGasPocket)) / convft3toUSgal ! [lbm/ft^3 to ppg] + ! ExitMass = (1.0 - (GasPocketModifiedVol%Array(NoGasPocket) / GasPocketNewVol%Array(NoGasPocket))) * GasPocketWeight%Array(NoGasPocket) ! exit mass due to expand + ! WRITE (*,*) ' ExitMass due to expand = ', GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal , ExitMass + !END IF + + !WRITE (*,*) 'Horiz 1' + + KickInFluxConditions = (Reservoir%FormationTop < TD_WellGeneral%WellTotalVerticalLength) .AND. (NOT(Reservoir%InactiveInflux)) .AND. (FormPressure > BottomHolePress + 5.0) + IF (KickInFluxConditions) THEN + KickFlux = .TRUE. + + CALL NewGasKick + + !WRITE (*,*) 'Kick Flux top' , KickFlux + !WRITE (*,*) 'FormPressure, BottomHolePress, FormationTop, TD_WellGeneral%WellTotalVerticalLength' , FormPressure, BottomHolePress, FormationTop, TD_WellGeneral%WellTotalVerticalLength + + ELSE + IF (ALLOCATED(GasPocketWeight%Array) .AND. KickFlux) THEN + KickOffBottom = .TRUE. + WRITE (*,*) 'Kick Off Bottom' + WRITE (*,*) 'FormPressure , BottomHolePress' , FormPressure , BottomHolePress + !WRITE (*,*) 'No Press(psia) Vol(gal) Weight(lbm) Flow Induced(gpm) Flow El Press(psia)' + DO i = 1 , NoGasPocket + WRITE (*,102) i , GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * Convft3toUSgal, GasPocketWeight%Array(i), GasPocketFlowInduced%Array(i), FlowEl(GasPocketFlowEl(i , 1))%StartPress + StandardPress + END DO + END IF + KickFlux = .FALSE. + END IF + + IF (ALLOCATED(KickJacobian)) OldKickJacobian = KickJacobian + +102 FORMAT (I2, 3X, (F8.1), 2X, (F8.2), 2X, (F8.3), 8X, (F8.2), 10X, (F8.1)) + + !!!!!!!! Auto Choke Procedure + ! DO i = 1 , 5 + ! AreaChange = -1.0 * (BottomHolePressure - (FormPressure + BHPSafetyMargin)) / FlowEl(OpenholeFirstEl - 1)%Flowrare**2 * 89158.0 & + ! * (0.26 * 0.61)**2 * TotalOpenChokeArea**3 / (4.0 * ChokeDensity) + ! CHOOKE(1)%AreaChokeFinal = CHOOKE(1)%AreaChokeFinal + AreaChange / * Convfttoinch**2 + ! + ! + ! + ! END DO + ! + ! + ! + ! + ! + + + !WRITE (*,*) ' SecondaryKickWeight', SecondaryKickWeight + !WRITE (*,*) ' SecondaryKickVol', SecondaryKickVol + DownHole%SecondKickVolume = SecondaryKickVol + + + + IF (WellHeadOpen == .FALSE. .OR. (FlowEl(OpenholeFirstEl - 1)%Flowrate < PressFlowrateTolerance .AND. FlowEl(AnnulusLastEl)%Flowrate < PressFlowrateTolerance)) THEN + OnShakerDensity = 0.0 + ELSE IF (FlowEl(OpenholeFirstEl - 1)%MaterialType == 1 .AND. ChokeKroneckerDelta == 1) THEN + OnShakerDensity = 2.0 + ELSE IF (ChokeKroneckerDelta == 0) THEN + OnShakerDensity = FlowEl(AnnulusLastEl)%Density + ELSE IF (ChokeKroneckerDelta == 1) THEN !!!(FlowEl(OpenholeFirstEl - 1)%Flowrate > PressFlowrateTolerance .AND. FlowEl(AnnulusLastEl)%Flowrate < PressFlowrateTolerance) THEN + OnShakerDensity = FlowEl(OpenholeFirstEl - 1)%Density + ELSE + OnShakerDensity = (FlowEl(OpenholeFirstEl - 1)%Density * FlowEl(OpenholeFirstEl - 1)%Flowrate & + + FlowEl(AnnulusLastEl)%Density * FlowEl(AnnulusLastEl)%Flowrate) / (FlowEl(OpenholeFirstEl - 1)%Flowrate + FlowEl(AnnulusLastEl)%Flowrate) + END IF + !WRITE (*,*) 'ANINT(OnShakerDensity * 100) / 100', ANINT(OnShakerDensity * 100) / 100 , OnShakerDensity + CALL Set_MudWeightOut(ANINT(OnShakerDensity * 100) / 100) + + + IF (ALLOCATED(FinalFlowEl)) DEALLOCATE(FinalFlowEl) + ALLOCATE(FinalFlowEl(NumbEl)) + + FinalFlowEl(:)%StartX = FlowEl(:)%StartX + FinalFlowEl(:)%EndX = FlowEl(:)%EndX + FinalFlowEl(:)%StartTVD = FlowEl(:)%StartTVD + FinalFlowEl(:)%EndTVD = FlowEl(:)%EndTVD + FinalFlowEl(:)%Length = FlowEl(:)%Length + FinalFlowEl(:)%DepthDiff = FlowEl(:)%DepthDiff + FinalFlowEl(:)%density = FlowEl(:)%density + FinalFlowEl(:)%StartPress = FlowEl(:)%StartPress + FinalFlowEl(:)%EndPress = FlowEl(:)%EndPress + FinalFlowEl(:)%dPdLFric = FlowEl(:)%dPdLFric + FinalFlowEl(:)%dPdLGrav = FlowEl(:)%dPdLGrav + + !WRITE (*,*) 'FlowRate=', FlowEl(AnnulusFirstEl)%FlowRate + !WRITE (*,*) 'Pressure Loss in Drill String', SUM(FlowEl(StringFirstEl : StringLastEl)%FricPressLoss) + !WRITE (*,*) 'Pressure Loss in Annulus', SUM(FlowEl(AnnulusFirstEl : AnnulusLastEl)%FricPressLoss) + !MDObserve(:) = [3000.0 , 4349.0 , 11880.0 , 19880.0 , 21680.0] + !NomMd (:) = [3000 , 4298 , 11690 , 19690 , 21490] + !DO i = 1 , 5 + ! CALL TVD_Calculator(MDObserve(i) , TVDObserve(i)) + !END DO + ! + !DO i = 1 , 5 + ! + ! WRITE (*,*) 'MDObserve(i)', INT(NomMD(i)) + ! WRITE (*,*) 'TVDObserve(i)', INT(TVDObserve(i)) + ! + ! DO j = StringFirstEl , StringLastEl + ! IF (INT(MDObserve(i)) < INT(FinalFlowEl(j)%EndX)) EXIT + ! END DO + ! StPressObserve(i) = FlowEl(j)%StartPress - (MDObserve(i) - FlowEl(j)%StartX) * FlowEl(j)%dPdLfric + (TVDObserve(i) - FlowEl(j)%StartTVD) * FlowEl(j)%dPdLGrav + ! WRITE (*,*) 'String Pressure', INT(StPressObserve(i)) + ! + ! + ! + ! IF (INT(MDObserve(i)) <= INT(FlowEl(AnnulusFirstEl)%StartX)) THEN !! mouse pointer is in the annulus space + ! DO j = AnnulusFirstEl , AnnulusLastEl + ! IF (INT(FlowEl(j)%EndX) <= INT(MDObserve(i))) EXIT + ! END DO + ! ELSE IF (INT(MDObserve(i)) > INT(FinalFlowEl(NumbEl)%EndX)) THEN ! mouse pointer is in the open hole space + ! DO j = OpenholeFirstEl , NumbEl + ! IF (INT(FinalFlowEl(j)%EndX) <= INT(MDObserve(i))) EXIT + ! END DO + ! END IF + ! AnnPressObserve(i) = FlowEl(j)%StartPress - (FlowEl(j)%StartX - MDObserve(i)) * FlowEl(j)%dPdLfric & + ! - (FlowEl(j)%StartTVD - TVDObserve(i)) * FlowEl(j)%dPdLGrav + ! WRITE (*,*) 'Annulus Pressure', INT(AnnPressObserve(i)) + ! + ! + !END DO + + + + + END SUBROUTINE + + + +SUBROUTINE SOLVE_LINEAR_EQUATIONS(A , x , b , error, dim) + + !!! This subroutine solves a linear systems of equations Ax=b + !! if vaiable erorr changed its value to .FALSE. means that the system of equations cab not be solved + !! I use this subroutine to solve the linearized equations which uprising in calculation of volume and pressure of gas kick pockets + + use KickVARIABLESModule + + IMPLICIT NONE + INTEGER , INTENT(IN) :: dim + REAL(8) , DIMENSION(dim,dim) , INTENT(in) :: A + REAL , DIMENSION(dim) , INTENT(OUT) :: x + REAL(8) , DIMENSION(dim) , INTENT(in) :: b + LOGICAL , INTENT(OUT) :: error + REAL(8) , DIMENSION(:,:) , ALLOCATABLE :: m + INTEGER , DIMENSION(1) :: max_loc + REAL(8) , DIMENSION(:) , ALLOCATABLE :: temp_row + INTEGER :: n , k + + !WRITE (*,*) 'SIZE(A , dim = 1), SIZE(A , dim = 2), SIZE(b)', SIZE(A , dim = 1), SIZE(A , dim = 2), SIZE(b) + error = (SIZE(A , dim = 1) /= SIZE(b)) .OR. (SIZE(A , dim = 2) /= SIZE(b)) + !WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 1' , error + + IF (error) THEN + x = 0.0d0 + RETURN + END IF + n = SIZE(b) + + ALLOCATE (m(n , n + 1) , temp_row(n + 1)) + m(1:n , 1:n) = A + m(1:n , n + 1) = b + !WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 2' , m + ! Triangularization phase + TRIANG_LOOP: DO k = 1 , n + max_loc = MAXLOC(ABS(m(k:n , k))) + temp_row(k:n + 1) = m(k , k:n + 1) + m(k , k:n+1) = m(k-1+max_loc(1) , k:n+1) + m(k - 1 + max_loc(1) , k:n + 1) = temp_row(k:n + 1) + !WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 3' , max_loc + + IF (m(k , k) == 0) THEN + error = .TRUE. + !WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 4' + EXIT TRIANG_LOOP + ELSE + !WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 5' + m(k , k : n + 1) = m(k , k : n + 1) / m(k , k) + m(k + 1 : n , k + 1 : n + 1) = m(k + 1 : n , k + 1 : n + 1) - SPREAD(m(k , k + 1:n + 1) , 1, n - k) * SPREAD(m(k + 1:n , k) , 2 , n - k + 1) + END IF + END DO TRIANG_LOOP + !WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 6' + + ! Back substitution phase + IF (error) THEN + x = 0.0 + ELSE + DO k = n , 1 , -1 + x(k) = REAL(m(k , n + 1) - SUM(m(k , k + 1 : n) * x(k + 1 : n))) + !WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 7' + END DO + END IF + + DEALLOCATE(m , temp_row) + +END SUBROUTINE solve_linear_equations + \ No newline at end of file diff --git a/FluidFlow-old/Pressure_Display_VARIABLES.f90 b/FluidFlow-old/Pressure_Display_VARIABLES.f90 new file mode 100644 index 0000000..dc7e9ce --- /dev/null +++ b/FluidFlow-old/Pressure_Display_VARIABLES.f90 @@ -0,0 +1,32 @@ +MODULE PressureDisplayVARIABLES + + USE DynamicRealArray + + IMPLICIT NONE + + + INTEGER :: NoGauges + REAL , DIMENSION(6) :: PressureGauges + INTEGER :: SoundSpeed ! speed of sound [ft/s] + INTEGER , DIMENSION(3) :: PressureTimeStepDelay + TYPE(DynamicRealArrayType) :: PumpPressureDelay + TYPE(DynamicRealArrayType) :: CasingPressureDelay + TYPE(DynamicRealArrayType) :: BottomHolePressureDelay + TYPE(DynamicRealArrayType) :: ShoePressureDelay + + + + TYPE :: ObservationAndGaugePointsInformations ! We have some gauges and may be have many observation points like casing shoe, bottomhole , etc. + ! This module stores information of these points to calculate pressure, density and other desired properties + ! at these points + ! Locations: 1: Stand Pipe , 2: Choke Manifold, 3: Botton Hole, 4: Under Bit, 5: Shoe, 6: Before BOP + INTEGER :: ElementNo ! Element Nubmer based on mud elements + REAL :: DistancetoRefrence ! Distance from pump or the end of fluid path [ft] + REAL :: ElementTrueDepth ! True depth of point or gauge [ft] + REAL :: Pressure ! Pressure [psi] + END TYPE + + !TYPE(ObservationAndGaugePointsInformations) , ALLOCATABLE :: GaugePoint(:) + TYPE(ObservationAndGaugePointsInformations) , ALLOCATABLE :: ObservationPoint(:) + + END MODULE \ No newline at end of file diff --git a/FluidFlow-old/Pressure_Distribution_VARIABLES.f90 b/FluidFlow-old/Pressure_Distribution_VARIABLES.f90 new file mode 100644 index 0000000..b4f52b5 --- /dev/null +++ b/FluidFlow-old/Pressure_Distribution_VARIABLES.f90 @@ -0,0 +1,178 @@ +MODULE FricPressDropVars + + + !! Record of revisions + !! Date Programmer Discription of change + !! ------ ------------ ----------------------- + !! 1396/07/26 Sheikh Original code + !! + + IMPLICIT NONE + + + + REAL :: TotFricPressLoss ! Total Frictional Pressure Loss [psi] + REAL :: FlowrateNearShoe + INTEGER :: NoHorizontalEl ! number of elements in horizontal pump to string line + INTEGER :: NoStringEl ! number of elements in string + INTEGER :: NoAnnulusEl ! number of elements in annulus space + INTEGER :: NoWellToChokeEl ! number of elements in well head to choke manifold + INTEGER :: NoOpenHoleEl ! number of elements in openhole + INTEGER :: NumbEl ! number of flow elements in horizontal line, string, annulus and openhole + INTEGER :: StringFirstEl ! number of first string element + INTEGER :: StringLastEl ! number of last string element + INTEGER :: AnnulusFirstEl ! number of first annulus element + INTEGER :: AnnulusLastEl ! number of last annulus element + INTEGER :: ChokeFirstEl ! number of first choke element + INTEGER :: ChokeLastEl ! number of last choke element + INTEGER :: OpenholeFirstEl ! number of first openhole element + INTEGER :: ShoeFlowElNo ! the flow element that starts from shoe, in other word the number of upper element adjacent to shoe + REAL :: KBOP ! DeltaPBOP = KBOP * Q**2 [psi * min^2 / gal^2] + REAL :: KBit ! DeltaPBit = KBit * Q**2 [psi * min^2 / gal^2] + + !!!! Choke Variables + REAL :: BackPressure , NewBackPressure ! back pressure at riser or choke line [psi] + REAL :: Kchoke ! DeltaPchoke = Kchoke * Q**2 [psi * min^2 / gal^2] + REAL :: TotalOpenChokeArea , OldTotalOpenChokeArea , ChokeBypassArea , NewTotalOpenChokeArea , AreaChange + REAL :: BHPSafetyMargin , AChBHPTol ! BHP safety margin and BHP Tolerance in Auto Choke mode [psi] + REAL(8) :: OnShakerDensity ! Outlet Density of well for displaying in drillwatch and data [ppg] + + LOGICAL :: FloatValveIn + LOGICAL :: FloatValveOpen , FloatValveWasOpen + LOGICAL :: BitTotallyPluged + + REAL :: ClingingFactor = 0.45 ! in calculating surge and swab pressure changes + REAL :: MudCompressibility = 2.7E-6 ! Volumne change relative to Volume/1psi, for example for change of 1000 psi in pressure, volume changes 0.27% [1/psi] + REAL :: FloatValveMinOpenPressure = 1.0 ! minimum pressure that opens the float valve [psi] + REAL :: StMudVol ! Total mud volume of Horizontal and String that may be compressed [gal] + REAL :: AnnMudVol ! Total mud volume of Bottom hole, Annulus and Choke line that may be compressed [gal] + REAL :: PumpToManifoldMudVol + REAL :: StCompressedMudVol ! Compressed mud volume in Horizontal and String [gal] + REAL :: AnnCompressedMudVol ! Compressed mud volume in Bottom hole, Annulus and Choke line [gal] + REAL :: PumpToManifoldCompressedMudVol + REAL :: StDeltaPDueToCompressibility ! Pressure increase due to mud compressibility in Horizontal and String [psi] + REAL :: AnnDeltaPDueToCompressibility ! Pressure increase due to mud compressibility in Bottom hole, Annulus and Choke line [psi] (usually when wellhead is closed) + REAL :: PumpToManifoldDeltaPDueToCompressibility + REAL :: StDeltaPtoDeltaVCompressibility ! string pressure change due to compressibility [psi/gal] + REAL :: AnnDeltaPtoDeltaVCompressibility ! annulus and openhole pressure change due to compressibility [psi/gal] + + + !!!! Problem Variables (Choke and Bit) + + INTEGER :: ManChoke1Plug , ManChoke2Plug ! = 1 if choke is plugged , = 0 else + INTEGER :: ManChoke1Washout , ManChoke2Washout ! = 1 if choke is washed out , = 0 else + INTEGER :: BitJetsPlugged , BitJetsWashedOut + INTEGER :: CasingPressure_DataDisplayMalF, CasingPressure_ChokeMalF + + !!!!!! Note that bit is not an element in these calculations + + + TYPE, PUBLIC :: PressDropCalcElemInfo + + !! Geometrical variables + REAL(8) :: Length ! Length of a Flow element [ft] + REAL(8) :: DepthDiff ! Difference between depth of start and end of element [ft] + REAL(8) :: StartX , EndX ! start and end point (measured depth) of flow element [ft] + REAL(8) :: StartTVD , EndTVD ! Start and End point True Vertical Depth of flow element [ft] + REAL :: Od , Id , Dhyd ! Outer, Inner and hydraulic diameter of flow element [in] + REAL :: Area ! area of element [ft^2] + INTEGER :: alpha ! geometry factor: 0 = pipe (ID=0) , 1 = annulus + INTEGER :: FrictionDirection ! = 1 if flowrate is positive, so frictional pressure gradient is in direction of preassumed + ! flowrate, = -1 if not above condition usually in Swab conditions + !! Flow variables + INTEGER :: MaterialType ! = 0 for mud , = 2 for gas + REAL :: volume , vel , density , FlowRate ! volume [ft^3], velocity [ft/s], density of fluid flow [ppg], flow rate [gpm] + REAL :: Gf ! geometry shear rate correction [-] + !! Rheological and frictional variables + REAL :: Theta600 , Theta300 ! Fann data at 600 and 300 rpm as rheological data + ! REAL(8) :: VelCritBing , VelCritPow ! critical velocity in Bingham Plastic and Power law model [ft/min] + REAL :: muPlastic , YieldP ! plastic viscosity [cp] and yield point [lbf/(100*ft^2)] + REAL :: mueff ! Effective or apparent viscosity which is used in calculation of generalized Reynolds number + REAL :: nIndex , kIndex ! n: flow behaivior index [-] and k: consistency factor [lbf*s^n/(100*ft^2)] + REAL :: gammaW , tauW ! shear rate at the wall [1/s] and wall shear stress [lbf/(100*ft^2)] + REAL :: GenRe ! generalized Reynolds number in power law model [-] + REAL :: ReCrit = 2100.0 ! Critical Reynolds number for Newtonian model and Bingham plastic model + REAL :: ReCritLam , ReCritTurb ! laminar and turbulent critical Reynolds + REAL :: f ! Fanning friction factor [-] + REAL :: a , b ! parameters for calculationg friction factor in turbulent regime for power law model [-] + LOGICAL :: LaminarRegime ! = .TRUE. if flow regime is laminar and = .FALSE. if flowregime is not + LOGICAL :: TurbulentRegime ! = .TRUE. if flow regime is turbulent and = .FALSE. if flowregime is not + !! Pressure change variables + REAL :: StartPress , EndPress ! Pressure at start and end of an element [psi] + REAL :: dPdLFric ! frictional pressure drop gradient in each element [psi/ft] + REAL :: dPdLGrav ! gravitional pressure gradient = 0.052 * Density [psi/ft] + REAL :: FricPressLoss ! frictional pressure loss in each element [psi] + REAL :: StaticPressDiff ! static pressure difference between top and bottom of a pocket [psi] always positive + REAL :: FricToQPartialDiff ! partial differentiation of friction relative to volume flow rate + + + + END TYPE PressDropCalcElemInfo + + TYPE (PressDropCalcElemInfo) , ALLOCATABLE :: FlowEl(:) ! FlowEl: Pressure Drop Calculation Elements The dimension is equal to the number of flow elements + + + + + TYPE, PUBLIC :: FinalPressDropCalcElemInfo + + !!! for use in calculationg properties of a point in 'downhole view' page + + REAL(8) :: StartX , EndX , StartTVD , EndTVD , Length , DepthDiff ! start and end point of flow element [ft] + REAL :: density ! density of fluid flow [ppg], flow rate [gpm] + REAL :: StartPress ! Pressure at start of an element [psi] + REAL :: EndPress ! Pressure at end of an element [psi] + REAL :: dPdLFric ! frictional pressure drop gradient in each element [psi/ft] + REAL :: dPdLGrav ! gravitional pressure gradient = 0.052 * Density [psi/ft] + + END TYPE FinalPressDropCalcElemInfo + + TYPE (FinalPressDropCalcElemInfo) , ALLOCATABLE :: FinalFlowEl(:) ! FlowEl: Pressure Drop Calculation Elements The dimension is equal to the number of flow elements + + + + + END MODULE FricPressDropVars + + MODULE UTUBEVARS + + REAL :: QUTubeInput ! flow rate from string to annulus which caused by head difference at two sides of U-tube [gpm] + REAL :: QUtubeOutput ! flow rate from annulus to string which caused by head difference at two sides of U-tube [gpm] + REAL :: PressureDp ! pressure at bit or end of drill string from drill string path [psi] + REAL :: PressureAnn ! pressure at bit or end of drill string from annular path [psi] + + END MODULE + + SUBROUTINE DeallocateFlowTypes + + USE FricPressDropVarsModule + use PressureDisplayVARIABLESModule + use KickVARIABLESModule + + IMPLICIT NONE + + + IF (ALLOCATED(FlowEl)) DEALLOCATE(FlowEl) + IF (ALLOCATED(FinalFlowEl)) DEALLOCATE(FinalFlowEl) + IF (ALLOCATED(GasPocketWeight%Array)) CALL GasPocketWeight%Empty() + IF (ALLOCATED(GasPocketNewPress%Array)) CALL GasPocketNewPress%Empty() + IF (ALLOCATED(GasPocketOldPress%Array)) CALL GasPocketOldPress%Empty() + IF (ALLOCATED(GasPocketNewTemp%Array)) CALL GasPocketNewTemp%Empty() + IF (ALLOCATED(GasPocketOldTemp%Array)) CALL GasPocketOldTemp%Empty() + IF (ALLOCATED(GasPocketNewVol%Array)) CALL GasPocketNewVol%Empty() + IF (ALLOCATED(GasPocketOldVol%Array)) CALL GasPocketOldVol%Empty() + IF (ALLOCATED(GasPocketdeltaVol%Array)) CALL GasPocketdeltaVol%Empty() + IF (ALLOCATED(GasPocketModifiedVol%Array)) CALL GasPocketModifiedVol%Empty() + IF (ALLOCATED(GasPocketFlowInduced%Array)) CALL GasPocketFlowInduced%Empty() + IF (ALLOCATED(GasPocketDensity%Array)) CALL GasPocketDensity%Empty() + IF (ALLOCATED(GasPocketCompressibility%Array)) CALL GasPocketCompressibility%Empty() + IF (ALLOCATED(GasPocketFlowEl)) DEALLOCATE(GasPocketFlowEl) + IF (ALLOCATED(KickJacobian)) DEALLOCATE(KickJacobian) + IF (ALLOCATED(OldKickJacobian)) DEALLOCATE(OldKickJacobian) + IF (ALLOCATED(KickVandPFunction)) DEALLOCATE(KickVandPFunction) + IF (ALLOCATED(KickUnknownVector)) DEALLOCATE(KickUnknownVector) + IF (ALLOCATED(KickCorrectionVector)) DEALLOCATE(KickCorrectionVector) + + + END SUBROUTINE + \ No newline at end of file diff --git a/FluidFlow-old/String_Property_Calculator.f90 b/FluidFlow-old/String_Property_Calculator.f90 new file mode 100644 index 0000000..cdd609a --- /dev/null +++ b/FluidFlow-old/String_Property_Calculator.f90 @@ -0,0 +1,31 @@ +SUBROUTINE StringPropertyCalculator (md, den, pre, tem) + + !!! This subroutine gets location of a guage or an observation point and determines information of that point such as pressure, density, velocity and temperature later. + use PressureDisplayVARIABLESModule + USE Fluid_Flow_Startup_Vars + !USE MudSystemVARIABLES + USE FricPressDropVarsModule + !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure + !USE CDataDisplayConsoleVariables , CasingPressureDataDisplay=>CasingPressure!, StandPipePressureDataDisplay=>StandPipePressure + USE CDrillWatchVariables + + IMPLICIT NONE + INTEGER, intent(in) :: md ! input + REAL(8) :: TVD + real(8), intent(inout) :: den ! output + real(8), intent(inout) :: pre ! output + real(8), intent(inout) :: tem ! output + + INTEGER :: ilocal + + CALL TVD_Calculator(md * 1.d0 , TVD) + + DO ilocal = StringFirstEl , StringLastEl + IF (md < INT(FinalFlowEl(ilocal)%EndX)) EXIT + END DO + den = FinalFlowEl(ilocal)%Density + pre = FinalFlowEl(ilocal)%StartPress - (md - FinalFlowEl(ilocal)%StartX) * FinalFlowEl(ilocal)%dPdLfric & + + (TVD - FinalFlowEl(ilocal)%StartTVD) * FinalFlowEl(ilocal)%dPdLGrav + tem = 500 + + END SUBROUTINE \ No newline at end of file diff --git a/FluidFlow-old/Utube.f90 b/FluidFlow-old/Utube.f90 new file mode 100644 index 0000000..5d4167a --- /dev/null +++ b/FluidFlow-old/Utube.f90 @@ -0,0 +1,117 @@ +SUBROUTINE Utube + + !! This subroutine calculates flow rate when pump is off, pump is disconnected from drill pipe + !! and both annulus and drill pipe are exposed to atmosphere pressure and thus a U-tube situation is occurs + + !! Record of revisions + !! Date Programmer Discription of change + !! ------ ------------ ----------------------- + !! 1396/07/29 Sheikh Original code + !! 1396/08/09 Sheikh Two-side U-tube + !! + + USE FricPressDropVarsModule + USE MudSystemVARIABLES + use UTUBEVARSModule + USE Fluid_Flow_Startup_Vars + + IMPLICIT NONE + + + + INTEGER :: i ,j, ibit , ij , ijk + REAL :: AreaBeforeBit !!! Area of element before bit in U-Tube condition [in^2] + + QUTubeInput = 1.0 + QUTubeOutput = 1.0 + TotFricPressLoss = 0 + BitPressLoss = 0 + PressureDp = 0 + PressureAnn = 0 +!!!!!!!!!!!!!!!!!!!!!! Bit +!!!!!!!!!!!! Calculating Pressure at the bottom of drill string from mud columns in drill pipes and annulus space + + PressureDp = SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + + PressureAnn = SUM(FlowEl(AnnulusFirstEl : AnnulusLastEl)%StaticPressDiff) +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!! U tube:: flow from string to annulus + IF ((PressureDp - PressureAnn) > UTubePressTolerance) THEN + DO ijk = 1 , 10 + FlowEl(StringFirstEl : AnnulusLastEl)%Flowrate = QUTubeInput + !WRITE (*,*) 'QUTubeInput', FlowEl(AnnulusLastEl)%Flowrate + DO ij = StringFirstEl , AnnulusLastEl !!!!! Updating values of flowrates + CALL FricPressDrop(ij) + CALL PartialDerivativeFricToFlowRate(ij) + !WRITE (*,*) 'FricPressDrop, PartialDerivative', FlowEl(ij)%FricPressLoss, FlowEl(ij)%FricToQPartialDiff, FlowEl(ij)%Length + END DO + + !!!!!!!!!!!!!! Bit pressure drop calculation + IF (BitTrue) THEN + i = NoHorizontalEl + NoStringEl + AreaBeforeBit = FlowEl(i)%Area * Convfttoinch**2 + BitPressLoss = FlowEl(i)%density * Convft3toUSgal * (FlowEl(i)%vel**2 * ((AreaBeforeBit/BitTotNozzArea)**2 - 1.)) / 2. / Convlbftolbm / Convfttoinch**2 + END IF + + !!!!!!!!!!!!!!!!!!!!!!!!!!! + i = NoHorizontalEl + 1 + j = NoHorizontalEl + NoStringEl + NoAnnulusEl + !IF (ALLOCATED(FlowEl)) THEN + ! WRITE (*,*) ' H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl + !END IF + + TotFricPressLoss = SUM(FlowEl(i : j)%FricPressLoss) + BitPressLoss + IF (ABS((PressureDp - PressureAnn) - TotFricPressLoss) <= UTubePressTolerance .OR. QUTubeInput < 1.0) EXIT ! tolerance set to 1.0 psi + IF ((PressureDp - PressureAnn) > TotFricPressLoss) THEN + QUTubeInput = QUTubeInput + ((PressureDp - PressureAnn) - TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff) + ELSE IF ((PressureDp - PressureAnn) < TotFricPressLoss) THEN + QUTubeInput = QUTubeInput + ((PressureDp - PressureAnn) - TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff) + END IF + !WRITE (*,*) 'QUTubeInput, TotFricPressLoss', QUTubeInput, TotFricPressLoss + !WRITE (*,*) '1) PressureDp, PressureAnn', PressureDp, PressureAnn, TotFricPressLoss, QUTubeInput + + END DO + QUTubeOutput = 0.0 +!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!! U tube:: flow from annulus to string + ELSE IF ((PressureAnn - PressureDp) > UTubePressTolerance) THEN + DO ijk = 1 , 10 + DO ij = NoHorizontalEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl !!!!! Updating values of flowrates + FlowEl(ij)%Flowrate = QUTubeOutput + CALL FricPressDrop(ij) + CALL PartialDerivativeFricToFlowRate(ij) + END DO + + !!!!!!!!!!!!!! Bit pressure drop calculation + IF (BitTrue) THEN + !DO i = NumbEl , 1 , -1 !! This loop starts from the first elements of string and check the elements to reach the bit at the bottom of string + ! IF (FlowEl(i)%Id==0) CYCLE + i = NoHorizontalEl + NoStringEl + 1 + AreaBeforeBit = FlowEl(i)%Area * Convfttoinch**2 + BitPressLoss = FlowEl(i)%density * Convft3toUSgal * (FlowEl(i)%vel**2 * ((AreaBeforeBit/BitTotNozzArea)**2 - 1.)) / 2. / Convlbftolbm / Convfttoinch**2 + !IF (FlowEl(i)%Id>0) EXIT + !END DO + END IF + !!!!!!!!!!!!!!!!!!!!!!!!!!! + i = NoHorizontalEl + 1 + j = NoHorizontalEl + NoStringEl + NoAnnulusEl + TotFricPressLoss = SUM(FlowEl(i : j)%FricPressLoss) + BitPressLoss + + IF (ABS((PressureDp - PressureAnn) - TotFricPressLoss) <= UTubePressTolerance) EXIT ! tolerance set to 1.0 psi + IF ((PressureAnn - PressureDp) > TotFricPressLoss) THEN + QUTubeOutput = QUTubeOutput - (((PressureAnn - PressureDp) - TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff)) + ELSE IF ((PressureAnn - PressureDp) < TotFricPressLoss) THEN + QUTubeOutput = QUTubeOutput + (((PressureAnn - PressureDp) - TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff)) + END IF + !WRITE (*,*) 'QUTubeOutput, TotFricPressLoss', QUTubeOutput, TotFricPressLoss + + WRITE (*,*) '2) PressureDp, PressureAnn', PressureDp, PressureAnn, TotFricPressLoss + END DO + QUTubeInput = 0.0 +!!!!!!!!!!!! No U-Tube + ELSE + QUTubeInput = 0.0 + QUTubeOutput = 0.0 + END IF + +END SUBROUTINE \ No newline at end of file diff --git a/FluidFlow-old/Well_Pressure_Data_Transfer.f90 b/FluidFlow-old/Well_Pressure_Data_Transfer.f90 new file mode 100644 index 0000000..b07a903 --- /dev/null +++ b/FluidFlow-old/Well_Pressure_Data_Transfer.f90 @@ -0,0 +1,775 @@ +SUBROUTINE WellPressureDataTransfer + + !! This subroutine calculates pressure distribution in well + !! We divide well hydraulic system to 4 zones. 1- pump to string zone; this zone is horizontal + !! 2- string zone; this zone includes drill pipes and collars and is vertical or neraly vertical + !! 3- annulus zone; this zone includes annulus space between string and openhole or casing + !! 4- Openhole zone; this zone includes spaces under bit to bottom of the wellbore + !! The last two zone includes annulus space and open hole, are influenced by kicks and have crucial role in + !! computing pressure distribution because reference point (back pressure in well head open condition + !! and bottomhole pressure in well head closed condition) are in one of them. because of this, pressure + !! distribution calculates in two subroutines : PressureAnnAndOHDistribution and PressurePumptoBitDistribution + !! pressure change through well consist of pressure change due to friction, change of elevation and acceleration + !! frictional pressure drop calculated by subroutine Sub_Press_Drop_Calculator + !! This subroutine includes hydrostatic pressure and later will include effect of corss-section area change + !! which causes acceleration or decceleration of flow + Use ConfigurationVariables + USE FricPressDropVarsModule + use MudSystemModule + USE MudSystemVARIABLES + USE GeoElements_FluidModule + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule + USE CMudPropertiesVariables + USE CBopStackVariables + USE sROP_Variables + USE CHOKEVARIABLES, PI2 => PI + USE CChokeManifoldVariables + USE CBitProblemsVariables + USE CChokeProblemsVariables + USE CStringConfigurationVariables + USE CDrillWatchVariables + USE CDataDisplayConsoleVariables + + + IMPLICIT NONE + + INTEGER :: i , j + REAL :: InstantaneousTotalOpenChokeArea , VolumeDensityProduct + + ChokeIsClosing = .FALSE. + Kchoke = 0.0 + KBit = 0.0 + + + !!!!!!!!!!!!!!!! bit is present + BitTrue = Configuration%StringConfiguration%StringConfigurations(1)%ComponentType == Bit_ComponentType ! Bit_ComponentType = 0 + BitCd = 0.98 + BitNozzDia = 32.0 * Configuration%StringConfiguration%BitDefinition%BitNozzleSize ! nozzle diameter in 1/32 in + BitNozzleArea = 7.6699E-4 * BitNozzDia**2 + BitNozzleNum = Configuration%StringConfiguration%BitDefinition%BitNozzleNo - BitJetsPlugged * BitProblems%PlugJetsCount + BitTotNozzArea = BitNozzleNum * BitNozzleArea + 0.5 * BitJetsWashedOut * BitProblems%JetWashoutCount * BitNozzleArea + IF (BitNozzleNum == 0) THEN + BitTotallyPluged = .TRUE. + ELSE + BitTotallyPluged = .FALSE. + END IF + + FloatValveIn = Configuration%StringConfiguration%BitDefinition%FloatValve + !FloatValveOpen = .TRUE. + !IF (JetWashoutCount > 0 .OR. PlugJetsCount > 0) THEN + ! WRITE (*,*) 'PlugJetsCount' , PlugJetsCount + ! WRITE (*,*) 'JetWashoutCount', JetWashoutCount + !END IF + + !WRITE (*,*) 'BitNozzleNum', BitNozzleNum + !WRITE (*,*) 'BitTotNozzArea', BitTotNozzArea + !WRITE (*,*) 'Float Valve??', BitDefinition%FloatValve + + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + IF(ALLOCATED(GasPocketFlowEl)) DEALLOCATE(GasPocketFlowEl) + +!!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed ) + ChokeKroneckerDelta = 0 + + + IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN + + WellHeadOpen = .FALSE. + !WRITE (*,*) ' Well Head is closed ' + ELSE + WellHeadOpen = .TRUE. + END IF + + IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen) ChokeKroneckerDelta = 1 + !WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + + NoHorizontalEl = MudSystem%NoHorizontalMudElements + NoStringEl = MudSystem%NoStringMudElements + NoAnnulusEl = MudSystem%NoCasingMudElements + NoWellToChokeEl = 0 + 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) + ALLOCATE(FlowEl(NumbEl)) + + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Transfering Data from module:MudSystemVARIABLES to module:FricPressDropVars to calculate Pressure distribution in flow path + !!!!!!!!!!!!!!!!!!!!!!! Horizontal line + !WRITE (*,*) 'H', NoHorizontalEl + DO i = 1 , NoHorizontalEl + 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 = 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 (MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air + FlowEl(i)%MaterialType = 0 + ELSE IF (MudSystem%MudType_MudElement%Array(i) == 4) THEN + FlowEl(i)%MaterialType = 4 + ELSE + FlowEl(i)%MaterialType = 1 + END IF + + FlowEl(i)%dPdLgrav = 0.0 + FlowEl(i)%StaticPressDiff = 0.0 + + !WRITE (*,*) 'H density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType + + + END DO + !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!!!!! String + !WRITE (*,*) 'S', NoStringEl + StringFirstEl = NoHorizontalEl + 1 + StringLastEl = NoHorizontalEl + NoStringEl + DO i = NoHorizontalEl + 1 , NoHorizontalEl + NoStringEl + !WRITE (*,*) 'ST , i' , i + FlowEl(i)%StartX = MudSystem%Xstart_MudElement%Array(i) + !WRITE (*,*) 'StartX', FlowEl(i)%StartX + FlowEl(i)%EndX = MudSystem%Xend_MudElement%Array(i) + !WRITE (*,*) 'EndX', FlowEl(i)%EndX + FlowEl(i)%StartTVD = MudSystem%TVDstart_MudElement%Array(i) + !WRITE (*,*) 'StartTVD', FlowEl(i)%StartTVD + 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 = MudSystem%PipeOD_MudElement%Array(i) + !WRITE (*,*) 'Od', FlowEl(i)%Od + FlowEl(i)%Density = MudSystem%Density_MudElement%Array(i) + !WRITE (*,*) 'Density', FlowEl(i)%Density + + + FlowEl(i)%Dhyd = FlowEl(i)%Od + FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX) + !WRITE (*,*) 'Length', FlowEl(i)%Length + FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD) + !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 (MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air + FlowEl(i)%MaterialType = 0 + ELSE IF (MudSystem%MudType_MudElement%Array(i) == 4) THEN + FlowEl(i)%MaterialType = 4 + ELSE + FlowEl(i)%MaterialType = 1 + END IF + + IF (FlowEl(i)%MaterialType == 1 .OR. FlowEl(i)%MaterialType == 4) THEN + FlowEl(i)%dPdLgrav = 0.0 + ELSE + FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%Density + END IF + FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff) + + !WRITE (*,*) 'S density, length, DeltaPStatic' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%StaticPressDiff, FlowEl(i)%MaterialType + + + + END DO + !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!!!!!!!! Annulus + !WRITE (*,*) 'A', NoAnnulusEl + AnnulusFirstEl = NoHorizontalEl + NoStringEl + 1 + AnnulusLastEl = NoHorizontalEl + NoStringEl + NoAnnulusEl + DO i = NoHorizontalEl + NoStringEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl + 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 (MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air + FlowEl(i)%MaterialType = 0 + ELSE IF (MudSystem%MudType_MudElement%Array(i) == 4) THEN + FlowEl(i)%MaterialType = 4 + ELSE + FlowEl(i)%MaterialType = 1 + END IF + + IF (FlowEl(i)%MaterialType == 1 .OR. FlowEl(i)%MaterialType == 4) THEN + FlowEl(i)%dPdLgrav = 0.0 + ELSE + FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%density + END IF + FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff) + + !WRITE (*,*) 'A density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType + + + END DO + !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!! Well to choke manifold path + !ChokeFirstEl = AnnulusLastEl + 1 + !ChokeLastEl = OpenholeFirstEl - 1 + j = 1 + DO i = NoHorizontalEl + NoStringEl + NoAnnulusEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWelltoChokeEl + 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 = 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 (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 + + + FlowEl(i)%dPdLgrav = 0.0 + FlowEl(i)%StaticPressDiff = 0.0 + + !WRITE (*,*) 'Ch density, length, Type' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType + + j = j + 1 + + END DO + + !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!! Open Hole + OpenholeFirstEl = NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWelltoChokeEl + 1 + j = 1 + DO i = OpenholeFirstEl , NumbEl ! = NoHorizontalEl + NoStringEl + NoCasingEl + NoOpenHoleEl + 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 = 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 (MudSystem%MudTypeOp_MudElement%Array(j) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air + FlowEl(i)%MaterialType = 0 + ELSE IF (MudSystem%MudTypeOp_MudElement%Array(j) == 4) THEN + FlowEl(i)%MaterialType = 4 + ELSE + FlowEl(i)%MaterialType = 1 + END IF + + j = j + 1 + IF (FlowEl(i)%MaterialType == 1) THEN + FlowEl(i)%dPdLgrav = 0.0 + ELSE + FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%density + END IF + FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff) + + !WRITE (*,*) 'O density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType + + END DO + !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 + + !DO i = NoHorizontalEl + 1, NoHorizontalEl + NoStringEl + ! WRITE (*,*) 'element No, Start , Length, DeltaPSt', i, FlowEl(i)%StartX, FlowEl(i)%Length, FlowEl(i)%StaticPressDiff + !END DO +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!! Mud Element Viscosity Calculation + + DO i = 1 , NumbEl + IF (FlowEl(i)%MaterialType /= 0) CYCLE + IF (FlowEl(i)%density < 8.33) THEN + WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , StringFirstEl , AnnulusFirstEl , NoWellToChokeEl , OpenHoleFirstEl + + WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type' + DO j = 1 , NumbEl + WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType + END DO + + CALL ErrorStop('Density below water density (8.33)', i) + CYCLE + END IF + + FlowEl(i)%Theta600 = Theta600Refrence + 11.0 * (MAX(FlowEl(i)%density , 8.33) - DensityRefrence) + FlowEl(i)%Theta300 = Theta300Refrence + 6.0 * (MAX(FlowEl(i)%density , 8.33) - DensityRefrence) + !WRITE (*,*) 'i, Theta600, Theta600', i, FlowEl(i)%Theta600, FlowEl(i)%Theta300 + END DO +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + + FlowEl(:)%FlowRate = 0.0 + FlowEl(:)%StartPress = 0.0 + FlowEl(:)%EndPress = 0.0 + + !WRITE (*,*) 'NoGasPocket=' , SIZE(GasPocketWeight%Array) + + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + 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 = 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 + MudSystem%WellToChokeManifoldOpen = .FALSE. + OldTotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen + !WRITE (*,*) ' Choke Controler Here 2' + + 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' + ELSE + IF (InstantaneousTotalOpenChokeArea > OldTotalOpenChokeArea) THEN + TotalOpenChokeArea = MIN(1.1 * OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea) + WRITE (*,*) ' Choke is opening' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea + ELSE IF (InstantaneousTotalOpenChokeArea < OldTotalOpenChokeArea) THEN + TotalOpenChokeArea = MAX(0.9 * OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea) + WRITE (*,*) ' Choke is closing' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea + !ExitMass = 0.1 * ExitMass ! for decreasing mass exit due to expansion + ELSE + TotalOpenChokeArea = InstantaneousTotalOpenChokeArea + END IF + END IF + !WRITE (*,*) 'TotalOpenChokeArea=', TotalOpenChokeArea + + + + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed ) + ChokeKroneckerDelta = 0 + !WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen + !WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen + IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN + !WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen + !WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen + + WellHeadOpen = .FALSE. + !WRITE (*,*) ' Well Head is closed ' + ELSE + WellHeadOpen = .TRUE. + END IF + + 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 (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(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, MudSystem%StringFlowRate * dt / ConvMinToSec + IF (FlowEl(OpenholeFirstEl - 1)%MaterialType /= 1) THEN + CALL RemoveGasPocket(NoGasPocket) + WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', MudSystem%Choke_Kick_Saved_Volume_Final + END IF + + END IF + + + !NoGasPocket = SIZE(GasPocketWeight%Array) + IF (NoGasPocket > 0) CALL GasPocketFlowElementTransformer + END IF + + IF (NoWelltoChokeEl > 0) THEN + OldChokeDensity = ChokeDensity + !ChokeDensity = SUM(FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Density * FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Volume) / SUM(FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Volume) + !ChokeDensity = MAX(ChokeDensity , ChokeMinDensity) + VolumeDensityProduct = 0.0 + Do i = AnnulusLastEl + 1 , OpenholeFirstEl - 1 + VolumeDensityProduct = VolumeDensityProduct + ((MAX(FlowEl(i)%Density , ChokeMinDensity)) * FlowEl(i)%Volume) + End Do + ChokeDensity = VolumeDensityProduct / SUM(FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Volume) + + !IF ((ChokeDensity - OldChokeDensity) > (MaxChokeDensityChange * dt / Convmintosec)) THEN + ! ChokeDensity = OldChokeDensity + (MaxChokeDensityChange * dt / Convmintosec) + !ELSE IF ((OldChokeDensity - ChokeDensity) > (MaxChokeDensityChange * dt / Convmintosec)) THEN + ! ChokeDensity = OldChokeDensity - (MaxChokeDensityChange * dt / Convmintosec) + !END IF + + !WRITE (*,*) 'ChokeDensity=', ChokeDensity + Kchoke = (ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * TotalOpenChokeArea)**2)) * 4.d0 ! *4.d0: seyyed gofte + END IF + + IF (BitTotallyPluged == .FALSE.) THEN + KBit = FlowEl(StringLastEl)%density / 12042.0 / BitCd**2 / BitTotNozzArea**2 + END IF + + + +END SUBROUTINE WellPressureDataTransfer + + +SUBROUTINE GasPocketFlowElementTransformer + + !! This Subroutine makes relationship between fluid flow elements and gas pocket elements + !! The main variable of this subroutine is GasPocketFlowEl + !! For each gas pocket, GasPocketFlowEl has a row, which columns are numbers of flow elements which are contains that gas pocket + !! For example, if we have two gas pockets and they are in (7,8) and (12,3,4) flow elements respectively, + !! GasPocketFlowEl(1,:) = [12 , 3 , 4] and GasPocketFlowEl(2,:) = [7 , 8 , 0] + + + USE FricPressDropVarsModule + USE MudSystemVARIABLES + USE GeoElements_FluidModule + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule + USE CMudPropertiesVariables + USE CBopStackVariables + USE CDownHoleVariables + USE CError + + IMPLICIT NONE + + INTEGER :: i , j , k + REAL :: PressureCorrection + PressureCorrection = 1.0 + + ALLOCATE(GasPocketFlowEl(NoGasPocket , 1)) + GasPocketFlowEl(:,:) = 0 + !WRITE (*,*) 'NoGasPocket=' , NoGasPocket + + i = 1 + j = 1 + DO k = OpenholeFirstEl , NumbEl + IF (FlowEl(k)%MaterialType == 1) THEN + IF (j > 1) THEN + IF (GasPocketFlowEl(i , j - 1) /= k - 1) THEN + i = i + 1 + j = 1 + END IF + END IF + + IF (SIZE(GasPocketFlowEl , dim = 2) < j) THEN + ALLOCATE(tempGasPocketFlowEl(SIZE(GasPocketFlowEl , dim = 1) , SIZE(GasPocketFlowEl , dim = 2))) + tempGasPocketFlowEl = GasPocketFlowEl + DEALLOCATE(GasPocketFlowEl) + ALLOCATE(GasPocketFlowEl(SIZE(tempGasPocketFlowEl , dim = 1) , SIZE(tempGasPocketFlowEl , dim = 2) + 1)) + GasPocketFlowEl(: , 1 : SIZE(tempGasPocketFlowEl , dim = 2)) = tempGasPocketFlowEl + GasPocketFlowEl(: , SIZE(GasPocketFlowEl , dim = 2)) = 0 + DEALLOCATE(tempGasPocketFlowEl) + END IF + + GasPocketFlowEl(i , j) = k + j = j + 1 + END IF + END DO + !WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl + + DO k = AnnulusFirstEl , OpenholeFirstEl - 1 + IF (FlowEl(k)%MaterialType == 1) THEN + IF (j > 1) THEN + IF (k == AnnulusFirstEl .AND. GasPocketFlowEl(i , j - 1) == NumbEl) THEN + !WRITE (*,*) 'Kick is Around Bit' + ELSE IF (GasPocketFlowEl(i , j - 1) /= k - 1) THEN + i = i + 1 + j = 1 + !WRITE (*,*) 'i, j, k', i, j, k, FlowEl(k)%MaterialType + END IF + END IF + + IF (j > SIZE(GasPocketFlowEl , dim = 2)) THEN + ALLOCATE(tempGasPocketFlowEl(SIZE(GasPocketFlowEl , dim = 1) , SIZE(GasPocketFlowEl , dim = 2))) + tempGasPocketFlowEl = GasPocketFlowEl + DEALLOCATE(GasPocketFlowEl) + ALLOCATE(GasPocketFlowEl(SIZE(tempGasPocketFlowEl , dim = 1) , SIZE(tempGasPocketFlowEl , dim = 2) + 1)) + GasPocketFlowEl(: , 1 : SIZE(tempGasPocketFlowEl , dim = 2)) = tempGasPocketFlowEl + GasPocketFlowEl(: , SIZE(GasPocketFlowEl , dim = 2)) = 0 + DEALLOCATE(tempGasPocketFlowEl) + END IF + IF (i > NoGasPocket) THEN + WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl + WRITE (*,*) 'i , j , k', i, j, k + WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , StringFirstEl , AnnulusFirstEl , NoWellToChokeEl , OpenHoleFirstEl + + WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type' + DO j = 1 , NumbEl + WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType + END DO + !WRITE (*,*) 'Op Last: Volume(gal), Type', NumbEl, FlowEl(NumbEl)%Volume * ConvFt3ToUSgal , FlowEl(NumbEl)%MaterialType + !WRITE (*,*) 'Ann First: Volume(gal), Type', AnnulusFirstEl, FlowEl(AnnulusFirstEl)%Volume * ConvFt3ToUSgal , FlowEl(AnnulusFirstEl)%MaterialType + !IF (ChokeKroneckerDelta == 1) THEN + ! WRITE (*,*) 'Ann Last: Volume(gal), Type', AnnulusLastEl, FlowEl(AnnulusLastEl)%Volume * ConvFt3ToUSgal , FlowEl(AnnulusLastEl)%MaterialType + ! WRITE (*,*) 'Ch First: Volume(gal), Type', AnnulusLastEl + 1 , FlowEl(AnnulusLastEl + 1)%Volume * ConvFt3ToUSgal , FlowEl(AnnulusLastEl + 1)%MaterialType + !END IF + + CALL ErrorStop('Error in calculating GasPocketFlowEl') + END IF + + GasPocketFlowEl(i , j) = k + !WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl + j = j + 1 + + END IF + !IF (i > NoGasPocket) CALL ErrorStop('Error in GasPocketFlowEl' , i) + END DO + + !i = SIZE(GasPocketFlowEl , dim = 1) + !j = SIZE(GasPocketFlowEl , dim = 2) + !WRITE(*,*) 'GasPocketFlowEl Data' , GasPocketFlowEl + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + GasPocketModifiedVol%Array(:) = 0.d0 + + DO i = 1 , NoGasPocket + !WRITE(*,*) 'GasPocketFlowEl Data' , i , GasPocketFlowEl(: , i) + DO j = 1 , SIZE(GasPocketFlowEl , dim = 2) + IF (GasPocketFlowEl(i , j) > 0) GasPocketModifiedVol%Array(i) = GasPocketModifiedVol%Array(i) + FlowEl(GasPocketFlowEl(i , j))%Volume + END DO + END DO + i = AnnulusLastEl + j = OpenholeFirstEl - 1 + !WRITE (*,*) ' b) GasPocketModifiedVol (ft3)=', GasPocketModifiedVol(1) + !WRITE (*,*) ' b) GasPocketModifiedVol (gal)=' , GasPocketModifiedVol(1) * 7.48 + !IF (NoWelltoChokeEl > 0 .AND. ANY(FlowEl(i : j)%MaterialType == 1) .AND. FlowEl(j)%MaterialType == 0) THEN + ! BehindKickMudDensity = FlowEl(GasPocketFlowEl(NoGasPocket , 1) - 1)%Density + ! FrontKickMudDensity = FlowEl(MAXVAL(GasPocketFlowEl(NoGasPocket , :)) + 1)%Density + ! KickVolBeforeChoke = REAL(GasPocketModifiedVol%Array(NoGasPocket)) + ! WRITE (*,*) 'BehindKickMudDensity', BehindKickMudDensity + ! WRITE (*,*) 'FrontKickMudDensity' , FrontKickMudDensity + ! WRITE (*,*) 'KickVolBeforeChoke', KickVolBeforeChoke + !END IF + + + GasPocketOldVol%Array(:) = GasPocketModifiedVol%Array(:) + + GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) + !WRITE (*,*) ' GasPocketweight%Array(1)', GasPocketweight%Array(1) + IF (GasPocketWeight%Array(1) < 0.0) CALL ErrorStop(' Error in Calculating Mass ' , KickmdotBCoef) + + + GasPocketDensity%Array(:) = (GasPocketweight%Array(:) / GasPocketModifiedVol%Array(:)) / convft3toUSgal ! [lbm/ft^3 to ppg] + DO i = 1 , SIZE(GasPocketFlowEl , dim = 1) + DO j = 1 , SIZE(GasPocketFlowEl , dim = 2) + IF (GasPocketFlowEl(i , j) > 0) FlowEl(GasPocketFlowEl(i , j))%Density = GasPocketDensity%Array(i) + END DO + END DO + + + !WRITE (*,*) 'Kick density (ppg)=' , GasPocketDensity(1) + DownHole%InfluxRate = MAX(((KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1))) / GasPocketDensity%Array(1) * ConvMinToSec) , 0.0) + !WRITE (*,*) ' InfluxRate (gpm) =', InfluxRate + + 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 (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) + 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 * & + GasPocketCompressibility%Array(NoGasPocket) * GasPocketNewTemp%Array(NoGasPocket) / GasPocketModifiedVol%Array(NoGasPocket) + GasPocketDensity%Array(NoGasPocket) = (GasPocketweight%Array(NoGasPocket) / GasPocketModifiedVol%Array(NoGasPocket)) / convft3toUSgal + GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:) + !FlowEl(i)%Density = GasPocketDensity%Array(NoGasPocket) ! for choke pressure drop calculation + !WRITE (*,*) 'kick weight, pressure & density', GasPocketWeight%Array(NoGasPocket), GasPocketOldPress%Array(NoGasPocket), FlowEl(i)%Density + ELSE ! gas pocket is escaped from the well completely + WRITE (*,*) ' Last Pocket Removed' + WRITE (*,*) ' GasPocketFlowEl', GasPocketFlowEl + CALL RemoveGasPocket(NoGasPocket) + + !WRITE (*,*) ' GasPocketFlowEl', GasPocketFlowEl + + END IF + + ELSE IF (NoGasPocket == 1 .OR. WellHeadOpen) THEN ! kick is not last element of choke line or well head is closed + !WRITE (*,*) ' Gas Kick Pressure (psi) (before) = ' , GasPocketNewPress(1) + !DO j = 1 , NoGasPocket + GasPocketNewPress%Array(:) = GasPocketNewPress%Array(:) * REAL(GasPocketNewVol%Array(:) / GasPocketOldVol%Array(:)) + GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) + GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:) + !WRITE (*,*) ' Gas Kick Pressure (psi) (after) = ' , GasPocketOldPress(1), REAL(GasPocketNewVol(1) / GasPocketOldVol(1)) + !END DO + + ELSE ! Many gas pocket is in the well and well head is closed + +103 FORMAT (2I, 4X, (F9.3), 5X, (F9.3)) + + !WRITE (*,*) 'Before 0' + !DO i = 1 , NoGasPocket + ! WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL(GasPocketNewVol%Array(i) * Convft3toUSgal), REAL(GasPocketOldVol%Array(i) * Convft3toUSgal) + !END DO + GasPocketNewPress%Array(NoGasPocket) = GasPocketOldPress%Array(NoGasPocket) + GasPocketNewVol%Array(NoGasPocket) = GasPocketCompressibility%Array(NoGasPocket) * GasType(KickGasType)%GasConstant * & + GasPocketNewTemp%Array(NoGasPocket) * GasPocketWeight%Array(NoGasPocket) / GasPocketNewPress%Array(NoGasPocket) + + + !GasPocketNewPress%Array(:) = GasPocketNewPress%Array(:) * REAL(GasPocketNewVol%Array(:) / GasPocketOldVol%Array(:)) + !GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) + + !WRITE (*,*) 'Before 1' + !DO i = 1 , NoGasPocket + ! WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL((GasPocketNewVol%Array(i) * Convft3toUSgal)) + !END DO + + !WRITE (*,*) 'Mid' + DO WHILE (ABS(PressureCorrection * 10.0) > KickConvergenceTolerance) + DO j = NoGasPocket - 1 , 1 , -1 + CALL KickFunctionsCalculator(GasPocketNewPress%Array(j) , j , 5) + GasPocketNewVol%Array(j) = GasPocketCompressibility%Array(j) * GasType(KickGasType)%GasConstant * & + GasPocketNewTemp%Array(j) * GasPocketWeight%Array(j) / GasPocketNewPress%Array(j) + !WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal) + END DO + PressureCorrection = (SUM(GasPocketNewVol%Array(:)) - SUM(GasPocketOldVol%Array(:))) / SUM(GasPocketNewVol%Array(:) / GasPocketNewPress%Array(:)) + GasPocketNewPress%Array(NoGasPocket) = GasPocketNewPress%Array(NoGasPocket) + PressureCorrection + GasPocketNewVol%Array(NoGasPocket) = GasPocketCompressibility%Array(NoGasPocket) * GasType(KickGasType)%GasConstant * & + GasPocketNewTemp%Array(NoGasPocket) * GasPocketWeight%Array(NoGasPocket) / GasPocketNewPress%Array(NoGasPocket) + j = NoGasPocket + !WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal) + END DO + + !WRITE (*,*) 'Pressure Correction = ', PressureCorrection + WRITE (*,*) 'After' + DO i = 1 , NoGasPocket + WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL((GasPocketNewVol%Array(i) * Convft3toUSgal)) + END DO + + GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) + + END IF + + + IF (GasPocketFlowEl(NoGasPocket , 1) == 0) THEN + CALL RemoveGasPocket(1) + + !WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl + WRITE (*,*) 'First Pocket Removed' + !WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl + END IF + + + + DownHole%KickVolume = INT(SUM(GasPocketOldVol%Array(:)) * convft3toUSgal / 42. * 10.0) / 10.0 + + + !WRITE (*,*) ' Gas Kick Pressure (psi) = ' , GasPocketOldPress(1) , INT((GasPocketNewVol(1) / GasPocketOldVol(1)) * 1000.d0) / 1000.d0 + !WRITE (*,*) ' b) GasPocketNewVol (ft^3) = ' , GasPocketOldVol(1) + + + + END SUBROUTINE + + +SUBROUTINE RemoveGasPocket(ilocal) + + use KickVARIABLESModule + USE MudSystemVARIABLES + + IMPLICIT NONE + + INTEGER :: ilocal + + DEALLOCATE(KickJacobian , OldKickJacobian , KickVandPFunction , KickUnknownVector , KickCorrectionVector) + + + WRITE (*,*) 'Gas Pocket Will be Removed', ilocal + call GasPocketOldPress%Remove(ilocal) + call GasPocketNewPress%Remove(ilocal) + call GasPocketOldTemp%Remove(ilocal) + call GasPocketNewTemp%Remove(ilocal) + call GasPocketOldVol%Remove(ilocal) + call GasPocketNewVol%Remove(ilocal) + call GasPocketDeltaVol%Remove(ilocal) + call GasPocketFlowInduced%Remove(ilocal) + call GasPocketModifiedVol%Remove(ilocal) + call GasPocketWeight%Remove(ilocal) + call GasPocketDensity%Remove(ilocal) + call GasPocketCompressibility%Remove(ilocal) + + NoGasPocket = NoGasPocket - 1 + + IF (NoGasPocket > 0) THEN + ALLOCATE(KickJacobian(2 * NoGasPocket , 2 * NoGasPocket) , OldKickJacobian(2 * NoGasPocket , 2 * NoGasPocket) , KickVandPFunction(2 * NoGasPocket)) + ALLOCATE(KickUnknownVector(2 * NoGasPocket) , KickCorrectionVector(2 * NoGasPocket)) + + IF (ALLOCATED(GasPocketFlowEl)) THEN + ALLOCATE(tempGasPocketFlowEl(NoGasPocket , SIZE(GasPocketFlowEl , dim = 2))) + tempGasPocketFlowEl = GasPocketFlowEl(1 : NoGasPocket , :) + DEALLOCATE(GasPocketFlowEl) + ALLOCATE(GasPocketFlowEl(SIZE(tempGasPocketFlowEl , dim = 1) , SIZE(tempGasPocketFlowEl , dim = 2))) + GasPocketFlowEl = tempGasPocketFlowEl + DEALLOCATE(tempGasPocketFlowEl) + END IF + + ELSE ! NoGasPocket = 0 + + + CALL GasPocketOldPress%Empty + CALL GasPocketNewPress%Empty + CALL GasPocketOldTemp%Empty + CALL GasPocketNewTemp%Empty + CALL GasPocketOldVol%Empty + CALL GasPocketNewVol%Empty + CALL GasPocketDeltaVol%Empty + CALL GasPocketFlowInduced%Empty + CALL GasPocketModifiedVol%Empty + CALL GasPocketWeight%Empty + CALL GasPocketDensity%Empty + + DownHole%InfluxRate = 0.0 + DownHole%KickVolume = 0.0 + + END IF + + !WRITE (*,*) 'Gas Pocket Removed', NoGasPocket + 1, ALLOCATED(GasPocketWeight%Array) + +END SUBROUTINE + + + + + + + \ No newline at end of file diff --git a/FluidFlow/fricpressdropvars.mod b/FluidFlow-old/fricpressdropvars.mod similarity index 100% rename from FluidFlow/fricpressdropvars.mod rename to FluidFlow-old/fricpressdropvars.mod diff --git a/FluidFlow-old/kick/Formation_Information.f90 b/FluidFlow-old/kick/Formation_Information.f90 new file mode 100644 index 0000000..d6df9d7 --- /dev/null +++ b/FluidFlow-old/kick/Formation_Information.f90 @@ -0,0 +1,125 @@ +SUBROUTINE FormationInformationCalculator + + use KickVARIABLESModule + Use TD_WellGeometry + Use CReservoirVariables + Use CFormationVariables + Use ConfigurationVariables + USE Fluid_Flow_Startup_Vars + USE CLog2 + USE CDownHoleVariables + USE MudSystemVARIABLES + + + IMPLICIT NONE + + INTEGER :: i + REAL(8) :: WellGeoTopTVD + + KickGasType = 1 ! methane + +!==================================================== +! Formation Length Calculation +!==================================================== + + WellGeoTopTVD = 0. + KickFormTopMD = 0. + KickFormDownMD = 0. + !===> Top Measured Depth of Formation + Do i = 1 , TD_WellGeneral%WellIntervalsCount + if ( Reservoir%FormationTop >= TD_WellGeo(i)%VerticalDepth ) then + KickFormTopMD = KickFormTopMD + TD_WellGeo(i)%IntervalLength + !WRITE (*,*) ' here 11' , TD_WellGeo(i)%IntervalLength + !WRITE (*,*) ' here v11' , TD_WellGeo(i)%VerticalDepth + + WellGeoTopTVD = TD_WellGeo(i)%VerticalDepth + else if ( Reservoir%FormationTop < TD_WellGeo(i)%VerticalDepth ) then + if ( TD_WellGeo(i)%HoleType == 0 ) then + KickFormTopMD = KickFormTopMD + ((Reservoir%FormationTop - WellGeoTopTVD)& + / cos(TD_WellGeo(i)%StartAngle)) + !WRITE (*,*) ' here 12' , (FormationTop - WellGeoTopTVD) / cos(TD_WellGeo(i)%StartAngle) + + else + KickFormTopMD = KickFormTopMD + (TD_WellGeo(i)%RCurvature & + * Asin((Reservoir%FormationTop - WellGeoTopTVD) / TD_WellGeo(i)%RCurvature)) + !WRITE (*,*) ' here 13' , TD_WellGeo(i)%RCurvature * Asin((FormationTop - WellGeoTopTVD) / TD_WellGeo(i)%RCurvature) + + end if + exit + end if + End Do + + !!===> Down Measured Depth of Formation + WellGeoTopTVD = 0. + Do i = 1 , TD_WellGeneral%WellIntervalsCount + if ( (Reservoir%FormationTop + Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness)>=TD_WellGeo(i)%VerticalDepth ) then + KickFormDownMD = KickFormDownMD + TD_WellGeo(i)%IntervalLength + WellGeoTopTVD = TD_WellGeo(i)%VerticalDepth + else if ( (Reservoir%FormationTop+Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness) Determination of Formation Length for Kick Modeling + if (TD_WellGeneral%WellTotalVerticalLength >= Reservoir%FormationTop .AND. TD_WellGeneral%WellTotalVerticalLength < (Reservoir%FormationTop+Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness)) then + KickFormLength = TD_WellGeneral%WellTotalLength - KickFormTopMD ![ft] + else if ( TD_WellGeneral%WellTotalVerticalLength >= (Reservoir%FormationTop + Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness) ) then + KickFormLength = KickFormDownMD - KickFormTopMD ![ft] + else + KickFormLength = 0. + end if + + !PermeabilityExposedHeight = KickFormLength * FormationPermeability + DownHole%PermeabilityExposedHeight = MudSystem%FluidFlowCounter - MudSystem%MudSys_timeCounter +!==================================================== +! Reservoir Data +!==================================================== + FormPermeability = Reservoir%FormationPermeability ! [mD] + + FormPressure = TD_WellGeneral%WellTotalVerticalLength * Configuration%Formation%Formations(Reservoir%FormationNo)%PorePressureGradient ![psia] + DownHole%FormationPressure = INT(FormPressure) + !CALL Log_2('FormPressure =' , FormPressure) + !print*, 'Formations(FormationNo)%PorePressureGradient=', Formations(FormationNo)%PorePressureGradient + !print * , 'FormationNo=' , FormationNo + !print * , 'TD_WellGeneral%WellTotalVerticalLength=' , TD_WellGeneral%WellTotalVerticalLength + FormTemperature = 600 ! [Ra] + !WRITE (*,*) ' Formation pressure ' , FormPressure + + +!==================================================== +! Gas Properties (Methane Gas) +!==================================================== + + GasResTemperature = FormTemperature + GasResPressure = FormPressure + + !!!! Methane , Gas type =1 + GasKickMolarMass = GasType(KickGasType)%MolarWt ! Methane Gas [gr/mol] + GasSpecGravity = GasKickMolarMass / GasDensityRefrence + + KickTc = GasType(KickGasType)%CritTemp + KickPc = GasType(KickGasType)%CritPress + + !!!!!!!! Calculating Compressibility, viscosity for influx condition (Average of reservoir and bottomhole) + KickTr = GasResTemperature / KickTc + KickPr = GasResPressure / KickPc + + K_A_Res = 3.53 * KickPr + K_B_Res = 10.0**(0.9813 * KickTr) + K_C_Res = 0.274 * (KickPr**2) + K_D_Res = 10.0**(0.8157 * KickTr) + + GasResCompressibility = 0.98 !1. - (K_A_Res / K_B_Res) + (K_C_Res / K_D_Res) + + GasReservoirDensity = GasResPressure / (GasResCompressibility * & + GasResTemperature * GasType(KickGasType)%GasConstant) / Convft3toUSgal ! [ppg] + +END SUBROUTINE + \ No newline at end of file diff --git a/FluidFlow-old/kick/Gas_Kick_Calculator.f90 b/FluidFlow-old/kick/Gas_Kick_Calculator.f90 new file mode 100644 index 0000000..7c9b035 --- /dev/null +++ b/FluidFlow-old/kick/Gas_Kick_Calculator.f90 @@ -0,0 +1,566 @@ +SUBROUTINE GasKickCalculator + + use KickVARIABLESModule + Use TD_WellGeometry + Use CReservoirVariables + Use CFormationVariables + USE Fluid_Flow_Startup_Vars + use PressureDisplayVARIABLESModule + USE FricPressDropVarsModule + USE MudSystemVARIABLES + USE CMudPropertiesVariables + USE CError + USE , INTRINSIC :: IEEE_ARITHMETIC + + + !! Note: a subject that may be confusing is that when we use gauge pressure and when're using absolute pressure?! + !! all stated pressure are gauge pressure, so I do like this. + !! only when we want to use a state equation (like ideal gas equation), we should use absolute equation and so I do this. + !! Thus gas pocket pressure are all absolute pressure. + + IMPLICIT NONE + + INTEGER :: i , j , k , l + + SolvingEquationError = .FALSE. + KickVandPFunction(:) = 0.d0 + KickJacobian(: , :) = 0.d0 + +!==================================================== +! Gas Properties (Methane Gas) +!==================================================== + !GasPocketNewTemp%Array(1) = 600 + BottomHoleTemperature = 600 + KickFluxAvgPressure = (BottomHolePress + FormPressure) / 2 + StandardPress + KickFluxAvgTemperature = (FormTemperature + BottomHoleTemperature) / 2 + KickFluxAvgCompressibility = 0.98d0 + + K_Aa = (5.8742362 * 10.**(-3) * KickFluxAvgTemperature**1.2288) / (511.1728532 + KickFluxAvgTemperature) + K_Bb = 5.5565586 + (1000.01 / KickFluxAvgTemperature) + K_Cc = 2.47862 - 0.12294 * K_Bb + GasKickSIDensity = KickFluxAvgPressure / (KickFluxAvgCompressibility * & + KickFluxAvgTemperature * GasType(KickGasType)%GasConstant) * Convpcftogpcm3 + + GasKickViscosity = K_Aa * EXP(K_Bb * GasKickSIDensity**K_Cc) + !!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!! Calculating compressibility for bottom hole condition + !K_BHTpr = BottomHoleTemperature / KickTc + !K_BHPpr = (BottomHolePress + StandardPress) / KickPc + + !K_A_Bottomhole = 3.53 * K_BHPpr + !K_B_Bottomhole = 10.0**(0.9813 * K_BHTpr) + !K_C_Bottomhole = 0.274 * (K_BHPpr**2) + !K_D_Bottomhole = 10.0**(0.8157 * K_BHTpr) + + BottomHoleCompressibility = 0.98d0 !1. - (K_A_Bottomhole / K_B_Bottomhole) + (K_C_Bottomhole / K_D_Bottomhole) + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + GasKickBg = 0.00504 * KickFluxAvgCompressibility * KickFluxAvgTemperature / KickFluxAvgPressure ![bbl/SCF] + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !WRITE (*,*) 'Gas Kick Top' +!===> Kick Flow Rate Calculation + IF (FormPressure > BottomHolePress) THEN + KickmdotACoef = 10.0**(-8) * 1.15741d0 * 7.080 * FormPermeability * REAL(KickFormLength) * GasType(KickGasType)%StDensity / & + (GasKickViscosity * GasKickBg * LOG(10000.0)) + !IF (WellHeadOpen .AND. NoGasPocket == 1) KickmdotACoef = (1.d0 + 2.d0) * KickmdotACoef + ELSE + KickmdotACoef = 0.0 + END IF + + i = StringLastEl + j = OpenholeFirstEl - 1 + k = GasPocketFlowEl(1 , 1) + KickmdotBCoef = FormPressure + StandardPress !! - Sum(static and friction pressure loss) of flow elements below gas pocket, see below + IF (FormPressure > BottomHolePress) THEN + + !WRITE (*,*) 'k , i, j' , k , i, j + IF (k >= OpenholeFirstEl) THEN ! Bottom of active kick is in openhole + KickmdotBCoef = KickmdotBCoef - (SUM(FlowEl(OpenholeFirstEl : k)%StaticPressDiff)) !+ SUM(FlowEl(j + 1 : GasPocketFlowEl(1 , 1) - 1)%FricPressLoss + !WRITE (*,*) '1 SUM(FlowEl(j + 1 : k)%FricPressLoss', k, SUM(FlowEl(j + 1 : k)%FricPressLoss) + ELSE IF (k < OpenholeFirstEl) THEN ! bottom of 1st gas pocket (active kick) is in annulus ond/or choke line only + KickmdotBCoef = KickmdotBCoef - SUM(FlowEl(OpenholeFirstEl : NumbEl)%StaticPressDiff) & + - (SUM(FlowEl(AnnulusFirstEl : k)%StaticPressDiff) + SUM(FlowEl(AnnulusFirstEl : k)%FricPressLoss)) + !WRITE (*,*) '2 SUM(FlowEl(j + 1 : NumbEl)%FricPressLoss', k, SUM(FlowEl(j + 1 : NumbEl)%FricPressLoss) + END IF + !WRITE (*,*) ' KickmdotBCoef=', KickmdotBCoef + END IF + !WRITE (*,*) 'Kick A, B', KickmdotACoef, KickmdotBCoef + + DO l = 1 , NoGasPocket + KickUnknownVector(2 * l - 1) = GasPocketNewVol%Array(l) + KickUnknownVector(2 * l) = GasPocketNewPress%Array(l) + END DO + + IF (WellHeadOpen) THEN + !!!!!!!!!! Calculation of functions of pocket Pressure and gas Volumes + !IF (GasPocketElementNo(1) > 0) WRITE (*,*) ' GasPocketElementNo(1) ' , GasPocketElementNo(1) + !WRITE (*,*) ' Kick Unknown Vector' , KickUnknownVector!(1) , KickUnknownVector(2) + IF (KickIteration == 1) THEN ! updating initial guess based on previous time step data + DO l = 1 , NoGasPocket + KickUnknownVector(2 * l - 1) = KickUnknownVector(2 * l - 1) + GasPocketDeltaVol%Array(l) + END DO + END IF + + KickVandPFunction(1) = KickUnknownVector(1) - GasPocketCompressibility%Array(1) * GasType(KickGasType)%GasConstant * & ! VandP(1) = V(1) + GasPocketNewTemp%Array(1) * (GasPocketWeight%Array(1) + KickmdotACoef * MAX(((KickmdotBCoef - KickUnknownVector(2)) * dt) , 0.0)) / KickUnknownVector(2) + !WRITE (*,*) 'KickVandPFunction(1)',KickVandPFunction(1) + l = 2 * NoGasPocket + CALL KickFunctionsCalculator(KickVandPFunction(l) , NoGasPocket , 2) ! VandP(last) = P(last) + !WRITE (*,*) 'KickVandPFunction(l)', l, KickVandPFunction(l) + DO l = 2 , NoGasPocket ! VandP(Odd) = V(l, l > 1) + KickVandPFunction(2 * l - 1) = KickUnknownVector(2 * l - 1) - GasPocketCompressibility%Array(l) * GasType(KickGasType)%GasConstant * & + GasPocketNewTemp%Array(l) * GasPocketWeight%Array(l) / KickUnknownVector(2 * l) + !WRITE(*,*) 'KickVandPFunction(V)', l, KickVandPFunction(2 * l - 1) + END DO + + DO l = NoGasPocket - 1 , 1 , -1 + CALL KickFunctionsCalculator(KickVandPFunction(2 * l) , l , 1) ! VandP(Even) = P(l, l < NoGasPocket) + !WRITE(*,*) 'KickVandPFunction(P)', l , KickVandPFunction(2 * l) + END DO + !!!!!!!!!! END - Calculation of functions of pocket Pressure and gas Volumes + + !!!!!!!!!! Calculation of Jacobian + DO k = 1 , 2 * NoGasPocket ! Main Diagonal + KickJacobian(k , k) = 1.d0 + END DO + + KickJacobian(1,2) = (GasPocketCompressibility%Array(1) * GasType(KickGasType)%GasConstant * GasPocketNewTemp%Array(1) & + * (GasPocketWeight%Array(1) + KickmdotACoef * KickmdotBCoef * dt) / KickUnknownVector(2)**2) ! Row 1 Finished + IF (KickJacobian(1,2) == 0.d0) THEN + CALL Error('KickJacobian(1,2) = 0.0') + KickJacobian(1,2) = OldKickJacobian(1,2) + END IF + + !WRITE(*,*) 'KickJacobian(1,2)', KickJacobian(1,2) + + l = NoGasPocket + CALL KickFunctionsCalculator(KickJacobian(2 * l , 2 * l - 1) , NoGasPocket , 4) ! for last Row + IF (KickJacobian(2 * l , 2 * l - 1) == 0.d0) THEN + CALL Error ('KickJacobian(Last,Odd) = 0.0') + KickJacobian(2 * l , 2 * l - 1) = OldKickJacobian(2 * l , 2 * l - 1) + END IF + + DO k = NoGasPocket - 1 , 1 , -1 + KickJacobian(2 * l , 2 * k - 1) = KickJacobian(2 * l , 2 * l - 1) + END DO ! Last Row Finished + !WRITE(*,*) 'KickJacobian(2,1)', KickJacobian(2,1) + + + DO k = 2 , NoGasPocket + KickJacobian(2 * k - 1 , 2 * k) = GasPocketCompressibility%Array(k) * GasType(KickGasType)%GasConstant * GasPocketNewTemp%Array(k) & + * GasPocketWeight%Array(k) / KickUnknownVector(2 * k)**2 + + END DO ! Odd Rows (V equations) Finished + + DO k = 1 , NoGasPocket - 1 + KickJacobian(2 * k , 2 * k + 2) = -1.d0 + END DO ! Even Rows (P equations) effect of upper pocket + + DO k = 2 , 2 * (NoGasPocket - 1) , 2 + DO l = 1 , k - 1 , 2 + CALL KickFunctionsCalculator(KickJacobian(k , l) , k / 2 , 3) + IF (KickJacobian(k , l) == 0.d0) THEN + WRITE (*,*) 'Jacobian Array = 0.0', k , l + CALL Error ('KickJacobian(k , l) = 0.0') + KickJacobian(k , l) = OldKickJacobian(k , l) + END IF + END DO + END DO + + IF (ANY(IEEE_IS_NaN(KickJacobian))) CALL ErrorStop ('NaN in calculating Kick Jacobian, Call your Service Provider') + + !!!!!!!!!! Solving linear equation in order to finding correction vector for correcting pocket pressure and gas induced flowrates + KickVandPFunction = -1.d0 * KickVandPFunction + !WRITE (*,*) 'Max Remainder', MAXVAL(ABS(KickVandPFunction)) , MAXLOC(ABS(KickVandPFunction)) + !WRITE (*,*) 'SIZE(A , dim = 1), SIZE(A , dim = 2), SIZE(b)', SIZE(KickJacobian , dim = 1), SIZE(KickJacobian , dim = 2), SIZE(KickVandPFunction) + CALL SOLVE_LINEAR_EQUATIONS(KickJacobian , KickCorrectionVector , KickVandPFunction , SolvingEquationError, SIZE(KickCorrectionVector)) + IF (SolvingEquationError) CALL ErrorStop( ' Error in solving kick equation ' ) + + KickUnknownVector = KickUnknownVector + KickCorrectionUnderRelaxation * KickCorrectionVector + + DO l = 1 , NoGasPocket + GasPocketNewVol%Array(l) = KickUnknownVector(2 * l - 1) + IF (IEEE_IS_NaN(GasPocketNewVol%Array(l))) CALL ErrorStop('Volume of this pocket is Not a Number:', l) + IF (GasPocketNewVol%Array(l) <= 0.d0) CALL Error('Volume of this pocket is Negative or Zero:', l) + GasPocketNewPress%Array(l) = KickUnknownVector(2 * l) + IF (IEEE_IS_NaN(GasPocketNewPress%Array(l))) CALL ErrorStop('Pressure of this Pocket is Not a Number:', l) + IF (GasPocketNewPress%Array(l) <= 0.d0) CALL ErrorStop('Pressure of this Pocket is Negative or Zero:', l) + END DO + + + !WRITE(*,*) 'GasPocketDeltaVol (gal)' , GasPocketDeltaVol(1) * 7.48 + !WRITE (*,*) 'GasPocketFlowInduced (gpm), GasPocketNewVol' , GasPocketFlowInduced(1), GasPocketNewVol(1) + !IF (Kchoke > 0.0) + !WRITE(*,*) ' New Vol (ft3), New Press (psi)', GasPocketNewVol(1), GasPocketNewPress(1) + + ELSE ! well haed is closed, so build up process or migration occurs + + !WRITE (*,*) 'GasPocketOldPress (before)' , GasPocketOldPress(1) + GasPocketNewPress%Array(1) = GasPocketOldPress%Array(1) * & + (REAL((GasPocketWeight%Array(1) + KickmdotACoef * KickmdotBCoef * dt) / (GasPocketWeight%Array(1) + KickmdotACoef * GasPocketOldPress%Array(1) * dt))) + !WRITE (*,*) 'GasPocketNewPress (after)' , GasPocketNewPress(1), ((GasPocketWeight(1) + KickmdotACoef * KickmdotBCoef * dt) / (GasPocketWeight(1) + KickmdotACoef * GasPocketOldPress(1) * dt)) + + + !WRITE (*,*) ' Well head is closed, GasPocketNewPress =' , GasPocketNewPress(1) + !WRITE (*,*) 'Old Press, Weight, A, B' , GasPocketOldPress(1), GasPocketWeight(1), KickmdotACoef, KickmdotBCoef + !WRITE (*,*) 'Numerator and denumerator Gas kick' , KickmdotACoef * KickmdotBCoef * dt , KickmdotACoef * GasPocketOldPress(1) * dt + + !WRITE (*,*) ' Gas Kick Volume (ft^3) = ' , GasPocketNewVol(1) + + END IF + + !DO l = 1 , NoGasPocket + GasPocketDeltaVol%Array(:) = GasPocketNewVol%Array(:) - GasPocketOldVol%Array(:) + GasPocketFlowInduced%Array(:) = (GasPocketDeltaVol%Array(:)) / dt * 448.8 ! gpm + !END DO + + GasKickPumpFlowRate = 0.0 + IF (NOT(KickOffBottom) .AND. WellHeadOpen) GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) + + !WRITE (*,*) ' No Iteration, KickCorrectionVector =' , KickIteration , KickCorrectionVector(1) , KickCorrectionVector(2) + !WRITE (*,*) ' Kick Jacobian ', REAL(KickJacobian) + !WRITE (*,*) ' KickVandPFunction = ' , REAL(KickVandPFunction) + !WRITE (*,*) ' Kick Unknown Vector = ' , REAL(-KickUnknownVector) + + + + !WRITE (*,*) 'Gas Kick Bottom' + + + END SUBROUTINE + + + SUBROUTINE KickFunctionsCalculator(ExitValue , GasPocketNo , CalcMode) + + + use KickVARIABLESModule + USE FricPressDropVarsModule + USE Fluid_Flow_Startup_Vars + USE CError + USE , INTRINSIC :: IEEE_Arithmetic + + + IMPLICIT NONE + + REAL(8) :: ExitValue + INTEGER :: GasPocketNo , CalcMode + INTEGER :: x + INTEGER :: y + INTEGER :: z , i , j + + x = GasPocketFlowEl(GasPocketNo , 1) + IF (GasPocketNo < NoGasPocket) y = GasPocketFlowEl(GasPocketNo + 1 , 1) + i = StringLastEl + j = OpenholeFirstEl - 1 + + ! Case 1: gas pocket is completely in OP and STARTX of upper gas pocket is also + ! Case 2: gas pocket is completely in OP and STARTX of upper gas pocket is above Bit + ! Case 3: gas pocket is AROUNDBIT and so upper gas pocket is in ANN (or Choke line) + ! Case 4: gas pocket is completely in ANN and upper gas pocket is also + + ! CalcMode 1: KickVandPFunction between 2 pocket + ! CalcMode 2: KickVandPFunction for top gas pocket + ! CalcMode 3: KickJacobian between 2 Pocket + ! CalcMode 4: KickJacobian for top (last) gas pocket + ! CalcMode 5: Calculating pressure of bottom pocket based on upper pocket + + + IF (CalcMode == 1) THEN ! calculating pressure difference between two pocket, include static pressure difference and frictional + ! pressure difference, use in calculating 'KickVandPFunction' + ExitValue = KickUnknownVector(2 * GasPocketNo) - KickUnknownVector(2 * GasPocketNo + 2) + IF (x >= OpenholeFirstEl .AND. y < OpenholeFirstEl) THEN ! Case 2 , Case 3 + ExitValue = ExitValue - SUM(FlowEl(x : NumbEl)%StaticPressDiff) - SUM(FlowEl(x : NumbEl)%FricPressLoss) & + - SUM(FlowEl(AnnulusFirstEl : y)%StaticPressDiff) - SUM(FlowEl(AnnulusFirstEl : y)%FricPressLoss) + ELSE ! Case 1 , Case 4 + ExitValue = ExitValue - SUM(FlowEl(x : y)%StaticPressDiff) - SUM(FlowEl(x : y)%FricPressLoss) + END IF + + + ELSE IF (CalcMode == 2) THEN + ExitValue = KickUnknownVector(2 * GasPocketNo) - StandardPress - Kchoke * FlowEl(OpenholeFirstEl - 1)%Flowrate**2 + IF (x >= OpenholeFirstEl) THEN ! Gas Pocket is in Openhole + ExitValue = ExitValue - SUM(FlowEl(x : NumbEl)%StaticPressDiff) - SUM(FlowEl(x : NumbEl)%FricPressLoss) & + - SUM(FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%StaticPressDiff) - SUM(FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FricPressLoss) + ELSE ! Gas Pocket is in Annulus + ExitValue = ExitValue - SUM(FlowEl(x : OpenholeFirstEl - 1)%StaticPressDiff) - SUM(FlowEl(x : OpenholeFirstEl - 1)%FricPressLoss) + END IF + + + ELSE IF (CalcMode == 3) THEN ! calculating derivative of pressure difference between two pocket, relative to change in flowrate + ! use in calculating 'KickJacobian' + IF (x >= OpenholeFirstEl .AND. y < OpenholeFirstEl) THEN ! Top kick STARTX is in Annulus + DO z = x , NumbEl ! open hole elements + CALL PartialDerivativeFricToFlowRate(z) + IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN + WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe + WRITE (*,*) ' Op start, end, density, Q, mu' , FlowEl(z)%StartX, FlowEl(z)%EndX, FlowEl(z)%Density, FlowEl(z)%FlowRate, FlowEl(z)%mueff + CALL ErrorStop('NaN in calculating partial derivative') + END IF + END DO + DO z = AnnulusFirstEl , y ! Annulus elements + CALL PartialDerivativeFricToFlowRate(z) + IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN + WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe + WRITE (*,*) ' Op start, end, density, Q, mu' , FlowEl(z)%StartX, FlowEl(z)%EndX, FlowEl(z)%Density, FlowEl(z)%FlowRate, FlowEl(z)%mueff + CALL ErrorStop('NaN in calculating partial derivative') + END IF + END DO + ExitValue = ExitValue - (SUM(FlowEl(x : NumbEl)%FricToQPartialDiff) + SUM(FlowEl(AnnulusFirstEl : y)%FricToQPartialDiff)) * 448.8 / dt + ELSE ! both pockets are one side of bit + DO z = x , y + CALL PartialDerivativeFricToFlowRate(z) + IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN + WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe + WRITE (*,*) ' Op start, end, density, Q, mu' , FlowEl(z)%StartX, FlowEl(z)%EndX, FlowEl(z)%Density, FlowEl(z)%FlowRate, FlowEl(z)%mueff + CALL ErrorStop('NaN in calculating partial derivative') + END IF + END DO + ExitValue = ExitValue - SUM(FlowEl(x : y)%FricToQPartialDiff) * 448.8 / dt + END IF + + + ELSE IF (CalcMode == 4) THEN ! partial derivative of frictional pressure drop relative to flowrate for top gas pocket + ExitValue = - 2.d0 * Kchoke * FlowEl(OpenholeFirstEl - 1)%Flowrate * 448.8 / dt + IF (x >= OpenholeFirstEl) THEN ! kick STARTX is in openhole + DO z = x , NumbEl ! open hole elements + CALL PartialDerivativeFricToFlowRate(z) + IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN + WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe + WRITE (*,*) ' Op start, end, density, Q, mu' , FlowEl(z)%StartX, FlowEl(z)%EndX, FlowEl(z)%Density, FlowEl(z)%FlowRate, FlowEl(z)%mueff + CALL ErrorStop('NaN in calculating partial derivative') + END IF + END DO + DO z = AnnulusFirstEl , OpenholeFirstEl - 1 ! Annulus elements + CALL PartialDerivativeFricToFlowRate(z) + IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN + WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe + WRITE (*,*) ' Op start, end, density, Q, mu' , FlowEl(z)%StartX, FlowEl(z)%EndX, FlowEl(z)%Density, FlowEl(z)%FlowRate, FlowEl(z)%mueff + CALL ErrorStop('NaN in calculating partial derivative') + END IF + END DO + ExitValue = ExitValue - (SUM(FlowEl(x : NumbEl)%FricToQPartialDiff) + SUM(FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FricToQPartialDiff)) * 448.8 / dt + ELSE + DO z = x , OpenholeFirstEl - 1 ! Annulus elements + CALL PartialDerivativeFricToFlowRate(z) + IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN + WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe + WRITE (*,*) ' Op start, end, density, Q, mu' , FlowEl(z)%StartX, FlowEl(z)%EndX, FlowEl(z)%Density, FlowEl(z)%FlowRate, FlowEl(z)%mueff + CALL ErrorStop('NaN in calculating partial derivative') + END IF + END DO + ExitValue = ExitValue - SUM(FlowEl(x : OpenholeFirstEl - 1)%FricToQPartialDiff) * 448.8 / dt + END IF + + + ELSE IF (CalcMode == 5) THEN + IF (x >= OpenholeFirstEl .AND. y < OpenholeFirstEl) THEN ! Gas Pocket is in Openhole and upper pocket is in annulus + !WRITE (*,*) 'x , y 1' , x, y + ExitValue = GasPocketNewPress%Array(GasPocketNo + 1) + SUM(FlowEl(x : NumbEl)%StaticPressDiff) + SUM(FlowEl(AnnulusFirstEl : y)%StaticPressDiff) + ELSE ! Both gas pockets are in Annulus or openhole + !WRITE (*,*) 'x , y 2' , x, y + ExitValue = GasPocketNewPress%Array(GasPocketNo + 1) + SUM(FlowEl(x : y)%StaticPressDiff) + END IF + END IF + + + + END SUBROUTINE + + + +SUBROUTINE NewGasKick + + use KickVARIABLESModule + Use TD_WellGeometry + Use CReservoirVariables + Use CFormationVariables + USE Fluid_Flow_Startup_Vars + use PressureDisplayVARIABLESModule + USE FricPressDropVarsModule + USE MudSystemVARIABLES + USE CMudPropertiesVariables + USE CError + USE , INTRINSIC :: IEEE_ARITHMETIC + + + !! Note: a subject that may be confusing is that when we use gauge pressure and when using absolute pressure?! + !! all stated pressure are gauge pressure, so I do like this. + !! only when we want to use a state equation (like ideal gas equation), we should use absolute equation and so I do this. + !! Thus gas pocket pressure are all absolute pressure. + + IMPLICIT NONE + + INTEGER :: i , j , k , l + + IF (NOT(ALLOCATED(GasPocketWeight%Array))) THEN ! 1st kick + WRITE (*,*) ' New Influx 1' + + NoGasPocket = 1 + MudSystem%NewInfluxNumber = MudSystem%NewInfluxNumber + 1 + + MudSystem%NewInfluxElementCreated = 0 + KickOffBottom = .FALSE. + + + CALL GasPocketOldPress%AddToFirst((BottomHolePress + StandardPress) * 1.d0) + CALL GasPocketNewPress%AddToFirst((BottomHolePress + StandardPress) * 1.d0) + CALL GasPocketOldTemp%AddToFirst(600.0) + CALL GasPocketNewTemp%AddToFirst(600.0) + CALL GasPocketOldVol%AddToFirst(0.d0) + CALL GasPocketNewVol%AddToFirst(0.d0) + CALL GasPocketdeltaVol%AddToFirst(0.0) + CALL GasPocketFlowInduced%AddToFirst(0.0) + CALL GasPocketModifiedVol%AddToFirst(0.0) + CALL GasPocketWeight%AddToFirst(0.0) + CALL GasPocketDensity%AddToFirst(2.0) + CALL GasPocketCompressibility%AddToFirst(0.98) + + ALLOCATE(KickJacobian(2 , 2) , OldKickJacobian(2 , 2) , KickVandPFunction(2) , KickUnknownVector(2) , KickCorrectionVector(2)) + + BottomHoleTemperature = 600 + KickFluxAvgPressure = (BottomHolePress + FormPressure) / 2 + StandardPress + KickFluxAvgTemperature = (FormTemperature + BottomHoleTemperature) / 2 + KickFluxAvgCompressibility = 0.98 + + !K_Aa = (5.8742362 * 10.**(-3) * KickFluxAvgTemperature**1.2288) / (511.1728532 + KickFluxAvgTemperature) + !K_Bb = 5.5565586 + (1000.01 / KickFluxAvgTemperature) + !K_Cc = 2.47862 - 0.12294 * K_Bb + GasKickSIDensity = KickFluxAvgPressure / (KickFluxAvgCompressibility * & + KickFluxAvgTemperature * GasType(KickGasType)%GasConstant) * Convpcftogpcm3 + GasKickDensity = GasKickSIDensity * 8.3523 + + !GasKickViscosity = K_Aa * EXP(K_Bb * GasKickSIDensity**K_Cc) + ! + !K_BHTpr = BottomHoleTemperature / KickTc + !K_BHPpr = (BottomHolePress + StandardPress) / KickPc + ! + !K_A_Bottomhole = 3.53 * K_BHPpr + !K_B_Bottomhole = 10.0**(0.9813 * K_BHTpr) + !K_C_Bottomhole = 0.274 * (K_BHPpr**2) + !K_D_Bottomhole = 10.0**(0.8157 * K_BHTpr) + ! + !BottomHoleCompressibility = 0.98 !1. - (K_A_Bottomhole / K_B_Bottomhole) + (K_C_Bottomhole / K_D_Bottomhole) + ! + !GasKickBg = 0.00504 * KickFluxAvgCompressibility * KickFluxAvgTemperature / KickFluxAvgPressure ![bbl/SCF] + + + !KickmdotACoef = 10.**(-8) * 1.15741d0 * 7.08d0 * FormPermeability * REAL(KickFormLength) * GasType(KickGasType)%StDensity / & + !(GasKickViscosity * GasKickBg * LOG(10000.d0)) + !IF (WellHeadOpen) KickmdotACoef = (1.0 + 2.0) * KickmdotACoef + + !KickmdotBCoef = FormPressure + StandardPress !! - Sum(static and friction pressure loss) of flow elements below gas pocket, see below + + !GasPocketWeight%Array(1) = GasKickDensity * 0.05 !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + GasPocketWeight%Array(1) = GasKickDensity * MinKickVol !1.0:seyyed gofte !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + + GasPocketNewVol%Array(1) = GasPocketCompressibility%Array(1) * GasType(KickGasType)%GasConstant * & + GasPocketNewTemp%Array(1) * GasPocketWeight%Array(1) / GasPocketNewPress%Array(1) + + GasPocketDeltaVol%Array(1) = 0.05 !GasPocketNewVol%Array(1) + GasPocketFlowInduced%Array(1) = (GasPocketDeltaVol%Array(1)) / dt * 448.8 ! gpm + GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) + + WRITE (*,*) ' FormPressure , BottomHolePress' , FormPressure , BottomHolePress, GasKickDensity + WRITE (*,*) ' No Press(psia) Vol(gal) Weight(lbm) Flow Induced(gpm)' + DO i = 1 , NoGasPocket + WRITE (*,102) i , GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * Convft3toUSgal, GasPocketWeight%Array(i), GasPocketFlowInduced%Array(i) + END DO + + !ELSE IF (NoGasPocket < MaxGasPocket .AND. KickOffBottom .AND. (GasPocketNewVol%Array(1) > MinAllowableKickVol .OR. KickWasExitingThroughChoke)) THEN + ELSE IF (NoGasPocket < MaxGasPocket .AND. KickOffBottom .AND. (GasPocketNewVol%Array(1) > MinAllowableKickVol .OR. ANY(GasPocketFlowEl(1 , :) == OpenholeFirstEl - 1))) THEN + WRITE (*,*) ' New Influx', NoGasPocket + 1 + +102 FORMAT (I2, 4X, (F8.1), 3X, (F8.3), 2X, (F8.3), 8X, (F8.3)) + + + NoGasPocket = NoGasPocket + 1 + MudSystem%NewInfluxNumber = MudSystem%NewInfluxNumber + 1 + + MudSystem%NewInfluxElementCreated = 0 + KickOffBottom = .FALSE. + + CALL GasPocketOldPress%AddToFirst((BottomHolePress + StandardPress) * 1.d0) + CALL GasPocketNewPress%AddToFirst((BottomHolePress + StandardPress) * 1.d0) + CALL GasPocketOldTemp%AddToFirst(600.0) + CALL GasPocketNewTemp%AddToFirst(600.0) + CALL GasPocketOldVol%AddToFirst(0.d0) + CALL GasPocketNewVol%AddToFirst(0.d0) + CALL GasPocketdeltaVol%AddToFirst(0.0) + CALL GasPocketFlowInduced%AddToFirst(0.0) + CALL GasPocketModifiedVol%AddToFirst(0.0) + CALL GasPocketWeight%AddToFirst(0.0) + CALL GasPocketDensity%AddToFirst(2.0) + CALL GasPocketCompressibility%AddToFirst(0.98) + + DEALLOCATE(KickJacobian , OldKickJacobian , KickVandPFunction , KickUnknownVector , KickCorrectionVector) + + ALLOCATE(KickJacobian(2 * NoGasPocket , 2 * NoGasPocket) , OldKickJacobian(2 * NoGasPocket , 2 * NoGasPocket)) + ALLOCATE(KickUnknownVector(2 * NoGasPocket) , KickCorrectionVector(2 * NoGasPocket) , KickVandPFunction(2 * NoGasPocket)) + + + BottomHoleTemperature = 600 + KickFluxAvgPressure = (BottomHolePress + FormPressure) / 2 + StandardPress + KickFluxAvgTemperature = (FormTemperature + BottomHoleTemperature) / 2 + KickFluxAvgCompressibility = 0.98 + + !K_Aa = (5.8742362 * 10.**(-3) * KickFluxAvgTemperature**1.2288) / (511.1728532 + KickFluxAvgTemperature) + !K_Bb = 5.5565586 + (1000.01 / KickFluxAvgTemperature) + !K_Cc = 2.47862 - 0.12294 * K_Bb + GasKickSIDensity = KickFluxAvgPressure / (KickFluxAvgCompressibility * & + KickFluxAvgTemperature * GasType(KickGasType)%GasConstant) * Convpcftogpcm3 + GasKickDensity = GasKickSIDensity * 8.3523 + + !GasKickViscosity = K_Aa * EXP(K_Bb * GasKickSIDensity**K_Cc) + ! + !K_BHTpr = BottomHoleTemperature / KickTc + !K_BHPpr = (BottomHolePress + StandardPress) / KickPc + ! + !K_A_Bottomhole = 3.53 * K_BHPpr + !K_B_Bottomhole = 10.0**(0.9813 * K_BHTpr) + !K_C_Bottomhole = 0.274 * (K_BHPpr**2) + !K_D_Bottomhole = 10.0**(0.8157 * K_BHTpr) + ! + !BottomHoleCompressibility = 0.98 !1. - (K_A_Bottomhole / K_B_Bottomhole) + (K_C_Bottomhole / K_D_Bottomhole) + ! + !GasKickBg = 0.00504 * KickFluxAvgCompressibility * KickFluxAvgTemperature / KickFluxAvgPressure ![bbl/SCF] + ! + ! + !KickmdotACoef = 10.**(-8) * 1.15741d0 * 7.08d0 * FormPermeability * REAL(KickFormLength) * GasType(KickGasType)%StDensity / & + ! (GasKickViscosity * GasKickBg * LOG(10000.d0)) + !IF (WellHeadOpen) KickmdotACoef = (1.0 + 2.0) * KickmdotACoef + ! + !KickmdotBCoef = FormPressure + StandardPress !! - Sum(static and friction pressure loss) of flow elements below gas pocket, see below + + !GasPocketWeight%Array(1) = GasKickDensity * 0.05 !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + GasPocketWeight%Array(1) = GasKickDensity * MinKickVol !1.0:seyyed gofte !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + + GasPocketNewVol%Array(1) = GasPocketCompressibility%Array(1) * GasType(KickGasType)%GasConstant * & + GasPocketNewTemp%Array(1) * GasPocketWeight%Array(1) / GasPocketNewPress%Array(1) + + GasPocketDeltaVol%Array(1) = 0.05 !GasPocketNewVol%Array(1) + GasPocketFlowInduced%Array(1) = (GasPocketDeltaVol%Array(1)) / dt * 448.8 ! gpm + GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) + + WRITE (*,*) ' FormPressure , BottomHolePress' , FormPressure , BottomHolePress, GasKickDensity + WRITE (*,*) ' No Press(psia) Vol(gal) Weight(lbm) Flow Induced(gpm)' + DO i = 1 , NoGasPocket + WRITE (*,102) i , GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * Convft3toUSgal, GasPocketWeight%Array(i), GasPocketFlowInduced%Array(i) + END DO + + ELSE ! no new kick, so mass of 1st kick should increase + GasPocketWeight%Array(1) = GasPocketweight%Array(1) + KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) + + IF (NoGasPocket > 1 .OR. SecondaryKickWeight > 0.0) THEN + SecondaryKickWeight = SecondaryKickWeight + KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + SecondaryKickVol = SecondaryKickWeight / GasReservoirDensity / 42.0 ! 42 USGal = 1bbl + END IF + + END IF + + +END SUBROUTINE + \ No newline at end of file diff --git a/FluidFlow-old/kick/Kick_VARIABLES.f90 b/FluidFlow-old/kick/Kick_VARIABLES.f90 new file mode 100644 index 0000000..b7efd7f --- /dev/null +++ b/FluidFlow-old/kick/Kick_VARIABLES.f90 @@ -0,0 +1,95 @@ +MODULE KickVARIABLES + + USE DynamicDoubleArray + USE DynamicIntegerArray + USE DynamicRealArray + + IMPLICIT NONE + + + REAL :: DrillStringSpeed ! drill string speed during surge and swab [ft/s] + + REAL :: ChokeDensity , OldChokeDensity ! density of fluid that exits through choke [ppg] + REAL :: ChokeMinDensity ! [ppg] + REAL :: MaxChokeDensityChange ! [ppg/min] + + + INTEGER :: TotalGasKicks ! Number of gas kicks enetered well + REAL :: GasKickMolarMass ! molar mass of gas kick [lbm/lbmole] + REAL :: GasKickBg ! Gas formation volume factor [bbl/SCF] + REAL :: GasResPressure , GasResTemperature , GasResCompressibility ! pressure [psi] , temperature [R] and compressibility [-] at reservoir condition + REAL :: GasReservoirDensity ! density of gas kick in reservoir condition [ppg] + REAL :: BottomHolePress , BottomHoleTemperature , BottomHoleCompressibility ! pressure [psi] , temperature [R] and compressibility [-] at bottom hole condition + REAL :: KickFluxAvgTemperature , KickFluxAvgPressure , KickFluxAvgCompressibility ! Average pressure [psia] and temperature [R] for calculating gas kick flux + REAL :: GasKickViscosity ! Gas kick viscosity at average condition [cp] + REAL :: GasKickSIDensity ! density of gas kick in average condition and in SI units [gr/cm^3] + REAL :: GasKickDensity ! [ppg] + REAL :: GasKickPumpFlowRate ! change of volume of gas kick in sense of flow rate [gpm] + REAL :: FormPressure , FormTemperature + REAL(8) :: KickFormLength , KickFormTopMD , KickFormDownMD ! [ft] + REAL :: FormPermeability ! formation permeability [mD] + REAL :: GasSpecGravity ! specific gravity of gas kick relative to air [-] + REAL :: KickTc , KickPc ! critical temperature [R] and pressure [psi] of gas kick + REAL :: KickTr , KickPr ! Reduced temperature and pressure of gas kick at reservoir condition + REAL :: K_BHTpr , K_BHPpr ! Reduced temperature and pressure of gas kick at bottom hole condition + REAL :: K_A_Res , K_B_Res , K_C_Res , K_D_Res ! Coefficients in calculating compressibility at reservoir condition + REAL :: K_A_Bottomhole , K_B_Bottomhole , K_C_Bottomhole , K_D_Bottomhole + ! Coefficients in calculating compressibility at bottomhole condition + REAL :: K_Aa , K_Bb , K_Cc ! Coefficient in calculating gas viscosity at reservoir condition + REAL :: MinKickVol ! minimum of kick volume at the beginning of entrance to wellbore [gal] + REAL :: MinAllowableKickVol ! minimum allowable kick volume [ft^3] + REAL :: SecondaryKickVol ! Volume of kicks other than first kick in reservoir condition [bbl] + REAL :: SecondaryKickWeight ! Weight of kicks other than first kick in reservoir condition [lbm] + + + REAL :: Kickmdot ! mass flow rate of kick [lbm/sec] + REAL :: ExitMass ! escaped mass from choke [lbm] + REAL :: KickmdotACoef ! coefficient in calculating mdot of kick, Eqn. 5 handnote [lbm/(sec.psi)] + REAL :: KickmdotBCoef ! coefficient in calculating mdot of kick, Eqn. 5 handnote [psi] + + LOGICAL :: KickFlux ! .TRUE. = Bottomhole pressure is lower than reservoir pressure and thus gas + ! enters the bottomhole. + LOGICAL :: KickInFluxConditions ! a set of conditions, when all are true, this variable will become true + LOGICAL :: WellHeadOpen ! .TRUE. = wellhead is open or flow on choke line + ! .FALSE. = wellhead is close and no fluid flow out + LOGICAL :: WellHeadWasOpen ! well Head Condition in last time step + LOGICAL :: WellToChokeManifoldWasOpen + LOGICAL :: KickOffBottom ! .TRUE. = kick starts to rise up + LOGICAL :: KickSinglePocket ! when 'MakeKickSinglePacket' is active, only one pocket of kick exists in the well. + LOGICAL :: SolvingEquationError + LOGICAL :: KickWasExitingThroughChoke + LOGICAL :: ChokeIsClosing + + INTEGER :: NoGasPocket ! number of gas pockets (not gas kick) in wellbore which may migrate or expand + INTEGER :: KickIteration ! the number of itertion for calculating pressure and flowrate, when kick is in the well + INTEGER :: KickType ! = 0 for gas kicks , = 1 for oil kicks and = 2 for water kicks + INTEGER :: KickGasType ! = 1 for methane , = 2 for Hydrogen sulfide + INTEGER :: ChokeKroneckerDelta ! if well to choke manifold is open and well to pit is closed ChokeKroneckerDelta = 1 + INTEGER :: MaxGasPocket ! = 1 if 'single pocket model' is on and = 15 if 'single pocket model' is off + + !!!!!!!!!!!!!!!!!!!!!!! Gas Pockets Data + TYPE(DynamicDoubleArrayType) :: GasPocketOldPress , GasPocketOldVol ! pressure and volume of gas pocket at the beginning of time step [psia , ft^3] + TYPE(DynamicDoubleArrayType) :: GasPocketNewPress , GasPocketNewVol ! pressure and volume of gas pocket at the end of time step [psia , ft^3] + TYPE(DynamicRealArrayType) :: GasPocketOldTemp , GasPocketNewTemp ! temperature at the beginning (old) and at the end of time step [R] + TYPE(DynamicRealArrayType) :: GasPocketFlowInduced , GasPocketDeltaVol ! flowrate in elements above gas pocket due to mass influx and expansion [gpm] + TYPE(DynamicRealArrayType) :: GasPocketModifiedVol ! in some situation in migration process, or entering kick in a new space type + ! such as entering annulus from openhole, or entering ckokeline from annulus, + ! volume of gas pocket changes due to calculation process, and thus volume of + ! gas pocket should be modified [10^-3 ft^3] + TYPE(DynamicRealArrayType) :: GasPocketWeight ! weight of pocket [lbm] + TYPE(DynamicRealArrayType) :: GasPocketDensity ! density of gas pocket [ppg] + TYPE(DynamicRealArrayType) :: GasPocketCompressibility ! compressibility as a measure of deviation from ideal gas behavior [-] + INTEGER , DIMENSION(:,:) , ALLOCATABLE :: GasPocketFlowEl ! This matrix makes relationship between gas pockets and flow elements, + ! Further information in SUBROUTINE GasPocketFlowElementTransformer + INTEGER , DIMENSION(:,:) , ALLOCATABLE :: tempGasPocketFlowEl ! a temperorary matrix using for data saving during GasPocketFlowEl manipulation + !INTEGER , DIMENSION(:) , ALLOCATABLE :: GasPocketGasType ! = 1 for methane , = 2 for Hydrogen Sulfide + + REAL(8) , DIMENSION(:,:) , ALLOCATABLE :: KickJacobian , OldKickJacobian ! a matrix in which jacibian elements stored + REAL(8) , DIMENSION(:) , ALLOCATABLE :: KickVandPFunction + REAL(8) , DIMENSION(:) , ALLOCATABLE :: KickUnknownVector ! (2*n - 1) elements are flowrate and (2*n) elements are pressure of pockets (n >= 1) + REAL , DIMENSION(:) , ALLOCATABLE :: KickCorrectionVector + REAL :: KickCorrectionUnderRelaxation ! under relaxation parameter for correcting gas Kick Unknown Vector (0,1) + ! = 0 means no correction between two step + ! = 1 for direct correcting and no under relaxation + + END MODULE \ No newline at end of file diff --git a/FluidFlow-sh/Annulus_and_Openhole_Pressure_Distribution.f90 b/FluidFlow-sh/Annulus_and_Openhole_Pressure_Distribution.f90 new file mode 100644 index 0000000..bdc2fe3 --- /dev/null +++ b/FluidFlow-sh/Annulus_and_Openhole_Pressure_Distribution.f90 @@ -0,0 +1,278 @@ +SUBROUTINE PressureAnnAndOHDistribution + + !! Record of revisions + !! Date Programmer Discription of change + !! ------ ------------ ----------------------- + !! 1396/07/30 Sheikh Original code + !! + + USE FricPressDropVarsModule + USE MudSystemVARIABLES + use PressureDisplayVARIABLESModule + USE GeoElements_FluidModule + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule + USE CMudPropertiesVariables + USE TD_WellGeometry + USE CReservoirVariables + use MudSystemModule + USE CHOKEVARIABLES + USE CChokeManifoldVariables + USE VARIABLES + USE CError + USE , INTRINSIC :: IEEE_ARITHMETIC + + + IMPLICIT NONE + + INTEGER :: i , j , k , l + INTEGER :: ifric + REAL :: Fraction + + + FricPressDropVars%KBOP = 0.0 + + + +IF (KickVARIABLES%WellHeadOpen .OR. KickVARIABLES%NoGasPocket == 0) THEN !! (mud circulation is normal wellhead may be open or closed) OR (kick is in the well and well head is open) + + + !!!!! Determining flow rate in each section + i = FricPressDropVars%AnnulusFirstEl + j = FricPressDropVars%OpenholeFirstEl - 1 + + !!!!!!!!!!!!!!!!!!!!!!!!! flowrates due to external sources like pump and tripping + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = (ClingingFactor * FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%Area + FlowEl(FricPressDropVars%StringFirstEl)%Area) * KickVARIABLES%DrillStringSpeed * ConvMintoSec * Convft3toUSgal ! flowrate in annulus due to tripping + + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate + REAL(MudSystem%MudVolume_InjectedToBH) * ConvMintoSec / dt ! flowrate in annulus due to pump + + IF (MudSystem%ShoeFractured) THEN ! reduction of flowrate due to formation fracture and lost circulation + + IF (ShoeFlowElNo > FricPressDropVars%AnnulusLastEl) THEN ! shoe is in openhole + FlowEl(ShoeFlowElNo : FricPressDropVars%NumbEl)%FlowRate = - MudSystem%Qlost + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate - MudSystem%Qlost + ELSE ! shoe is in annulus + FlowEl(ShoeFlowElNo : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(ShoeFlowElNo : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate - MudSystem%Qlost + END IF + END IF + + + !!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!! initial guess flowrates for opening BOP or choke line + IF (KickVARIABLES%WellHeadWasOpen == .FALSE. .AND. KickVARIABLES%NoGasPocket > 0 .AND. KickVARIABLES%KickIteration == 1) THEN + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN ! flow on choke line + IF (FricPressDropVars%TotalOpenChokeArea < 0.01 * Choke%ChokeAreaFullyOpen) THEN + WRITE (*,*) 'density , TotalOpenChokeArea' , DownHole%Density, FricPressDropVars%TotalOpenChokeArea + FricPressDropVars%TotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen + END IF + FricPressDropVars%Kchoke = (KickVARIABLES%ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * FricPressDropVars%TotalOpenChokeArea)**2)) * 4.0 ! *4.d0: seyyed gofte + GasPocketFlowInduced%Array(:) = MIN((0.6 / KickVARIABLES%NoGasPocket * SQRT(PressureGauges(2) / FricPressDropVars%Kchoke)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) + WRITE (*,*) ' PressureGauges(2) , Kchoke' , PressureDisplayVARIABLES%PressureGauges(2) , FricPressDropVars%Kchoke + WRITE (*,*) 'Initial guess after opening choke =', GasPocketFlowInduced%Array(1) + + WRITE (*,*) ' valve 49 ', Manifold%Valve(49)%Status + WRITE (*,*) ' valve 47 ', Manifold%Valve(47)%Status + WRITE (*,*) ' valve 26 ', Manifold%Valve(26)%Status + WRITE (*,*) ' valve 30 ', Manifold%Valve(30)%Status + WRITE (*,*) ' valve 34 ', Manifold%Valve(34)%Status + WRITE (*,*) ' valve 63 ', Manifold%Valve(63)%Status + WRITE (*,*) ' valve 28 ', Manifold%Valve(28)%Status + WRITE (*,*) ' valve 33 ', Manifold%Valve(33)%Status + WRITE (*,*) ' valve 62 ', Manifold%Valve(62)%Status + WRITE (*,*) ' valve 36 ', Manifold%Valve(36)%Status + WRITE (*,*) ' valve 38 ', Manifold%Valve(38)%Status + + ELSE ! flow through bell nipple + k = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl + FricPressDropVars%KBOP = FlowEl(FricPressDropVars%AnnulusLastEl)%Density / ((2.0 * 89158.0) * (0.26 * 0.61 * ShearRam%MinimumOpenArea_InBOP)**2) + GasPocketFlowInduced%Array(:) = MIN((0.1 / KickVARIABLES%NoGasPocket * SQRT(PressureDisplayVARIABLES%PressureGauges(6) / FricPressDropVars%KBOP)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) + WRITE (*,*) 'PressureGauges(6), KBOP', PressureDisplayVARIABLES%PressureGauges(6), FricPressDropVars%KBOP + WRITE (*,*) 'Initial guess after opening BOP =', GasPocketFlowInduced%Array(1) + END IF + END IF + !!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!!!!! flowrates due to expansion of gas pockets or kick influx + !i = AnnulusFirstEl + !j = OpenholeFirstEl - 1 + IF (KickVARIABLES%NoGasPocket > 0) THEN + DO l = 1 , KickVARIABLES%NoGasPocket !GasPocketFlowEl + k = KickVARIABLES%GasPocketFlowEl(l , 1) + !WRITE (*,*) 'KickVARIABLES%GasPocketFlowEl(l , 1)', l, k, j + IF (k == 0) CALL ERRORSTOP('GasPocketFlowEl(l , 1) == 0', l) + + IF (k >= FricPressDropVars%OpenholeFirstEl) THEN ! gas pocket is in open hole only + FlowEl(k : FricPressDropVars%NumbEl)%FlowRate = FlowEl(k : FricPressDropVars%NumbEl)%FlowRate + GasPocketFlowInduced%Array(l) ! openhole elements above pocket + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus and choke line elements + ELSE IF (k < FricPressDropVars%OpenholeFirstEl) THEN ! gas pocket is in annulus ond/or choke line only + FlowEl(k : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(k : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus or choke line elements above pocket + END IF + END DO + END IF + + + !!!!!!!!!!!!!!!!!!!!!!!!! + !!!!! END - Determining flow rate in each section + + !!!!!!!!!!!!!!!!!!!!!!!!! effect of surge and swab on frictional pressure drop direction + DO l = FricPressDropVars%AnnulusFirstEl , FricPressDropVars%OpenholeFirstEl - 1 + IF (FlowEl(l)%FlowRate < 0.0) THEN + FlowEl(l)%FrictionDirection = -1 + IF (FlowEl(l)%FlowRate > -1.0 * PressFlowrateTolerance .AND. ALLOCATED(GasPocketWeight%Array)) FlowEl(l)%FlowRate = - PressFlowrateTolerance + ELSE + FlowEl(l)%FrictionDirection = 1 + IF (FlowEl(l)%FlowRate < PressFlowrateTolerance .AND. ALLOCATED(GasPocketWeight%Array)) FlowEl(l)%FlowRate = PressFlowrateTolerance + END IF + END DO + !!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!!!!! Calculating Back Pressure, in well to pit path back pressure = 0 + ! in well to choke manifold path back pressure is equal to pressure before choke not casing pressure + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN + + IF (FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%FlowRate < 0.0) THEN + WRITE (*,*) ' Negative choke flowrate' + FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = MAX((REAL(MudSystem%MudVolume_InjectedToBH) * ConvMintoSec / dt) , 10.0) + END IF + MudSystem%deltaPchoke = (FricPressDropVars%Kchoke * FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%FlowRate * ABS(FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%FlowRate)) * 1.d0 + IF (MudSystem%deltaPchoke < 0.d0) MudSystem%deltaPchoke = 0.d0 + FricPressDropVars%BackPressure = REAL(MudSystem%deltaPchoke) + ELSE + FricPressDropVars%BackPressure = 0.0 + END IF + IF (IEEE_IS_NaN(FricPressDropVars%BackPressure)) CALL ErrorStop('NaN in calculating back pressure' , FlowEl(j)%FlowRate) + !write(*,*) 'BackPressure=' , BackPressure + + !!!!!!!!!!!!!!!!!!!!!!!!! when flow passes through choke manifold, solution process may be unstable + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN ! thus we should stabilize solution + IF (FricPressDropVars%TotalOpenChokeArea > 0.5 * Choke%ChokeAreaFullyOpen) THEN + KickVARIABLES%KickCorrectionUnderRelaxation = 0.6 + ELSE IF (FricPressDropVars%TotalOpenChokeArea > 0.1 * Choke%ChokeAreaFullyOpen) THEN + KickVARIABLES%KickCorrectionUnderRelaxation = 0.5 + ELSE ! TotalOpenChokeArea < 0.1 * ChokeAreaFullyOpen + KickVARIABLES%KickCorrectionUnderRelaxation = 0.4 + END IF + ELSE + KickVARIABLES%KickCorrectionUnderRelaxation = 0.6 + END IF + !!!!!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!!!!! calculating frictional pressure drop in annulus, chooke line and open hole elements + DO ifric = FricPressDropVars%AnnulusFirstEl , FricPressDropVars%NumbEl + CALL FricPressDrop(ifric) + !WRITE (*,*) ' element No, FlowRate , Density, FricPressLoss', ifric, FlowEl(ifric)%FlowRate, FlowEl(ifric)%Density, FlowEl(ifric)%FricPressLoss + IF (IEEE_IS_NaN(FlowEl(ifric)%FricPressLoss)) THEN + WRITE (*,*) 'H, S, A, Ch, O', FricPressDropVars%NoHorizontalEl , FricPressDropVars%NoStringEl , FricPressDropVars%NoAnnulusEl , FricPressDropVars%NoWellToChokeEl , FricPressDropVars%NoOpenHoleEl + WRITE (*,*) 'Ann/Op start, end, density, Q, mu, Type' , FlowEl(ifric)%StartX, FlowEl(ifric)%EndX, FlowEl(ifric)%Density, FlowEl(ifric)%FlowRate, FlowEl(ifric)%mueff, FlowEl(ifric)%MaterialType + CALL ErrorStop('NaN in calculating pressure drop' , ifric) + END IF + + END DO + + + !!!!!!!!!!!!!!!!!!!!!!!!! Pressure distribution in annulus + j = FricPressDropVars%OpenholeFirstEl - 1 + FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%EndPress = FricPressDropVars%BackPressure + FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%StartPress = FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%EndPress + FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%FricPressLoss + FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%StaticPressDiff + + + DO l = FricPressDropVars%OpenholeFirstEl - 2 , FricPressDropVars%AnnulusFirstEl , -1 + !WRITE (*,*) '123' + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%FricPressLoss + FlowEl(l)%StaticPressDiff + END DO + + + !!!!!!!!!!!!!!!!! Pressure distribution in Open Hole + FlowEl(FricPressDropVars%NumbEl)%EndPress = FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress + FlowEl(FricPressDropVars%NumbEl)%StartPress = FlowEl(FricPressDropVars%NumbEl)%EndPress + FlowEl(FricPressDropVars%NumbEl)%FricPressLoss + FlowEl(FricPressDropVars%NumbEl)%StaticPressDiff + + DO l = FricPressDropVars%NumbEl - 1 , FricPressDropVars%OpenholeFirstEl , -1 + !WRITE(*,*) ' ope' + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%FricPressLoss + FlowEl(l)%StaticPressDiff + !WRITE (*,*) ' Length, static, frictional open' , FlowEl(i)%Length, FlowEl(i)%StaticPressDiff, FlowEl(i)%FricPressLoss + + !END IF + END DO + +ELSE ! wellhead is closed and kick is in the well + !WRITE (*,*) ' well head is closed' + k = KickVARIABLES%GasPocketFlowEl(KickVARIABLES%NoGasPocket , 1) + !WRITE (*,*) 'k, Pocket Press', k, GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) - StandardPress + i = FricPressDropVars%AnnulusFirstEl + j = FricPressDropVars%OpenholeFirstEl - 1 + FlowEl(k)%StartPress = GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) - StandardPress + FlowEl(k)%EndPress = GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) - StandardPress + IF (k > FricPressDropVars%OpenholeFirstEl - 1) THEN ! Top pocket StartX is in Open hole + !WRITE (*,*) 'here 1' + DO l = k - 1 , FricPressDropVars%OpenholeFirstEl , -1 ! below elements in openhole + !WRITE (*,*) 'here 1-1' + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff + END DO + + DO l = k + 1 , FricPressDropVars%NumbEl ! Above elements in openhole + !WRITE (*,*) 'here 1-2' + FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress + FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff + END DO + + FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress = FlowEl(FricPressDropVars%NumbEl)%EndPress + FlowEl(FricPressDropVars%AnnulusFirstEl)%EndPress = FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress - FlowEl(FricPressDropVars%AnnulusFirstEl)%StaticPressDiff + + DO l = FricPressDropVars%AnnulusFirstEl + 1 , FricPressDropVars%OpenholeFirstEl - 1 + FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress + FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff + END DO + + ELSE ! Top pocket StartX is in annulus or choke line + + DO l = k - 1 , FricPressDropVars%AnnulusFirstEl , -1 ! below elements in annnulus + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff + END DO + + DO l = k + 1 , FricPressDropVars%OpenholeFirstEl - 1 ! Above elements in annulus + FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress + FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff + END DO + + FlowEl(FricPressDropVars%NumbEl)%EndPress = FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress + FlowEl(FricPressDropVars%NumbEl)%StartPress = FlowEl(FricPressDropVars%NumbEl)%EndPress + FlowEl(FricPressDropVars%NumbEl)%StaticPressDiff + + DO l = FricPressDropVars%NumbEl - 1 , FricPressDropVars%OpenholeFirstEl , -1 + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff + END DO + + END IF + +END IF + + !!!!!!!!!!!!!!!!!!!!!! checking pressure for preventing NaN in pressures + DO l = FricPressDropVars%OpenholeFirstEl - 1 , FricPressDropVars%AnnulusFirstEl , -1 ! annulus or choke elements + !WRITE (*,*) 'start, end' , FlowEl(i)%StartX, FlowEl(i)%EndX + IF (IEEE_IS_NaN(FlowEl(l)%EndPress)) THEN + WRITE (*,*) 'H, S, A, Ch, O', FricPressDropVars%NoHorizontalEl , FricPressDropVars%NoStringEl , FricPressDropVars%NoAnnulusEl , FricPressDropVars%NoWellToChokeEl , FricPressDropVars%NoOpenHoleEl + WRITE (*,*) 'Ann/Ch start, end, density, Q, mu' , FlowEl(l)%StartX, FlowEl(l)%EndX, FlowEl(l)%Density, FlowEl(l)%FlowRate, FlowEl(l)%mueff, FlowEl(l)%MaterialType + CALL ERRORSTOP('NaN in EndPress', l) + END IF + END DO + + DO l = FricPressDropVars%NumbEl , FricPressDropVars%OpenholeFirstEl - 1 , -1 ! op elements + !WRITE (*,*) 'start, end' , FlowEl(i)%StartX, FlowEl(i)%EndX + IF (IEEE_IS_NaN(FlowEl(l)%EndPress)) THEN + WRITE (*,*) 'H, S, A, Ch, O', FricPressDropVars%NoHorizontalEl , FricPressDropVars%NoStringEl , FricPressDropVars%NoAnnulusEl , FricPressDropVars%NoWellToChokeEl , FricPressDropVars%NoOpenHoleEl + WRITE (*,*) 'Op start, end, density, Q, mu' , FlowEl(l)%StartX, FlowEl(l)%EndX, FlowEl(l)%Density, FlowEl(l)%FlowRate, FlowEl(l)%mueff, FlowEl(l)%MaterialType + CALL ERRORSTOP('NaN in EndPress', l) + END IF + END DO + !!!!!!!!!!!!!!!!!!!!!! + + !!!!!!!!!!!!!!!!!!!!!! + KickVARIABLES%BottomHolePress = FlowEl(FricPressDropVars%OpenholeFirstEl)%StartPress + + !!!!!!!!!!!!!!!!!!!!!! + +END SUBROUTINE \ No newline at end of file diff --git a/FluidFlow/Annulus_Property_Calculator.f90 b/FluidFlow/Annulus_Property_Calculator.f90 index 121569d..7fc4c10 100644 --- a/FluidFlow/Annulus_Property_Calculator.f90 +++ b/FluidFlow/Annulus_Property_Calculator.f90 @@ -1,10 +1,10 @@ SUBROUTINE AnnulusPropertyCalculator (md, den, pre, tem) !!! This subroutine gets location of a guage or an observation point and determines information of that point such as pressure, density, velocity and temperature later. - USE PressureDisplayVARIABLES + use PressureDisplayVARIABLESModule USE Fluid_Flow_Startup_Vars USE MudSystemVARIABLES - USE FricPressDropVars + USE FricPressDropVarsModule USE CDrillWatchVariables IMPLICIT NONE @@ -19,13 +19,13 @@ SUBROUTINE AnnulusPropertyCalculator (md, den, pre, tem) CALL TVD_Calculator(md * 1.d0 , TVD) - IF (md <= INT(FinalFlowEl(AnnulusFirstEl)%StartX)) THEN !! mouse pointer is in the annulus space - DO ilocal = AnnulusFirstEl , AnnulusLastEl + IF (md <= INT(FinalFlowEl(FricPressDropVars%AnnulusFirstEl)%StartX)) THEN !! mouse pointer is in the annulus space + DO ilocal = FricPressDropVars%AnnulusFirstEl , FricPressDropVars%AnnulusLastEl IF (INT(FinalFlowEl(ilocal)%EndX) <= md) EXIT END DO - ELSE IF (md > INT(FinalFlowEl(NumbEl)%EndX)) THEN ! mouse pointer is in the open hole space - DO ilocal = OpenholeFirstEl , NumbEl + ELSE IF (md > INT(FinalFlowEl(FricPressDropVars%NumbEl)%EndX)) THEN ! mouse pointer is in the open hole space + DO ilocal = FricPressDropVars%OpenholeFirstEl , FricPressDropVars%NumbEl IF (INT(FinalFlowEl(ilocal)%EndX) <= md) EXIT END DO diff --git a/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90 b/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90 index a7330df..8e37a58 100644 --- a/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90 +++ b/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90 @@ -6,12 +6,12 @@ SUBROUTINE PressureAnnAndOHDistribution !! 1396/07/30 Sheikh Original code !! - USE FricPressDropVars + USE FricPressDropVarsModule USE MudSystemVARIABLES - USE PressureDisplayVARIABLES + use PressureDisplayVARIABLESModule USE GeoElements_FluidModule USE Fluid_Flow_Startup_Vars - USE KickVariables + use KickVARIABLESModule USE CMudPropertiesVariables USE TD_WellGeometry USE CReservoirVariables @@ -30,51 +30,44 @@ SUBROUTINE PressureAnnAndOHDistribution REAL :: Fraction - KBOP = 0.0 + FricPressDropVars%KBOP = 0.0 -IF (WellHeadOpen .OR. NoGasPocket == 0) THEN !! (mud circulation is normal wellhead may be open or closed) OR (kick is in the well and well head is open) +IF (KickVARIABLES%WellHeadOpen .OR. KickVARIABLES%NoGasPocket == 0) THEN !! (mud circulation is normal wellhead may be open or closed) OR (kick is in the well and well head is open) !!!!! Determining flow rate in each section - i = AnnulusFirstEl - j = OpenholeFirstEl - 1 + i = FricPressDropVars%AnnulusFirstEl + j = FricPressDropVars%OpenholeFirstEl - 1 !!!!!!!!!!!!!!!!!!!!!!!!! flowrates due to external sources like pump and tripping - !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(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = (ClingingFactor * FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%Area + FlowEl(FricPressDropVars%StringFirstEl)%Area) * KickVARIABLES%DrillStringSpeed * ConvMintoSec * Convft3toUSgal ! flowrate in annulus due to tripping - 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 = MudSystem%AnnulusFlowRate + (DeltaVolumePipe * ConvMinToSec / dt) - !END IF + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate + REAL(MudSystem%MudVolume_InjectedToBH) * ConvMintoSec / dt ! flowrate in annulus due to pump 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 = - MudSystem%Qlost - FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate = FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate - MudSystem%Qlost + IF (ShoeFlowElNo > FricPressDropVars%AnnulusLastEl) THEN ! shoe is in openhole + FlowEl(ShoeFlowElNo : FricPressDropVars%NumbEl)%FlowRate = - MudSystem%Qlost + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate - MudSystem%Qlost ELSE ! shoe is in annulus - FlowEl(ShoeFlowElNo : OpenholeFirstEl - 1)%FlowRate = FlowEl(ShoeFlowElNo : OpenholeFirstEl - 1)%FlowRate - MudSystem%Qlost + FlowEl(ShoeFlowElNo : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(ShoeFlowElNo : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate - MudSystem%Qlost END IF END IF !!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!! initial guess flowrates for opening BOP or choke line - IF (WellHeadWasOpen == .FALSE. .AND. NoGasPocket > 0 .AND. KickIteration == 1) THEN - IF (ChokeKroneckerDelta == 1) THEN ! flow on choke line - IF (TotalOpenChokeArea < 0.01 * Choke%ChokeAreaFullyOpen) THEN - WRITE (*,*) 'density , TotalOpenChokeArea' , DownHole%Density, TotalOpenChokeArea - TotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen + IF (KickVARIABLES%WellHeadWasOpen == .FALSE. .AND. KickVARIABLES%NoGasPocket > 0 .AND. KickIteration == 1) THEN + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN ! flow on choke line + IF (FricPressDropVars%TotalOpenChokeArea < 0.01 * Choke%ChokeAreaFullyOpen) THEN + WRITE (*,*) 'density , TotalOpenChokeArea' , DownHole%Density, FricPressDropVars%TotalOpenChokeArea + FricPressDropVars%TotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen END IF - Kchoke = (ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * TotalOpenChokeArea)**2)) * 4.0 ! *4.d0: seyyed gofte - GasPocketFlowInduced%Array(:) = MIN((0.6 / NoGasPocket * SQRT(PressureGauges(2) / Kchoke)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) - WRITE (*,*) ' PressureGauges(2) , Kchoke' , PressureGauges(2) , Kchoke + FricPressDropVars%Kchoke = (KickVARIABLES%ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * FricPressDropVars%TotalOpenChokeArea)**2)) * 4.0 ! *4.d0: seyyed gofte + GasPocketFlowInduced%Array(:) = MIN((0.6 / KickVARIABLES%NoGasPocket * SQRT(PressureDisplayVARIABLES%PressureGauges(2) / FricPressDropVars%Kchoke)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) + WRITE (*,*) ' PressureGauges(2) , Kchoke' , PressureDisplayVARIABLES%PressureGauges(2) , FricPressDropVars%Kchoke WRITE (*,*) 'Initial guess after opening choke =', GasPocketFlowInduced%Array(1) WRITE (*,*) ' valve 49 ', Manifold%Valve(49)%Status @@ -90,10 +83,10 @@ IF (WellHeadOpen .OR. NoGasPocket == 0) THEN !! (mud circulation is normal we WRITE (*,*) ' valve 38 ', Manifold%Valve(38)%Status ELSE ! flow through bell nipple - k = NoHorizontalEl + NoStringEl + NoAnnulusEl - KBOP = FlowEl(AnnulusLastEl)%Density / ((2.0 * 89158.0) * (0.26 * 0.61 * ShearRam%MinimumOpenArea_InBOP)**2) - GasPocketFlowInduced%Array(:) = MIN((0.1 / NoGasPocket * SQRT(PressureGauges(6) / KBOP)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) - WRITE (*,*) 'PressureGauges(6), KBOP', PressureGauges(6), KBOP + k = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl + FricPressDropVars%KBOP = FlowEl(FricPressDropVars%AnnulusLastEl)%Density / ((2.0 * 89158.0) * (0.26 * 0.61 * ShearRam%MinimumOpenArea_InBOP)**2) + GasPocketFlowInduced%Array(:) = MIN((0.1 / KickVARIABLES%NoGasPocket * SQRT(PressureDisplayVARIABLES%PressureGauges(6) / FricPressDropVars%KBOP)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) + WRITE (*,*) 'PressureGauges(6), KBOP', PressureDisplayVARIABLES%PressureGauges(6), FricPressDropVars%KBOP WRITE (*,*) 'Initial guess after opening BOP =', GasPocketFlowInduced%Array(1) END IF END IF @@ -102,29 +95,27 @@ IF (WellHeadOpen .OR. NoGasPocket == 0) THEN !! (mud circulation is normal we !!!!!!!!!!!!!!!!!!!!!!!!! flowrates due to expansion of gas pockets or kick influx !i = AnnulusFirstEl !j = OpenholeFirstEl - 1 - IF (NoGasPocket > 0) THEN - DO l = 1 , NoGasPocket !GasPocketFlowEl - k = GasPocketFlowEl(l , 1) - !WRITE (*,*) 'GasPocketFlowEl(l , 1)', l, k, j + IF (KickVARIABLES%NoGasPocket > 0) THEN + DO l = 1 , KickVARIABLES%NoGasPocket !GasPocketFlowEl + k = KickVARIABLES%GasPocketFlowEl(l , 1) + !WRITE (*,*) 'KickVARIABLES%GasPocketFlowEl(l , 1)', l, k, j IF (k == 0) CALL ERRORSTOP('GasPocketFlowEl(l , 1) == 0', l) - IF (k >= OpenholeFirstEl) THEN ! gas pocket is in open hole only - FlowEl(k : NumbEl)%FlowRate = FlowEl(k : NumbEl)%FlowRate + GasPocketFlowInduced%Array(l) ! openhole elements above pocket - FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate = FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus and choke line elements - ELSE IF (k < OpenholeFirstEl) THEN ! gas pocket is in annulus ond/or choke line only - FlowEl(k : OpenholeFirstEl - 1)%FlowRate = FlowEl(k : OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus or choke line elements above pocket + IF (k >= FricPressDropVars%OpenholeFirstEl) THEN ! gas pocket is in open hole only + FlowEl(k : FricPressDropVars%NumbEl)%FlowRate = FlowEl(k : FricPressDropVars%NumbEl)%FlowRate + GasPocketFlowInduced%Array(l) ! openhole elements above pocket + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus and choke line elements + ELSE IF (k < FricPressDropVars%OpenholeFirstEl) THEN ! gas pocket is in annulus ond/or choke line only + FlowEl(k : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate = FlowEl(k : FricPressDropVars%OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus or choke line elements above pocket END IF END DO END IF - !IF (ChokeKroneckerDelta == 1 .AND. ABS(FlowEl(i + NoAnnulusEl)%FlowRate / 600.0 - Ann_Saved_MudDischarged_Volume_Final) > 0.05) THEN - ! WRITE (*,*) 'Difference between flowrates', FlowEl(i + NoAnnulusEl + 1)%FlowRate / 600.0, Ann_Saved_MudDischarged_Volume_Final - !END IF + !!!!!!!!!!!!!!!!!!!!!!!!! !!!!! END - Determining flow rate in each section !!!!!!!!!!!!!!!!!!!!!!!!! effect of surge and swab on frictional pressure drop direction - DO l = AnnulusFirstEl , OpenholeFirstEl - 1 + DO l = FricPressDropVars%AnnulusFirstEl , FricPressDropVars%OpenholeFirstEl - 1 IF (FlowEl(l)%FlowRate < 0.0) THEN FlowEl(l)%FrictionDirection = -1 IF (FlowEl(l)%FlowRate > -1.0 * PressFlowrateTolerance .AND. ALLOCATED(GasPocketWeight%Array)) FlowEl(l)%FlowRate = - PressFlowrateTolerance @@ -137,95 +128,68 @@ IF (WellHeadOpen .OR. NoGasPocket == 0) THEN !! (mud circulation is normal we !!!!!!!!!!!!!!!!!!!!!!!!! Calculating Back Pressure, in well to pit path back pressure = 0 ! in well to choke manifold path back pressure is equal to pressure before choke not casing pressure - IF (ChokeKroneckerDelta == 1) THEN + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN - IF (FlowEl(OpenholeFirstEl - 1)%FlowRate < 0.0) THEN + IF (FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%FlowRate < 0.0) THEN WRITE (*,*) ' Negative choke flowrate' - FlowEl(OpenholeFirstEl - 1)%FlowRate = MAX((REAL(MudSystem%MudVolume_InjectedToBH) * ConvMintoSec / dt) , 10.0) + FlowEl(FricPressDropVars%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) - 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 + MudSystem%deltaPchoke = (FricPressDropVars%Kchoke * FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%FlowRate * ABS(FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%FlowRate)) * 1.d0 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 - !WRITE (*,*) 'Total Open Choke Area Percent' , TotalOpenChokeArea / 4.0 * ChokeAreaFullyOpen + FricPressDropVars%BackPressure = REAL(MudSystem%deltaPchoke) ELSE - BackPressure = 0.0 + FricPressDropVars%BackPressure = 0.0 END IF - IF (IEEE_IS_NaN(BackPressure)) CALL ErrorStop('NaN in calculating back pressure' , FlowEl(j)%FlowRate) + IF (IEEE_IS_NaN(FricPressDropVars%BackPressure)) CALL ErrorStop('NaN in calculating back pressure' , FlowEl(j)%FlowRate) !write(*,*) 'BackPressure=' , BackPressure !!!!!!!!!!!!!!!!!!!!!!!!! when flow passes through choke manifold, solution process may be unstable - IF (ChokeKroneckerDelta == 1) THEN ! thus we should stabilize solution - IF (TotalOpenChokeArea > 0.5 * Choke%ChokeAreaFullyOpen) THEN - KickCorrectionUnderRelaxation = 0.6 - ELSE IF (TotalOpenChokeArea > 0.1 * Choke%ChokeAreaFullyOpen) THEN - KickCorrectionUnderRelaxation = 0.5 + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN ! thus we should stabilize solution + IF (FricPressDropVars%TotalOpenChokeArea > 0.5 * Choke%ChokeAreaFullyOpen) THEN + KickVARIABLES%KickCorrectionUnderRelaxation = 0.6 + ELSE IF (FricPressDropVars%TotalOpenChokeArea > 0.1 * Choke%ChokeAreaFullyOpen) THEN + KickVARIABLES%KickCorrectionUnderRelaxation = 0.5 ELSE ! TotalOpenChokeArea < 0.1 * ChokeAreaFullyOpen - KickCorrectionUnderRelaxation = 0.4 + KickVARIABLES%KickCorrectionUnderRelaxation = 0.4 END IF ELSE - KickCorrectionUnderRelaxation = 0.6 + KickVARIABLES%KickCorrectionUnderRelaxation = 0.6 END IF !!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!! calculating frictional pressure drop in annulus, chooke line and open hole elements - DO ifric = AnnulusFirstEl , NumbEl + DO ifric = FricPressDropVars%AnnulusFirstEl , FricPressDropVars%NumbEl CALL FricPressDrop(ifric) !WRITE (*,*) ' element No, FlowRate , Density, FricPressLoss', ifric, FlowEl(ifric)%FlowRate, FlowEl(ifric)%Density, FlowEl(ifric)%FricPressLoss IF (IEEE_IS_NaN(FlowEl(ifric)%FricPressLoss)) THEN - WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl + WRITE (*,*) 'H, S, A, Ch, O', FricPressDropVars%NoHorizontalEl , FricPressDropVars%NoStringEl , FricPressDropVars%NoAnnulusEl , FricPressDropVars%NoWellToChokeEl , FricPressDropVars%NoOpenHoleEl WRITE (*,*) 'Ann/Op start, end, density, Q, mu, Type' , FlowEl(ifric)%StartX, FlowEl(ifric)%EndX, FlowEl(ifric)%Density, FlowEl(ifric)%FlowRate, FlowEl(ifric)%mueff, FlowEl(ifric)%MaterialType CALL ErrorStop('NaN in calculating pressure drop' , ifric) END IF END DO - !IF (ChokeKroneckerDelta == 1) THEN - !WRITE (*,*) ' velocity and flowrate', FlowEl(i)%vel, FlowEl(i)%flowrate - !WRITE (*,*) ' Theta600, Theta300', FlowEl(i)%Theta600 , FlowEl(i)%Theta300 - !WRITE (*,*) ' kIndex , nIndex', FlowEl(i)%kIndex, FlowEl(i)%nIndex - !WRITE (*,*) ' last el. mueff, gen. Rey.', i, FlowEl(i)%mueff, FlowEl(i)%GenRe - !END IF + !!!!!!!!!!!!!!!!!!!!!!!!! Pressure distribution in annulus - j = OpenholeFirstEl - 1 - FlowEl(OpenholeFirstEl - 1)%EndPress = BackPressure - FlowEl(OpenholeFirstEl - 1)%StartPress = FlowEl(OpenholeFirstEl - 1)%EndPress + FlowEl(OpenholeFirstEl - 1)%FricPressLoss + FlowEl(OpenholeFirstEl - 1)%StaticPressDiff + j = FricPressDropVars%OpenholeFirstEl - 1 + FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%EndPress = FricPressDropVars%BackPressure + FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%StartPress = FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%EndPress + FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%FricPressLoss + FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%StaticPressDiff - !write(*,*) 'FlowEl(j)%StartPress=' ,j, FlowEl(j)%StartPress - !write(*,*) 'FlowEl(j)%Length=' ,j, FlowEl(j)%Length, FlowEl(j)%EndX - !write(*,*) 'FlowEl(i)%dPdLFric=' ,i, FlowEl(i)%dPdLFric - DO l = OpenholeFirstEl - 2 , AnnulusFirstEl , -1 + DO l = FricPressDropVars%OpenholeFirstEl - 2 , FricPressDropVars%AnnulusFirstEl , -1 !WRITE (*,*) '123' FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%FricPressLoss + FlowEl(l)%StaticPressDiff - !WRITE(*,*) "ANNULUS: bottom , top Pressure", l , FlowEl(l)%StartPress , FlowEl(l)%EndPress , FlowEl(l)%fricPressLoss - !WRITE(*,*) "ANNULUS: Start , End X", FlowEl(l)%StartX , FlowEl(l)%EndX - - - !write(*,*) 'FlowEl(i)%StartPress=' ,i, FlowEl(i)%StartPress - !WRITE (*,*) ' FlowEl(i)%GenRe, FlowEl(i)%ReCritLam ' , FlowEl(i)%GenRe , FlowEl(i)%ReCritLam END DO !!!!!!!!!!!!!!!!! Pressure distribution in Open Hole - FlowEl(NumbEl)%EndPress = FlowEl(AnnulusFirstEl)%StartPress - FlowEl(NumbEl)%StartPress = FlowEl(NumbEl)%EndPress + FlowEl(NumbEl)%FricPressLoss + FlowEl(NumbEl)%StaticPressDiff - !WRITE (*,*) 'op top and op down' , FlowEl(NumbEl)%EndPress, FlowEl(j + 1)%StartPress - !write(*,*) 'FlowEl(NumbEl)%dPdLFric=' , FlowEl(NumbEl)%dPdLFric - !write(*,*) 'FlowEl(NumbEl)%dPdLGrav=' , FlowEl(NumbEl)%dPdLGrav + FlowEl(FricPressDropVars%NumbEl)%EndPress = FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress + FlowEl(FricPressDropVars%NumbEl)%StartPress = FlowEl(FricPressDropVars%NumbEl)%EndPress + FlowEl(FricPressDropVars%NumbEl)%FricPressLoss + FlowEl(FricPressDropVars%NumbEl)%StaticPressDiff - DO l = NumbEl - 1 , OpenholeFirstEl , -1 + DO l = FricPressDropVars%NumbEl - 1 , FricPressDropVars%OpenholeFirstEl , -1 !WRITE(*,*) ' ope' FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress - !IF (FlowEl(i)%FlowRate < 0.0d0) THEN - ! FlowEl(i)%StartPress = FlowEl(i)%EndPress - FlowEl(i)%FricPressLoss + FlowEl(i)%StaticPressDiff - !ELSE FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%FricPressLoss + FlowEl(l)%StaticPressDiff !WRITE (*,*) ' Length, static, frictional open' , FlowEl(i)%Length, FlowEl(i)%StaticPressDiff, FlowEl(i)%FricPressLoss @@ -234,76 +198,72 @@ IF (WellHeadOpen .OR. NoGasPocket == 0) THEN !! (mud circulation is normal we ELSE ! wellhead is closed and kick is in the well !WRITE (*,*) ' well head is closed' - k = GasPocketFlowEl(NoGasPocket , 1) - !WRITE (*,*) 'k, Pocket Press', k, GasPocketOldPress%Array(NoGasPocket) - StandardPress - i = AnnulusFirstEl - j = OpenholeFirstEl - 1 - FlowEl(k)%StartPress = GasPocketOldPress%Array(NoGasPocket) - StandardPress - FlowEl(k)%EndPress = GasPocketOldPress%Array(NoGasPocket) - StandardPress - IF (k > OpenholeFirstEl - 1) THEN ! Top pocket StartX is in Open hole + k = KickVARIABLES%GasPocketFlowEl(KickVARIABLES%NoGasPocket , 1) + !WRITE (*,*) 'k, Pocket Press', k, GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) - StandardPress + i = FricPressDropVars%AnnulusFirstEl + j = FricPressDropVars%OpenholeFirstEl - 1 + FlowEl(k)%StartPress = GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) - StandardPress + FlowEl(k)%EndPress = GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) - StandardPress + IF (k > FricPressDropVars%OpenholeFirstEl - 1) THEN ! Top pocket StartX is in Open hole !WRITE (*,*) 'here 1' - DO l = k - 1 , OpenholeFirstEl , -1 ! below elements in openhole + DO l = k - 1 , FricPressDropVars%OpenholeFirstEl , -1 ! below elements in openhole !WRITE (*,*) 'here 1-1' FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff END DO - DO l = k + 1 , NumbEl ! Above elements in openhole + DO l = k + 1 , FricPressDropVars%NumbEl ! Above elements in openhole !WRITE (*,*) 'here 1-2' FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff END DO - FlowEl(AnnulusFirstEl)%StartPress = FlowEl(NumbEl)%EndPress - FlowEl(AnnulusFirstEl)%EndPress = FlowEl(AnnulusFirstEl)%StartPress - FlowEl(AnnulusFirstEl)%StaticPressDiff + FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress = FlowEl(FricPressDropVars%NumbEl)%EndPress + FlowEl(FricPressDropVars%AnnulusFirstEl)%EndPress = FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress - FlowEl(FricPressDropVars%AnnulusFirstEl)%StaticPressDiff - DO l = AnnulusFirstEl + 1 , OpenholeFirstEl - 1 + DO l = FricPressDropVars%AnnulusFirstEl + 1 , FricPressDropVars%OpenholeFirstEl - 1 FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff END DO ELSE ! Top pocket StartX is in annulus or choke line - DO l = k - 1 , AnnulusFirstEl , -1 ! below elements in annnulus + DO l = k - 1 , FricPressDropVars%AnnulusFirstEl , -1 ! below elements in annnulus FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff END DO - DO l = k + 1 , OpenholeFirstEl - 1 ! Above elements in annulus + DO l = k + 1 , FricPressDropVars%OpenholeFirstEl - 1 ! Above elements in annulus FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff END DO - FlowEl(NumbEl)%EndPress = FlowEl(AnnulusFirstEl)%StartPress - FlowEl(NumbEl)%StartPress = FlowEl(NumbEl)%EndPress + FlowEl(NumbEl)%StaticPressDiff + FlowEl(FricPressDropVars%NumbEl)%EndPress = FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress + FlowEl(FricPressDropVars%NumbEl)%StartPress = FlowEl(FricPressDropVars%NumbEl)%EndPress + FlowEl(FricPressDropVars%NumbEl)%StaticPressDiff - DO l = NumbEl - 1 , OpenholeFirstEl , -1 + DO l = FricPressDropVars%NumbEl - 1 , FricPressDropVars%OpenholeFirstEl , -1 FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff END DO END IF - ! - ! !WRITE (*,*) ' first annulus bottom pressure ' , FlowEl(NoHorizontalEl + NoStringEl + 1)%StartPress - ! !WRITE (*,*) ' last OpenHole bottom pressure' , FlowEl(NumbEl)%StartPress - ! !WRITE (*,*) ' Gas Pocket pressure' , GasPocket%NewPress END IF !!!!!!!!!!!!!!!!!!!!!! checking pressure for preventing NaN in pressures - DO l = OpenholeFirstEl - 1 , AnnulusFirstEl , -1 ! annulus or choke elements + DO l = FricPressDropVars%OpenholeFirstEl - 1 , FricPressDropVars%AnnulusFirstEl , -1 ! annulus or choke elements !WRITE (*,*) 'start, end' , FlowEl(i)%StartX, FlowEl(i)%EndX IF (IEEE_IS_NaN(FlowEl(l)%EndPress)) THEN - WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl + WRITE (*,*) 'H, S, A, Ch, O', FricPressDropVars%NoHorizontalEl , FricPressDropVars%NoStringEl , FricPressDropVars%NoAnnulusEl , FricPressDropVars%NoWellToChokeEl , FricPressDropVars%NoOpenHoleEl WRITE (*,*) 'Ann/Ch start, end, density, Q, mu' , FlowEl(l)%StartX, FlowEl(l)%EndX, FlowEl(l)%Density, FlowEl(l)%FlowRate, FlowEl(l)%mueff, FlowEl(l)%MaterialType CALL ERRORSTOP('NaN in EndPress', l) END IF END DO - DO l = NumbEl , OpenholeFirstEl - 1 , -1 ! op elements + DO l = FricPressDropVars%NumbEl , FricPressDropVars%OpenholeFirstEl - 1 , -1 ! op elements !WRITE (*,*) 'start, end' , FlowEl(i)%StartX, FlowEl(i)%EndX IF (IEEE_IS_NaN(FlowEl(l)%EndPress)) THEN - WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl + WRITE (*,*) 'H, S, A, Ch, O', FricPressDropVars%NoHorizontalEl , FricPressDropVars%NoStringEl , FricPressDropVars%NoAnnulusEl , FricPressDropVars%NoWellToChokeEl , FricPressDropVars%NoOpenHoleEl WRITE (*,*) 'Op start, end, density, Q, mu' , FlowEl(l)%StartX, FlowEl(l)%EndX, FlowEl(l)%Density, FlowEl(l)%FlowRate, FlowEl(l)%mueff, FlowEl(l)%MaterialType CALL ERRORSTOP('NaN in EndPress', l) END IF @@ -311,27 +271,8 @@ END IF !!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!! - BottomHolePress = FlowEl(OpenholeFirstEl)%StartPress - !DO i = 1 , NoGasPocket - ! WRITE (*,*) ' Pocket, Pressure, Vol, Flow Induced, FlowElPress', i, REAL(GasPocketNewPress%Array(i)), REAL(GasPocketNewVol%Array(i)), GasPocketFlowInduced%Array(i), FlowEl(GasPocketFlowEl(i , 1))%StartPress - !END DO - !WRITE (*,*) ' BottomHolePress =' , BottomHolePress + KickVARIABLES%BottomHolePress = FlowEl(FricPressDropVars%OpenholeFirstEl)%StartPress + !!!!!!!!!!!!!!!!!!!!!! - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !IF (ChokeKroneckerDelta == 1) THEN - ! 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 - !END IF - - !IF (GasPocket%ElementNo == 0) THEN - ! KickUnknownVector(2) = BottomHolePress - !!ELSE - !! KickUnknownVector(2) = FlowEl(GasPocket%ElementNo)%StartPress - !END IF - !IF (WellHeadOpen) - ! GasPocket%NewPress = KickUnknownVector(2) - !END IF - !WRITE (*,*) 'Ann End' + END SUBROUTINE \ No newline at end of file diff --git a/FluidFlow/Flow_Startup.f90 b/FluidFlow/Flow_Startup.f90 index 95b674c..928df7b 100644 --- a/FluidFlow/Flow_Startup.f90 +++ b/FluidFlow/Flow_Startup.f90 @@ -1,90 +1,90 @@ SUBROUTINE FlowStartup - Use ConfigurationVariables + USE Fluid_Flow_Startup_Vars USE CStringConfigurationVariables USE CMudPropertiesVariables - USE FricPressDropVars - USE KickVariables + USE FricPressDropVarsModule + use KickVARIABLESModule USE MudSystemVARIABLES - USE PressureDisplayVARIABLES + use PressureDisplayVARIABLESModule USE CShoeVariables USE TD_DrillStemComponents USE TD_WellGeometry, pi3 => pi USE CPathGenerationVariables USE CWellSurveyDataVariables Use CHOKEVARIABLES, pi4 => pi - + use ConfigurationVariables IMPLICIT NONE INTEGER :: i - PressureGauges(:) = 0.0 + PressureDisplayVARIABLES%PressureGauges(:) = 0.0 - KickSinglePocket = Reservoir%MakeKickSinglePacket - IF (KickSinglePocket) THEN - MaxGasPocket = 1 + KickVARIABLES%KickSinglePocket = Reservoir%MakeKickSinglePacket + IF (KickVARIABLES%KickSinglePocket) THEN + KickVARIABLES%MaxGasPocket = 1 ELSE - MaxGasPocket = 4 + KickVARIABLES%MaxGasPocket = 4 END IF - MaxChokeDensityChange = 25.0 ! [ppg/min] - ChokeMinDensity = 2.0 + KickVARIABLES%MaxChokeDensityChange = 25.0 ! [ppg/min] + KickVARIABLES%ChokeMinDensity = 2.0 - ChokeDensity = MudProperties%ActiveDensity + KickVARIABLES%ChokeDensity = MudProperties%ActiveDensity - MinKickVol = 0.5 ! USGal + KickVARIABLES%MinKickVol = 0.5 ! USGal - SecondaryKickVol = 0.0 - SecondaryKickWeight = 0.0 + KickVARIABLES%SecondaryKickVol = 0.0 + KickVARIABLES%SecondaryKickWeight = 0.0 - NoGasPocket = 0 ! No Kick - WellHeadOpen = .TRUE. - WellHeadWasOpen = .TRUE. - BackPressure = 0.0 - GasKickPumpFlowRate = 0.0 + KickVARIABLES%NoGasPocket = 0 ! No Kick + KickVARIABLES%WellHeadOpen = .TRUE. + KickVARIABLES%WellHeadWasOpen = .TRUE. + FricPressDropVars%BackPressure = 0.0 + KickVARIABLES%GasKickPumpFlowRate = 0.0 DownHole%KickVolume = 0.0 DownHole%InfluxRate = 0.0 - ExitMass = 0.0 - MinAllowableKickVol = 1.0 * (42.0 / Convft3toUSgal) ! 1 bbl * 42 gal/bbl / 7.48 gal/ft^3 = ... ft^3 - StCompressedMudVol = 0.0 - AnnCompressedMudVol = 0.0 - KickFlux = .FALSE. - KickOffBottom = .FALSE. - KickWasExitingThroughChoke = .FALSE. - FloatValveOpen = .TRUE. + KickVARIABLES%ExitMass = 0.0 + KickVARIABLES%MinAllowableKickVol = 1.0 * (42.0 / Convft3toUSgal) ! 1 bbl * 42 gal/bbl / 7.48 gal/ft^3 = ... ft^3 + FricPressDropVars%StCompressedMudVol = 0.0 + FricPressDropVars%AnnCompressedMudVol = 0.0 + KickVARIABLES%KickFlux = .FALSE. + KickVARIABLES%KickOffBottom = .FALSE. + KickVARIABLES%KickWasExitingThroughChoke = .FALSE. + FricPressDropVars%FloatValveOpen = .TRUE. Choke%ChokeAreaFullyOpen = 123.0 / 64.0 ! fully open area is 123/64 in^2 = 0.01334635 ft^2 - ChokeBypassArea = PI / 4.0 * BopStackSpecification%ChokeLineId**2 - BHPSafetyMargin = 150.0 - AChBHPTol = 15.0 + FricPressDropVars%ChokeBypassArea = PI / 4.0 * BopStackSpecification%ChokeLineId**2 + FricPressDropVars%BHPSafetyMargin = 150.0 + FricPressDropVars%AChBHPTol = 15.0 - ManChoke1Plug = 0 - ManChoke2Plug = 0 - ManChoke1Washout = 0 - ManChoke2Washout = 0 - BitJetsPlugged = 0 - BitJetsWashedOut = 0 - CasingPressure_DataDisplayMalF = 0 + FricPressDropVars%ManChoke1Plug = 0 + FricPressDropVars%ManChoke2Plug = 0 + FricPressDropVars%ManChoke1Washout = 0 + FricPressDropVars%ManChoke2Washout = 0 + FricPressDropVars%BitJetsPlugged = 0 + FricPressDropVars%BitJetsWashedOut = 0 + FricPressDropVars%CasingPressure_DataDisplayMalF = 0 SoundSpeed = 1530.0 / Convfttom - PressureTimeStepDelay(1) = INT(2.0 * SUM(Configuration%StringConfiguration%StringConfigurations(2:)%ComponentLength) / SoundSpeed / dt) - PressureTimeStepDelay(2) = INT(PathGeneration%Items(SIZE(PathGeneration%Items))%MeasuredDepth / SoundSpeed / dt) - PressureTimeStepDelay(3) = INT(Shoe%ShoeDepth / SoundSpeed / dt) + PressureDisplayVARIABLES%PressureTimeStepDelay(1) = INT(2.0 * SUM(Configuration%StringConfiguration%StringConfigurations(2:)%ComponentLength) / SoundSpeed / dt) + PressureDisplayVARIABLES%PressureTimeStepDelay(2) = INT(PathGeneration%Items(SIZE(PathGeneration%Items))%MeasuredDepth / SoundSpeed / dt) + PressureDisplayVARIABLES%PressureTimeStepDelay(3) = INT(Shoe%ShoeDepth / SoundSpeed / dt) !WRITE (*,*) SUM(StringConfigurations(2:)%ComponentLength), PathGenerations(SIZE(PathGenerations))%TotalVerticalDepth!, WellSurveyData(SIZE(WellSurveyData))%TotalVerticalDepth !WRITE (*,*) PathGenerations(SIZE(PathGenerations))%MeasuredDepth!, WellSurveyData(SIZE(WellSurveyData))%MeasuredDepth - WRITE (*,*) 'time step delay', PressureTimeStepDelay + WRITE (*,*) 'time step delay', PressureDisplayVARIABLES%PressureTimeStepDelay - DO i = 1 , PressureTimeStepDelay(1) + DO i = 1 , PressureDisplayVARIABLES%PressureTimeStepDelay(1) CALL PumpPressureDelay%AddToFirst(0.0) END DO - DO i = 1 , PressureTimeStepDelay(2) + DO i = 1 , PressureDisplayVARIABLES%PressureTimeStepDelay(2) CALL BottomHolePressureDelay%AddToFirst(REAL(0.052 * MudProperties%ActiveDensity * PathGeneration%Items(SIZE(PathGeneration%Items))%TotalVerticalDepth)) END DO - DO i = 1 , PressureTimeStepDelay(3) + DO i = 1 , PressureDisplayVARIABLES%PressureTimeStepDelay(3) CALL ShoePressureDelay%AddToFirst(REAL(0.052 * MudProperties%ActiveDensity * Shoe%ShoeDepth)) END DO diff --git a/FluidFlow/Fluid_Flow_Solver.f90 b/FluidFlow/Fluid_Flow_Solver.f90 index 7a42dcd..db5a7a5 100644 --- a/FluidFlow/Fluid_Flow_Solver.f90 +++ b/FluidFlow/Fluid_Flow_Solver.f90 @@ -1,10 +1,10 @@ subroutine Fluid_Flow_Solver Use GeoElements_FluidModule - Use UTUBEVARS - USE KickVariables - USE PressureDisplayVARIABLES - USE FricPressDropVars + use UTUBEVARSModule + use KickVARIABLESModule + use PressureDisplayVARIABLESModule + USE FricPressDropVarsModule USE MudSystemVARIABLES USE Fluid_Flow_Startup_Vars USE CError @@ -36,13 +36,13 @@ subroutine Fluid_Flow_Solver CALL PressureAnnAndOHDistribution - IF (NoGasPocket > 0) THEN + IF (KickVARIABLES%NoGasPocket > 0) THEN !KickCorrectionVector(:) = 1. CALL GasKickCalculator END IF - IF (NoGasPocket == 0 .OR. NOT(WellHeadOpen)) EXIT - IF(MAXVAL(ABS(KickVandPFunction(:))) < KickConvergenceTolerance) EXIT + IF (KickVARIABLES%NoGasPocket == 0 .OR. NOT(KickVARIABLES%WellHeadOpen)) EXIT + IF(MAXVAL(ABS(KickVARIABLES%KickVandPFunction(:))) < KickConvergenceTolerance) EXIT !IF(MAXVAL(ABS(KickCorrectionVector(:))) < KickConvergenceTolerance) EXIT @@ -51,8 +51,8 @@ subroutine Fluid_Flow_Solver CALL PressureHorizAndStringDistribution IF (KickIteration == 41) THEN - WRITE (*,*) ' KickCorrectionVector ' , KickCorrectionVector - WRITE (*,*) ' Kick Jacobian = ', KickJacobian + WRITE (*,*) ' KickCorrectionVector ' , KickVARIABLES%KickCorrectionVector + WRITE (*,*) ' Kick Jacobian = ', KickVARIABLES%KickJacobian END IF end subroutine \ No newline at end of file diff --git a/FluidFlow/Frictional_Press_Drop_Calc.f90 b/FluidFlow/Frictional_Press_Drop_Calc.f90 index 87586e4..c1659e8 100644 --- a/FluidFlow/Frictional_Press_Drop_Calc.f90 +++ b/FluidFlow/Frictional_Press_Drop_Calc.f90 @@ -10,7 +10,7 @@ SUBROUTINE FricPressDrop(iloc) - USE FricPressDropVars + USE FricPressDropVarsModule USE CMudPropertiesVariables USE Fluid_Flow_Startup_Vars USE CError @@ -166,10 +166,10 @@ END SUBROUTINE FricPressDrop SUBROUTINE PartialDerivativeFricToFlowRate(iloc) - USE FricPressDropVars + USE FricPressDropVarsModule USE CMudPropertiesVariables USE Fluid_Flow_Startup_Vars - USE KickVariables + use KickVARIABLESModule USE CError diff --git a/FluidFlow/Horizontal_and_String_Pressure_Distribution.f90 b/FluidFlow/Horizontal_and_String_Pressure_Distribution.f90 index 7a83c9d..2bf6449 100644 --- a/FluidFlow/Horizontal_and_String_Pressure_Distribution.f90 +++ b/FluidFlow/Horizontal_and_String_Pressure_Distribution.f90 @@ -7,12 +7,12 @@ SUBROUTINE PressureHorizAndStringDistribution !! 1396/07/30 Sheikh Original code !! - USE FricPressDropVars - USE PressureDisplayVARIABLES + USE FricPressDropVarsModule + use PressureDisplayVARIABLESModule USE MudSystemVARIABLES USE GeoElements_FluidModule USE Fluid_Flow_Startup_Vars - USE KickVariables + use KickVARIABLESModule USE CMudPropertiesVariables USE CDataDisplayConsoleVariables !, StandPipePressureDataDisplay=> ChokeControlPanel%StandPipePressure USE CDataDisplayConsoleVariables !, CasingPressureDataDisplay=> CasingPressure @@ -23,7 +23,7 @@ SUBROUTINE PressureHorizAndStringDistribution USE CManifolds USE VARIABLES USE CError - USE UTUBEVARS + use UTUBEVARSModule USE CKellyConnectionEnumVariables USE Pumps_VARIABLES USE , INTRINSIC :: IEEE_ARITHMETIC @@ -44,62 +44,56 @@ SUBROUTINE PressureHorizAndStringDistribution REAL(8) :: ShoeTVD !REAL(8) , DIMENSION(5) :: MDObserve , TVDObserve , StPressObserve , AnnPressObserve , NomMD - ExitMass = 0.0 + KickVARIABLES%ExitMass = 0.0 BitPressLoss = 0.0 - WellHeadWasOpen = WellHeadOpen - WellToChokeManifoldWasOpen = MudSystem%WellToChokeManifoldOpen - KickWasExitingThroughChoke = .FALSE. + KickVARIABLES%WellHeadWasOpen = KickVARIABLES%WellHeadOpen + KickVARIABLES%WellToChokeManifoldWasOpen = MudSystem%WellToChokeManifoldOpen + KickVARIABLES%KickWasExitingThroughChoke = .FALSE. - IF (MudSystem%UtubeMode1Activated .OR. FloatValveWasOpen == .FALSE.) THEN ! Horizontal line flow rate - FlowEl(1 : NoHorizontalEl)%FlowRate = 0.0 + IF (MudSystem%UtubeMode1Activated .OR. FricPressDropVars%FloatValveWasOpen == .FALSE.) THEN ! Horizontal line flow rate + FlowEl(1 : FricPressDropVars%NoHorizontalEl)%FlowRate = 0.0 ELSE ! connection and line is open - FlowEl(1 : NoHorizontalEl)%FlowRate = MudSystem%StringFlowRate ! pump flow rate [gpm] + FlowEl(1 : FricPressDropVars%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) !IF (FloatValveIn == .FALSE.) FloatValveOpen = .TRUE. - FloatValveWasOpen = FloatValveOpen + FricPressDropVars%FloatValveWasOpen = FricPressDropVars%FloatValveOpen - PressBelowFloatValve = FlowEl(AnnulusFirstEl)%StartPress + PressBelowFloatValve = FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress - StMudVol = SUM(FlowEl(1 : StringLastEl)%Volume) * Convft3toUSGal - StDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * StMudVol) + FricPressDropVars%StMudVol = SUM(FlowEl(1 : FricPressDropVars%StringLastEl)%Volume) * Convft3toUSGal + FricPressDropVars%StDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * FricPressDropVars%StMudVol) - AnnMudVol = SUM(FlowEl(AnnulusFirstEl : NumbEl)%Volume) * Convft3toUSGal - !StCompressedMudVol = StCompressedMudVol + REAL(St_Saved_MudDischarged_Volume_Final) - !WRITE (*,*) 'St_Saved_MudDischarged_Volume_Final', REAL(St_Saved_MudDischarged_Volume_Final) - !StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol) - !PressAboveFloatValve = StDeltaPDueToCompressibility + SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) !!FlowEl(StringLastEl)%EndPress + FricPressDropVars%AnnMudVol = SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%NumbEl)%Volume) * Convft3toUSGal - !IF (NoGasPocket > 0) THEN ! mud exprience no comressibility - !IF (KickVolume > 2.0) THEN - IF ( (DownHole%KickVolume > 2.0) .or. (NoGasPocket>1) .or. (any(FlowEl(OpenholeFirstEl:NumbEl)%Materialtype==1)) .or. (ROP_bit%RateofPenetration > 0.0) ) THEN - AnnCompressedMudVol = 0.0 - AnnDeltaPDueToCompressibility = 0.0 + IF ( (DownHole%KickVolume > 2.0) .or. (KickVARIABLES%NoGasPocket>1) .or. (any(FlowEl(FricPressDropVars%OpenholeFirstEl:FricPressDropVars%NumbEl)%Materialtype==1)) .or. (ROP_bit%RateofPenetration > 0.0) ) THEN + FricPressDropVars%AnnCompressedMudVol = 0.0 + FricPressDropVars%AnnDeltaPDueToCompressibility = 0.0 - ELSE IF (WellHeadOpen) THEN - AnnDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * AnnMudVol) + ELSE IF (KickVARIABLES%WellHeadOpen) THEN + FricPressDropVars%AnnDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * FricPressDropVars%AnnMudVol) - AnnCompressedMudVol = BackPressure / AnnDeltaPtoDeltaVCompressibility - AnnDeltaPDueToCompressibility = AnnCompressedMudVol / (MudCompressibility * AnnMudVol) + FricPressDropVars%AnnCompressedMudVol = FricPressDropVars%BackPressure / FricPressDropVars%AnnDeltaPtoDeltaVCompressibility + FricPressDropVars%AnnDeltaPDueToCompressibility = FricPressDropVars%AnnCompressedMudVol / (MudCompressibility * FricPressDropVars%AnnMudVol) 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(MudSystem%Ann_Saved_MudDischarged_Volume_Final) !!!!!!!!! - AnnCompressedMudVol = MAX((AnnCompressedMudVol - REAL(MudSystem%Qlost / ConvMinToSec / dt)) , 0.0) - AnnDeltaPDueToCompressibility = AnnCompressedMudVol / (MudCompressibility * AnnMudVol) + FricPressDropVars%AnnDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * FricPressDropVars%AnnMudVol) + FricPressDropVars%AnnCompressedMudVol = FricPressDropVars%AnnCompressedMudVol + REAL(MudSystem%Ann_Saved_MudDischarged_Volume_Final) !!!!!!!!! + FricPressDropVars%AnnCompressedMudVol = MAX((FricPressDropVars%AnnCompressedMudVol - REAL(MudSystem%Qlost / ConvMinToSec / dt)) , 0.0) + FricPressDropVars%AnnDeltaPDueToCompressibility = FricPressDropVars%AnnCompressedMudVol / (MudCompressibility * FricPressDropVars%AnnMudVol) END IF - IF (FloatValveIn == .FALSE. .OR. NoGasPocket == 0 .OR. (FloatValveWasOpen .AND. REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol)) THEN ! float valve remains open - FloatValveOpen = .TRUE. + IF (FricPressDropVars%FloatValveIn == .FALSE. .OR. KickVARIABLES%NoGasPocket == 0 .OR. (FricPressDropVars%FloatValveWasOpen .AND. REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol)) THEN ! float valve remains open + FricPressDropVars%FloatValveOpen = .TRUE. - FlowEl(StringFirstEl : StringLastEl)%FlowRate = REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) / dt * ConvMinToSec !MudSystem%StringFlowRate ! String flow rate pump flow rate [gpm] + FlowEl(FricPressDropVars%StringFirstEl : FricPressDropVars%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 - DO ifric = 1 , StringLastEl + IF (KickVARIABLES%WellHeadOpen) THEN + DO ifric = 1 , FricPressDropVars%StringLastEl CALL FricPressDrop(ifric) !WRITE (*,*) ' element No, FlowRate , Density, FricPressLoss', ifric, FlowEl(ifric)%FlowRate, FlowEl(ifric)%Density, FlowEl(ifric)%FricPressLoss IF (IEEE_IS_NaN(FlowEl(ifric)%FricPressLoss)) THEN @@ -113,12 +107,12 @@ 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 + IF (FricPressDropVars%BitTotallyPluged) THEN MudSystem%MudVolume_InjectedToBH = 0.d0 - StCompressedMudVol = StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) - StDeltaPDueToCompressibility = StCompressedMudVol * StDeltaPtoDeltaVCompressibility + FricPressDropVars%StCompressedMudVol = FricPressDropVars%StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) + FricPressDropVars%StDeltaPDueToCompressibility = FricPressDropVars%StCompressedMudVol * FricPressDropVars%StDeltaPtoDeltaVCompressibility - ELSE IF (WellHeadOpen .OR. NoGasPocket > 0) THEN + ELSE IF (KickVARIABLES%WellHeadOpen .OR. KickVARIABLES%NoGasPocket > 0) THEN IF (REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN MudSystem%MudVolume_InjectedToBH = MudSystem%St_Saved_MudDischarged_Volume_Final @@ -126,76 +120,59 @@ SUBROUTINE PressureHorizAndStringDistribution !IF (BitTrue .AND. UtubeMode1Activated == .FALSE.) THEN IF (BitTrue) THEN - BitPressLoss = KBit * (MudSystem%MudVolume_InjectedToBH * ConvMinToSec / dt)**2 + BitPressLoss = FricPressDropVars%KBit * (MudSystem%MudVolume_InjectedToBH * ConvMinToSec / dt)**2 !WRITE (*,*) 'BitPressLoss', BitPressLoss END IF - StCompressedMudVol = BitPressLoss / StDeltaPtoDeltaVCompressibility + FricPressDropVars%StCompressedMudVol = BitPressLoss / FricPressDropVars%StDeltaPtoDeltaVCompressibility ELSE - MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((StDeltaPDueToCompressibility + SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff - PressBelowFloatValve - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & - / StDeltaPtoDeltaVCompressibility ) * 1.d0)) - MudSystem%MudVolume_InjectedToBH = MIN(MudSystem%MudVolume_InjectedToBH , StCompressedMudVol) - StCompressedMudVol = StCompressedMudVol - MudSystem%MudVolume_InjectedToBH + MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((FricPressDropVars%StDeltaPDueToCompressibility + SUM(FlowEl(FricPressDropVars%StringFirstEl : FricPressDropVars%StringLastEl)%StaticPressDiff - PressBelowFloatValve - FricPressDropVars%AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & + / FricPressDropVars%StDeltaPtoDeltaVCompressibility ) * 1.d0)) + MudSystem%MudVolume_InjectedToBH = MIN(MudSystem%MudVolume_InjectedToBH , FricPressDropVars%StCompressedMudVol) + FricPressDropVars%StCompressedMudVol = FricPressDropVars%StCompressedMudVol - MudSystem%MudVolume_InjectedToBH END IF - StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol) + FricPressDropVars%StDeltaPDueToCompressibility = FricPressDropVars%StCompressedMudVol / (MudCompressibility * FricPressDropVars%StMudVol) ELSE ! IF (NoGasPocket == 0 .AND. WellHeadOpen == .FALSE.) THEN - StCompressedMudVol = StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) - StDeltaPDueToCompressibility = StCompressedMudVol * StDeltaPtoDeltaVCompressibility - MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((StDeltaPDueToCompressibility - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & - / (StDeltaPtoDeltaVCompressibility + AnnDeltaPtoDeltaVCompressibility)) * 1.d0) - 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 + FricPressDropVars%StCompressedMudVol = FricPressDropVars%StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) + FricPressDropVars%StDeltaPDueToCompressibility = FricPressDropVars%StCompressedMudVol * FricPressDropVars%StDeltaPtoDeltaVCompressibility + MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((FricPressDropVars%StDeltaPDueToCompressibility - FricPressDropVars%AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & + / (FricPressDropVars%StDeltaPtoDeltaVCompressibility + FricPressDropVars%AnnDeltaPtoDeltaVCompressibility)) * 1.d0) + MudSystem%MudVolume_InjectedToBH = MIN(MudSystem%MudVolume_InjectedToBH , FricPressDropVars%StCompressedMudVol) + FricPressDropVars%StCompressedMudVol = FricPressDropVars%StCompressedMudVol - REAL(MudSystem%MudVolume_InjectedToBH) + FricPressDropVars%StDeltaPDueToCompressibility = FricPressDropVars%StCompressedMudVol / (MudCompressibility * FricPressDropVars%StMudVol) + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%NumbEl)%StartPress = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%NumbEl)%StartPress + FricPressDropVars%StDeltaPDueToCompressibility + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%NumbEl)%EndPress = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%NumbEl)%EndPress + FricPressDropVars%StDeltaPDueToCompressibility - !WRITE (*,*) 'WellHeadOpen', WellHeadOpen - !WRITE (*,*) ' StCompressedMudVol, StDeltaPDueToCompressibility',StCompressedMudVol, StDeltaPDueToCompressibility - !WRITE (*,*) ' AnnCompressedMudVol, AnnDeltaPDueToCompressibility',AnnCompressedMudVol, AnnDeltaPDueToCompressibility END IF - - - FlowEl(StringLastEl)%EndPress = FlowEl(AnnulusFirstEl)%StartPress + BitPressLoss + FloatValveMinOpenPressure + FlowEl(FricPressDropVars%StringLastEl)%EndPress = FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress + BitPressLoss + FloatValveMinOpenPressure !WRITE (*,*) 'BitPressLoss=', BitPressLoss - FlowEl(StringLastEl)%StartPress = FlowEl(StringLastEl)%EndPress + FlowEl(StringLastEl)%FricPressLoss - FlowEl(StringLastEl)%StaticPressDiff - DO i = StringLastEl - 1 , StringFirstEl , -1 + FlowEl(FricPressDropVars%StringLastEl)%StartPress = FlowEl(FricPressDropVars%StringLastEl)%EndPress + FlowEl(FricPressDropVars%StringLastEl)%FricPressLoss - FlowEl(FricPressDropVars%StringLastEl)%StaticPressDiff + DO i = FricPressDropVars%StringLastEl - 1 , FricPressDropVars%StringFirstEl , -1 FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss - FlowEl(i)%StaticPressDiff - !WRITE(*,*) "STRING: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress - !WRITE(*,*) "STRING: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX END DO - !FlowEl(NoHorizontalEl)%EndPress = FlowEl(StringFirstEl)%StartPress - FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD - !WRITE (*,*) '- FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD1=', - FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD - !FlowEl(NoHorizontalEl)%StartPress = FlowEl(NoHorizontalEl)%EndPress + FlowEl(StringLastEl)%FricPressLoss - !DO i = NoHorizontalEl - 1 , 1 , -1 - ! FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress - ! FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss - ! !WRITE(*,*) "HORIZONTAL: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress - ! !WRITE(*,*) "HORIZONTAL: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX - !END DO - !!!!!!!!!!!!!!!!!!!!!!!!!!!! Float valve was open and remains open ELSE IF (REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) < PumpMinDischargedVol) THEN ! NoGasPocket > 0 - FloatValveOpen = FloatValveWasOpen ! remains in its former status + FricPressDropVars%FloatValveOpen = FricPressDropVars%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) + IF (FricPressDropVars%FloatValveOpen) THEN + PressAboveFloatValve = MAX(FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress , SUM(FlowEl(FricPressDropVars%StringFirstEl : FricPressDropVars%StringLastEl)%StaticPressDiff) + 0.052 * FlowEl(FricPressDropVars%StringFirstEl)%Density * FlowEl(FricPressDropVars%StringFirstEl)%StartTVD) ELSE - PressAboveFloatValve = SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + StDeltaPDueToCompressibility + PressAboveFloatValve = SUM(FlowEl(FricPressDropVars%StringFirstEl : FricPressDropVars%StringLastEl)%StaticPressDiff) + FricPressDropVars%StDeltaPDueToCompressibility MudSystem%MudVolume_InjectedToBH = 0.d0 END IF - IF (PressBelowFloatValve >= PressAboveFloatValve .AND. KickFlux) THEN - FloatValveOpen = .FALSE. - IF (FloatValveOpen /= FloatValveWasOpen) THEN ! float valve was open and now closed + IF (PressBelowFloatValve >= PressAboveFloatValve .AND. KickVARIABLES%KickFlux) THEN + FricPressDropVars%FloatValveOpen = .FALSE. + IF (FricPressDropVars%FloatValveOpen /= FricPressDropVars%FloatValveWasOpen) THEN ! float valve was open and now closed WRITE (*,*) 'Float valve was open and now closed' WRITE (*,*) 'PressAboveFloatValve=', PressAboveFloatValve WRITE (*,*) 'PressBelowFloatValve=', PressBelowFloatValve @@ -203,76 +180,61 @@ SUBROUTINE PressureHorizAndStringDistribution END IF - IF (FloatValveOpen) THEN - MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , 0.1 * REAL((PressAboveFloatValve - PressBelowFloatValve - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & - / StDeltaPtoDeltaVCompressibility ) * 1.d0) - MudSystem%MudVolume_InjectedToBH = MIN(MudSystem%MudVolume_InjectedToBH , StCompressedMudVol) + IF (FricPressDropVars%FloatValveOpen) THEN + MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , 0.1 * REAL((PressAboveFloatValve - PressBelowFloatValve - FricPressDropVars%AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & + / FricPressDropVars%StDeltaPtoDeltaVCompressibility ) * 1.d0) + MudSystem%MudVolume_InjectedToBH = MIN(MudSystem%MudVolume_InjectedToBH , FricPressDropVars%StCompressedMudVol) !WRITE (*,*) 'MudVolume_InjectedToBH (No Pump)', MudVolume_InjectedToBH - StCompressedMudVol = StCompressedMudVol - MudSystem%MudVolume_InjectedToBH - StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol) + FricPressDropVars%StCompressedMudVol = FricPressDropVars%StCompressedMudVol - MudSystem%MudVolume_InjectedToBH + FricPressDropVars%StDeltaPDueToCompressibility = FricPressDropVars%StCompressedMudVol / (MudCompressibility * FricPressDropVars%StMudVol) !WRITE (*,*) 'StDeltaPDueToCompressibility(No Pump)', StDeltaPDueToCompressibility END IF - IF (NoGasPocket == 0 .AND. WellHeadOpen == .FALSE.) THEN !*********** - FlowEl(AnnulusFirstEl : NumbEl)%StartPress = FlowEl(AnnulusFirstEl : NumbEl)%StartPress + AnnDeltaPDueToCompressibility - FlowEl(AnnulusFirstEl : NumbEl)%EndPress = FlowEl(AnnulusFirstEl : NumbEl)%EndPress + AnnDeltaPDueToCompressibility + IF (KickVARIABLES%NoGasPocket == 0 .AND. KickVARIABLES%WellHeadOpen == .FALSE.) THEN !*********** + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%NumbEl)%StartPress = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%NumbEl)%StartPress + FricPressDropVars%AnnDeltaPDueToCompressibility + FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%NumbEl)%EndPress = FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%NumbEl)%EndPress + FricPressDropVars%AnnDeltaPDueToCompressibility END IF - IF (FloatValveOpen) THEN - FlowEl(StringLastEl)%EndPress = MAX(FlowEl(AnnulusFirstEl)%StartPress , SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + 0.052 * FlowEl(StringFirstEl)%Density * FlowEl(StringFirstEl)%StartTVD) + IF (FricPressDropVars%FloatValveOpen) THEN + FlowEl(FricPressDropVars%StringLastEl)%EndPress = MAX(FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress , SUM(FlowEl(FricPressDropVars%StringFirstEl : FricPressDropVars%StringLastEl)%StaticPressDiff) + 0.052 * FlowEl(FricPressDropVars%StringFirstEl)%Density * FlowEl(FricPressDropVars%StringFirstEl)%StartTVD) ELSE - FlowEl(StringLastEl)%EndPress = StDeltaPDueToCompressibility + SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + FlowEl(FricPressDropVars%StringLastEl)%EndPress = FricPressDropVars%StDeltaPDueToCompressibility + SUM(FlowEl(FricPressDropVars%StringFirstEl : FricPressDropVars%StringLastEl)%StaticPressDiff) END IF - FlowEl(StringLastEl)%StartPress = FlowEl(StringLastEl)%EndPress - FlowEl(StringLastEl)%StaticPressDiff - DO i = StringLastEl - 1 , StringFirstEl , -1 + FlowEl(FricPressDropVars%StringLastEl)%StartPress = FlowEl(FricPressDropVars%StringLastEl)%EndPress - FlowEl(FricPressDropVars%StringLastEl)%StaticPressDiff + DO i = FricPressDropVars%StringLastEl - 1 , FricPressDropVars%StringFirstEl , -1 FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss - FlowEl(i)%StaticPressDiff - !WRITE(*,*) "STRING: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress - !WRITE(*,*) "STRING: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX END DO - !FlowEl(NoHorizontalEl)%EndPress = FlowEl(StringFirstEl)%StartPress - FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD - !WRITE (*,*) '- FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD2=', - FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD - !FlowEl(NoHorizontalEl)%StartPress = FlowEl(NoHorizontalEl)%EndPress + FlowEl(StringLastEl)%FricPressLoss - !DO i = NoHorizontalEl - 1 , 1 , -1 - ! FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress - ! FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss - ! !WRITE(*,*) "HORIZONTAL: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress - ! !WRITE(*,*) "HORIZONTAL: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX - !END DO - !WRITE (*,*) ' StCompressedMudVol, StDeltaPDueToCompressibility',StCompressedMudVol, StDeltaPDueToCompressibility - !WRITE (*,*) ' AnnCompressedMudVol, AnnDeltaPDueToCompressibility',AnnCompressedMudVol, AnnDeltaPDueToCompressibility !!!!!!!!!!!!!!!!!!!!!!!!!!!! Float valve was open (close) and maybe remains open (close) or maybe closed - ELSE IF(FloatValveWasOpen == .FALSE. .AND. REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN - FloatValveOpen = .FALSE. + ELSE IF(FricPressDropVars%FloatValveWasOpen == .FALSE. .AND. REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN + FricPressDropVars%FloatValveOpen = .FALSE. MudSystem%MudVolume_InjectedToBH = 0.d0 - StCompressedMudVol = StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) - StDeltaPDueToCompressibility = StCompressedMudVol * StDeltaPtoDeltaVCompressibility - PressAboveFloatValve = SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + StDeltaPDueToCompressibility + FricPressDropVars%StCompressedMudVol = FricPressDropVars%StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) + FricPressDropVars%StDeltaPDueToCompressibility = FricPressDropVars%StCompressedMudVol * FricPressDropVars%StDeltaPtoDeltaVCompressibility + PressAboveFloatValve = SUM(FlowEl(FricPressDropVars%StringFirstEl : FricPressDropVars%StringLastEl)%StaticPressDiff) + FricPressDropVars%StDeltaPDueToCompressibility - - IF (PressAboveFloatValve > FloatValveBottomToUpAreaRatio * PressBelowFloatValve) THEN ! float valve was open and now closed - FloatValveOpen = .TRUE. + FricPressDropVars%FloatValveOpen = .TRUE. WRITE (*,*) 'Float valve was closed and now opened' WRITE (*,*) 'PressAboveFloatValve=', PressAboveFloatValve WRITE (*,*) 'PressBelowFloatValve=', PressBelowFloatValve END IF - FlowEl(StringLastEl)%EndPress = PressAboveFloatValve - FlowEl(StringLastEl)%StartPress = FlowEl(StringLastEl)%EndPress - FlowEl(StringLastEl)%StaticPressDiff - DO i = StringLastEl - 1 , StringFirstEl , -1 + FlowEl(FricPressDropVars%StringLastEl)%EndPress = PressAboveFloatValve + FlowEl(FricPressDropVars%StringLastEl)%StartPress = FlowEl(FricPressDropVars%StringLastEl)%EndPress - FlowEl(FricPressDropVars%StringLastEl)%StaticPressDiff + DO i = FricPressDropVars%StringLastEl - 1 , FricPressDropVars%StringFirstEl , -1 FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress FlowEl(i)%StartPress = FlowEl(i)%EndPress - FlowEl(i)%StaticPressDiff !WRITE(*,*) "STRING: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress @@ -285,33 +247,28 @@ SUBROUTINE PressureHorizAndStringDistribution END IF 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 - !WRITE (*,*) 'Density , StartX= , StartPress', FlowEl(NoHorizontalEl)%Density , FlowEl(StringFirstEl)%StartTVD - ELSE IF (WellHeadOpen) THEN - FlowEl(NoHorizontalEl)%EndPress = FlowEl(StringFirstEl)%StartPress - 2.0 * 0.052 * FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD + FlowEl(FricPressDropVars%NoHorizontalEl)%EndPress = 0.0 + ELSE IF (KickVARIABLES%WellHeadOpen == .FALSE.) THEN + FlowEl(FricPressDropVars%NoHorizontalEl)%EndPress = FlowEl(FricPressDropVars%StringFirstEl)%StartPress - 0.052 * FlowEl(FricPressDropVars%NoHorizontalEl)%Density * FlowEl(FricPressDropVars%StringFirstEl)%StartTVD + ELSE IF (KickVARIABLES%WellHeadOpen) THEN + FlowEl(FricPressDropVars%NoHorizontalEl)%EndPress = FlowEl(FricPressDropVars%StringFirstEl)%StartPress - 2.0 * 0.052 * FlowEl(FricPressDropVars%NoHorizontalEl)%Density * FlowEl(FricPressDropVars%StringFirstEl)%StartTVD END IF - FlowEl(NoHorizontalEl)%StartPress = FlowEl(NoHorizontalEl)%EndPress + FlowEl(NoHorizontalEl)%FricPressLoss - DO i = NoHorizontalEl - 1 , 1 , -1 + FlowEl(FricPressDropVars%NoHorizontalEl)%StartPress = FlowEl(FricPressDropVars%NoHorizontalEl)%EndPress + FlowEl(FricPressDropVars%NoHorizontalEl)%FricPressLoss + DO i = FricPressDropVars%NoHorizontalEl - 1 , 1 , -1 FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss - !WRITE(*,*) "HORIZONTAL: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress - !WRITE(*,*) "HORIZONTAL: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX END DO - !WRITE (*,*) 'MudVolume_InjectedToBH==', MudVolume_InjectedToBH - !WRITE (*,*) 'Ann_Saved_MudDischarged_Volume_Final==', Ann_Saved_MudDischarged_Volume_Final !!!!!!!!!!!!!!!!!!!!! Pressure distribution in string and horizontal pump to string line IF (RamLine%ShearBop_Situation_forTD == 1) THEN - FlowEl(1 : NoHorizontalEl)%EndPress = 0.0 - FlowEl(1 : NoHorizontalEl)%StartPress = 0.0 - FlowEl(1 : NoHorizontalEl)%FricPressLoss = 0.0 + FlowEl(1 : FricPressDropVars%NoHorizontalEl)%EndPress = 0.0 + FlowEl(1 : FricPressDropVars%NoHorizontalEl)%StartPress = 0.0 + FlowEl(1 : FricPressDropVars%NoHorizontalEl)%FricPressLoss = 0.0 END IF !!!!!!!!!!!!!!!!!!!!!!!!! @@ -321,65 +278,19 @@ SUBROUTINE PressureHorizAndStringDistribution - !IF (NoGasPocket == 0 .AND. WellHeadOpen) THEN - ! FlowEl(1 : NoHorizontalEl + NoStringEl)%EndPress = FlowEl(1 : NoHorizontalEl + NoStringEl)%EndPress + StDeltaPDueToCompressibility + AnnDeltaPDueToCompressibility - ! FlowEl(1 : NoHorizontalEl + NoStringEl)%StartPress = FlowEl(1 : NoHorizontalEl + NoStringEl)%StartPress + StDeltaPDueToCompressibility + AnnDeltaPDueToCompressibility - ! FlowEl(NoHorizontalEl + NoStringEl +1 : NumbEl)%EndPress = FlowEl(NoHorizontalEl + NoStringEl +1 : NumbEl)%EndPress + AnnDeltaPDueToCompressibility - ! FlowEl(NoHorizontalEl + NoStringEl + 1 : NumbEl)%StartPress = FlowEl(NoHorizontalEl + NoStringEl + 1 : NumbEl)%StartPress + AnnDeltaPDueToCompressibility - !ELSE - !IF (NoGasPocket == 0 .AND. WellHeadOpen == .FALSE.) THEN - ! FlowEl(1 : StringLastEl)%EndPress = FlowEl(1 : StringLastEl)%EndPress + StDeltaPDueToCompressibility + 30.0 ! badan eslah shavad - ! FlowEl(1 : StringLastEl)%StartPress = FlowEl(1 : NoHorizontalEl + NoStringEl)%StartPress + StDeltaPDueToCompressibility + 30.0 - ! FlowEl(AnnulusFirstEl : NumbEl)%EndPress = FlowEl(AnnulusFirstEl : NumbEl)%EndPress + AnnDeltaPDueToCompressibility - ! FlowEl(AnnulusFirstEl : NumbEl)%StartPress = FlowEl(AnnulusFirstEl : NumbEl)%StartPress + AnnDeltaPDueToCompressibility - !END IF - IF (MudSystem%UtubePossibility== .true. .and. Get_KellyConnection() /= KELLY_CONNECTION_STRING .and. WellHeadOpen) THEN + IF (MudSystem%UtubePossibility== .true. .and. Get_KellyConnection() /= KELLY_CONNECTION_STRING .and. KickVARIABLES%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) - ! !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 (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) - ! 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) - ! ! 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) - ! MudSystem%MudVolume_InjectedFromAnn = 0.d0 - ! END IF - !StCompressedMudVol = MAX(StCompressedMudVol - REAL(MudVolume_InjectedToBH) , 0.0) - !AnnCompressedMudVol = MAX(AnnCompressedMudVol - REAL(MudSystem%MudVolume_InjectedFromAnn) , 0.0) - !StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol) - !AnnDeltaPDueToCompressibility = AnnCompressedMudVol / (MudCompressibility * AnnMudVol) END IF - !MudVolume_InjectedToBH = 0.0 - !MudVolume_InjectedToBH = St_Saved_MudDischarged_Volume_Final - !WRITE (*,*) 'CompMudVol, DeltaP, MudVolumeInjected' - !WRITE (*,*) StCompressedMudVol, StDeltaPDueToCompressibility, REAL(MudVolume_InjectedToBH) - !WRITE (*,*) AnnCompressedMudVol, AnnDeltaPDueToCompressibility, REAL(MudSystem%MudVolume_InjectedFromAnn) - !WRITE (*,*) 'Press above/Below Float valve ', FlowEl(NoHorizontalEl + NoStringEl)%EndPress , FlowEl(NoHorizontalEl + NoStringEl + 1)%StartPress - !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) - !DO i = NumbEl , NumbEl - NoOpenHoleEl + 1 , -1 ! op elements - ! WRITE (*,*) 'el no, start, end' , i, FlowEl(i)%StartPress, FlowEl(i)%EndPress - !END DO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!! Kick Information Reports @@ -392,31 +303,31 @@ SUBROUTINE PressureHorizAndStringDistribution i = 1 DO WHILE (NOT(FlowEl(i)%EndX >= -170 .AND. FlowEl(i)%StartX <= -170)) i = i + 1 - IF (i > NoHorizontalEl) EXIT + IF (i > FricPressDropVars%NoHorizontalEl) EXIT END DO 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) + CALL PumpPressureDelay%Remove(PressureDisplayVARIABLES%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. - DO j = PressureTimeStepDelay(1) , 1 , -1 + DO j = PressureDisplayVARIABLES%PressureTimeStepDelay(1) , 1 , -1 IF (NOT(IEEE_IS_NaN(PumpPressureDelay%Array(j)))) THEN - PressureGauges(1) = INT(PumpPressureDelay%Array(j)) + PressureDisplayVARIABLES%PressureGauges(1) = INT(PumpPressureDelay%Array(j)) EXIT END IF END DO !PressureGauges(1) = INT(PumpPressureDelay%Array(PressureTimeStepDelay(1))) - IF (i > NoHorizontalEl) THEN + IF (i > FricPressDropVars%NoHorizontalEl) THEN WRITE (*,*) ' Error in calculating standpipe pressure ' END IF - IF (PressureGauges(1) < 0) THEN + IF (PressureDisplayVARIABLES%PressureGauges(1) < 0) THEN !CALL Set_StandPipePressure(real(PressureGauges(1) , 8)) ! for display console - PressureGauges(1) = 0.0 + PressureDisplayVARIABLES%PressureGauges(1) = 0.0 !CALL Set_StandPipePressure(0.0d0) !StandPipePressureGauge = 0 END IF - DownHole%DrillPipePressure = real(PressureGauges(1), 8) + DownHole%DrillPipePressure = real(PressureDisplayVARIABLES%PressureGauges(1), 8) !WRITE (*,*) 'Drillpipe Pressure', PressureGauges(1) !!!!!!!!!!!!!!!!! 2- Casing pressure gauge PressureGauge(2) @@ -428,21 +339,21 @@ SUBROUTINE PressureHorizAndStringDistribution !! but when pumps off due to failure, casing pressure will drop after a delay time 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) + CALL CasingPressureDelay%AddToFirst(FlowEl(FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl + FricPressDropVars%NoWellToChokeEl)%EndPress) + CALL CasingPressureDelay%Remove(PressureDisplayVARIABLES%PressureTimeStepDelay(1) + 1) - DO j = 1 , PressureTimeStepDelay(1) + DO j = 1 , PressureDisplayVARIABLES%PressureTimeStepDelay(1) IF (NOT(IEEE_IS_NaN(CasingPressureDelay%Array(j)))) THEN - PressureGauges(2) = INT(CasingPressureDelay%Array(j)) + PressureDisplayVARIABLES%PressureGauges(2) = INT(CasingPressureDelay%Array(j)) EXIT END IF END DO !PressureGauges(2) = INT(CasingPressureDelay%Array(1)) IF (ANY(PUMP(:)%PowerFailMalf == 1)) THEN - DO j = PressureTimeStepDelay(1) , 1 , -1 + DO j = PressureDisplayVARIABLES%PressureTimeStepDelay(1) , 1 , -1 IF (NOT(IEEE_IS_NaN(CasingPressureDelay%Array(j)))) THEN - PressureGauges(2) = INT(CasingPressureDelay%Array(j)) + PressureDisplayVARIABLES%PressureGauges(2) = INT(CasingPressureDelay%Array(j)) EXIT END IF END DO @@ -454,7 +365,7 @@ SUBROUTINE PressureHorizAndStringDistribution !IF (ANY(PUMP(:)%PowerFailMalf == 1)) PressureGauges(2) = INT(CasingPressureDelay%Array(PressureTimeStepDelay(1))) ELSE !IF (ChokeLineGaugeToTanks) THEN - PressureGauges(2) = 0 + PressureDisplayVARIABLES%PressureGauges(2) = 0 !WRITE (*,*) 'Here 2' END IF @@ -463,50 +374,43 @@ SUBROUTINE PressureHorizAndStringDistribution !IF (PressureGauges(2) < 0) THEN ! PressureGauges(2) = 0.0 !END IF - CALL Set_CasingPressure(real(PressureGauges(2) , 8)) ! for display console - Downhole%CasingPressure = real(PressureGauges(2) , 8) - !IF (PressureGauges(2) > 3000.0) THEN - ! !CALL Error(' High Casing Pressure') - !END IF - !WRITE (*,*) 'Casing Pressure=' , PressureGauges(2) - - + CALL Set_CasingPressure(real(PressureDisplayVARIABLES%PressureGauges(2) , 8)) ! for display console + Downhole%CasingPressure = real(PressureDisplayVARIABLES%PressureGauges(2) , 8) !!!!!!!!!!!!!!!!! 3- Bottom Hole Pressure PressureGauge(3) - CALL BottomHolePressureDelay%AddToFirst(FlowEl(OpenholeFirstEl)%StartPress) - CALL BottomHolePressureDelay%Remove(PressureTimeStepDelay(2) + 1) + CALL BottomHolePressureDelay%AddToFirst(FlowEl(FricPressDropVars%OpenholeFirstEl)%StartPress) + CALL BottomHolePressureDelay%Remove(PressureDisplayVARIABLES%PressureTimeStepDelay(2) + 1) !PressureGauges(3) = INT(BottomHolePressureDelay%Array(PressureTimeStepDelay(2))) - DO j = PressureTimeStepDelay(2) , 1 , -1 + DO j = PressureDisplayVARIABLES%PressureTimeStepDelay(2) , 1 , -1 IF (NOT(IEEE_IS_NaN(BottomHolePressureDelay%Array(j)))) THEN - PressureGauges(3) = INT(BottomHolePressureDelay%Array(j)) + PressureDisplayVARIABLES%PressureGauges(3) = INT(BottomHolePressureDelay%Array(j)) EXIT END IF END DO - BottomHolePress = BottomHolePressureDelay%Array(PressureTimeStepDelay(2)) + KickVARIABLES%BottomHolePress = BottomHolePressureDelay%Array(PressureDisplayVARIABLES%PressureTimeStepDelay(2)) - DownHole%BottomHolePressure = REAL(PressureGauges(3) , 8) + DownHole%BottomHolePressure = REAL(PressureDisplayVARIABLES%PressureGauges(3) , 8) !!!!!!!!!!!!!!!!! 4- Under Bit Pressure PressureGauges(4) - PressureGauges(4) = FlowEl(AnnulusFirstEl)%StartPress + PressureDisplayVARIABLES%PressureGauges(4) = FlowEl(FricPressDropVars%AnnulusFirstEl)%StartPress !!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!! 5- Casing Shoe Pressure PressureGauges(5) - - !IF (ShoeDepth <= FlowEl(NoHorizontalEl + NoStringEl + 1)%StartX) THEN - DO ShoeFlowElNo = AnnulusFirstEl , NumbEl + + DO ShoeFlowElNo = FricPressDropVars%AnnulusFirstEl , FricPressDropVars%NumbEl IF (FlowEl(ShoeFlowElNo)%StartX >= Shoe%ShoeDepth .AND. FlowEl(ShoeFlowElNo)%EndX < Shoe%ShoeDepth) EXIT END DO CALL TVD_Calculator(Shoe%ShoeDepth , ShoeTVD) - IF (ShoeFlowElNo > NumbEl) THEN + IF (ShoeFlowElNo > FricPressDropVars%NumbEl) THEN WRITE (*,*) 'ShoeDepth =', Shoe%ShoeDepth - DO i = AnnulusFirstEl , NumbEl + DO i = FricPressDropVars%AnnulusFirstEl , FricPressDropVars%NumbEl WRITE (*,*) 'i, StartX, EndX', i, FlowEl(i)%StartX, FlowEl(i)%EndX END DO @@ -520,30 +424,26 @@ SUBROUTINE PressureHorizAndStringDistribution CALL ShoePressureDelay%AddToFirst(REAL(FlowEl(ShoeFlowElNo)%StartPress & - (FlowEl(ShoeFlowElNo)%StartX - Shoe%ShoeDepth) * FlowEl(ShoeFlowElNo)%dPdLfric & - (FlowEl(ShoeFlowElNo)%StartTVD - ShoeTVD) * FlowEl(ShoeFlowElNo)%dPdLGrav)) - CALL ShoePressureDelay%Remove(PressureTimeStepDelay(3) + 1) + CALL ShoePressureDelay%Remove(PressureDisplayVARIABLES%PressureTimeStepDelay(3) + 1) - !FlowrateNearShoe = FlowEl(ShoeFlowElNo)%FlowRate - DO j = PressureTimeStepDelay(3) , 1 , -1 + !FricPressDropVars%FlowrateNearShoe = FlowEl(ShoeFlowElNo)%FlowRate + DO j = PressureDisplayVARIABLES%PressureTimeStepDelay(3) , 1 , -1 IF (NOT(IEEE_IS_NaN(ShoePressureDelay%Array(j)))) THEN - PressureGauges(5) = INT(ShoePressureDelay%Array(j)) + PressureDisplayVARIABLES%PressureGauges(5) = INT(ShoePressureDelay%Array(j)) EXIT END IF END DO !PressureGauges(5) = INT(ShoePressureDelay%Array(PressureTimeStepDelay(3))) - DownHole%ShoePressure = real(PressureGauges(5), 8) + DownHole%ShoePressure = real(PressureDisplayVARIABLES%PressureGauges(5), 8) - !IF (PressureGauges(5) >= FormationLostPressure) WRITE (*,*) 'Near Shoe Flowrate', FlowEl(ShoeFlowElNo)%FlowRate MudSystem%ShoeMudViscosity = FlowEl(ShoeFlowElNo)%MuEff MudSystem%ShoeMudDensity = FlowEl(ShoeFlowElNo)%Density - !WRITE (*,*) 'Drillstring speed (ft/s)' , DrillStringSpeed - !WRITE (*,*) 'shoe mud speed ', FlowEl(ShoeFlowElNo - 1)%vel - !WRITE (*,*) 'Shoe pressure (psi)', ShoePressureDelay%Array(1) @@ -552,90 +452,49 @@ SUBROUTINE PressureHorizAndStringDistribution !!!!!!!!! 6- Pressure Before Bop - PressureGauges(6) = FlowEl(NoHorizontalEl + NoStringEl + NoAnnulusEl)%EndPress + PressureDisplayVARIABLES%PressureGauges(6) = FlowEl(FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl)%EndPress !!!!!!!!!!!!!!!!! 101 FORMAT(4X, I2, 8X, (F8.1), 12X, (F8.3), 7X, (F8.2)) - !WRITE (*,*) ' Pump Pressure Delay', PumpPressureDelay%Array(1) - !WRITE (*,*) ' Bottom Hole Pressure Delay', BottomHolePressureDelay%Array(1) - !WRITE (*,*) ' Shoe Pressure Delay', ShoePressureDelay%Array(1) - - !IF (ALLOCATED(GasPocketWeight%Array) .AND. ChokeKroneckerDelta == 1) THEN - !WRITE (*,*) 'Pocket No , Gas Pocket (psia) , Volume (gal) , Flow Induced (gpm) ' - - !DO i = 1 , NoGasPocket - ! WRITE (*,101) i, GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * ConvFt3toUSGal, GasPocketFlowInduced%Array(i) - !END DO - ! WRITE (*,*) 'Kchoke =', Kchoke, FlowEl(OpenholeFirstEl - 1)%FlowRate - - !DO i = 1 , NoGasPocket - ! WRITE (*,*) 'Gas Kick Vol (gal)=' , GasPocketNewVol%Array(i) * ConvFt3toUSGal , GasPocketDeltaVol%Array(i) * ConvFt3toUSGal , GasPocketNewPress%Array(i) - !END DO - !WRITE (*,*) 'BHP (psig)=', BottomHolePress - - IF (ChokeKroneckerDelta == 1) THEN - !WRITE (*,*) 'Casing Pressure' , PressureGauges(2) - !WRITE (*,*) 'Below Bit' , FlowEl(AnnulusFirstEl)%StartPress - !WRITE (*,*) 'Above Bit' , FlowEl(StringLastEl)%EndPress - !WRITE (*,*) 'Pump Pressure' , PressureGauges(1) - - - - !WRITE (*,*) ' Kick Iteration', KickIteration - !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 - !write(*,*) 'BackPressure=' , BackPressure - - !WRITE (*,*) ' Kick Jacobian ', REAL(KickJacobian) - !WRITE (*,*) ' KickVandPFunction = ' , REAL(-KickVandPFunction) - !WRITE (*,*) ' Kick Unknown Vector = ' , REAL(KickUnknownVector) - !WRITE (*,*) 'SUM(StaticPressDiff) , SUM(FricPressLoss)', SUM(FlowEl(GasPocketElementNo(1) : i)%FricPressLoss) , SUM(FlowEl(GasPocketElementNo(1) : i)%StaticPressDiff) - !WRITE (*,*) 'Drillpipe, casing pressure', PressureGauges(1), PressureGauges(2) + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN END IF - !IF (NoWelltoChokeEl > 0 .AND. FlowEl(OpenholeFirstEl - 1)%MaterialType == 1 .AND. WellHeadOpen) THEN ! kick is last element in choke line and does not exit. - ! KickWasExitingThroughChoke = .TRUE. - ! GasPocketDensity%Array(NoGasPocket) = (GasPocketweight%Array(NoGasPocket) / GasPocketModifiedVol%Array(NoGasPocket)) / convft3toUSgal ! [lbm/ft^3 to ppg] - ! ExitMass = (1.0 - (GasPocketModifiedVol%Array(NoGasPocket) / GasPocketNewVol%Array(NoGasPocket))) * GasPocketWeight%Array(NoGasPocket) ! exit mass due to expand - ! WRITE (*,*) ' ExitMass due to expand = ', GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal , ExitMass - !END IF + !WRITE (*,*) 'Horiz 1' - KickInFluxConditions = (Reservoir%FormationTop < TD_WellGeneral%WellTotalVerticalLength) .AND. (NOT(Reservoir%InactiveInflux)) .AND. (FormPressure > BottomHolePress + 5.0) - IF (KickInFluxConditions) THEN - KickFlux = .TRUE. + KickVARIABLES%KickInFluxConditions = (Reservoir%FormationTop < TD_WellGeneral%WellTotalVerticalLength) .AND. (NOT(Reservoir%InactiveInflux)) .AND. (KickVARIABLES%FormPressure > KickVARIABLES%BottomHolePress + 5.0) + IF (KickVARIABLES%KickInFluxConditions) THEN + KickVARIABLES%KickFlux = .TRUE. CALL NewGasKick !WRITE (*,*) 'Kick Flux top' , KickFlux - !WRITE (*,*) 'FormPressure, BottomHolePress, FormationTop, TD_WellGeneral%WellTotalVerticalLength' , FormPressure, BottomHolePress, FormationTop, TD_WellGeneral%WellTotalVerticalLength + !WRITE (*,*) 'KickVARIABLES%FormPressure, BottomHolePress, FormationTop, TD_WellGeneral%WellTotalVerticalLength' , FormPressure, BottomHolePress, FormationTop, TD_WellGeneral%WellTotalVerticalLength ELSE - IF (ALLOCATED(GasPocketWeight%Array) .AND. KickFlux) THEN - KickOffBottom = .TRUE. + IF (ALLOCATED(GasPocketWeight%Array) .AND. KickVARIABLES%KickFlux) THEN + KickVARIABLES%KickOffBottom = .TRUE. WRITE (*,*) 'Kick Off Bottom' - WRITE (*,*) 'FormPressure , BottomHolePress' , FormPressure , BottomHolePress + WRITE (*,*) 'FormPressure , BottomHolePress' , KickVARIABLES%FormPressure , KickVARIABLES%BottomHolePress !WRITE (*,*) 'No Press(psia) Vol(gal) Weight(lbm) Flow Induced(gpm) Flow El Press(psia)' - DO i = 1 , NoGasPocket - WRITE (*,102) i , GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * Convft3toUSgal, GasPocketWeight%Array(i), GasPocketFlowInduced%Array(i), FlowEl(GasPocketFlowEl(i , 1))%StartPress + StandardPress + DO i = 1 , KickVARIABLES%NoGasPocket + WRITE (*,102) i , GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * Convft3toUSgal, GasPocketWeight%Array(i), GasPocketFlowInduced%Array(i), FlowEl(KickVARIABLES%GasPocketFlowEl(i , 1))%StartPress + StandardPress END DO END IF - KickFlux = .FALSE. + KickVARIABLES%KickFlux = .FALSE. END IF - IF (ALLOCATED(KickJacobian)) OldKickJacobian = KickJacobian + IF (ALLOCATED(KickVARIABLES%KickJacobian)) KickVARIABLES%OldKickJacobian = KickVARIABLES%KickJacobian 102 FORMAT (I2, 3X, (F8.1), 2X, (F8.2), 2X, (F8.3), 8X, (F8.2), 10X, (F8.1)) !!!!!!!! Auto Choke Procedure ! DO i = 1 , 5 - ! AreaChange = -1.0 * (BottomHolePressure - (FormPressure + BHPSafetyMargin)) / FlowEl(OpenholeFirstEl - 1)%Flowrare**2 * 89158.0 & - ! * (0.26 * 0.61)**2 * TotalOpenChokeArea**3 / (4.0 * ChokeDensity) + ! AreaChange = -1.0 * (BottomHolePressure - (KickVARIABLES%FormPressure + BHPSafetyMargin)) / FlowEl(OpenholeFirstEl - 1)%Flowrare**2 * 89158.0 & + ! * (0.26 * 0.61)**2 * TotalOpenChokeArea**3 / (4.0 * KickVARIABLES%ChokeDensity) ! CHOOKE(1)%AreaChokeFinal = CHOOKE(1)%AreaChokeFinal + AreaChange / * Convfttoinch**2 ! ! @@ -648,30 +507,30 @@ SUBROUTINE PressureHorizAndStringDistribution ! - !WRITE (*,*) ' SecondaryKickWeight', SecondaryKickWeight - !WRITE (*,*) ' SecondaryKickVol', SecondaryKickVol - DownHole%SecondKickVolume = SecondaryKickVol + !WRITE (*,*) ' SecondaryKickWeight', KickVARIABLES%SecondaryKickWeight + !WRITE (*,*) ' SecondaryKickVol', KickVARIABLES%SecondaryKickVol + DownHole%SecondKickVolume = KickVARIABLES%SecondaryKickVol - IF (WellHeadOpen == .FALSE. .OR. (FlowEl(OpenholeFirstEl - 1)%Flowrate < PressFlowrateTolerance .AND. FlowEl(AnnulusLastEl)%Flowrate < PressFlowrateTolerance)) THEN - OnShakerDensity = 0.0 - ELSE IF (FlowEl(OpenholeFirstEl - 1)%MaterialType == 1 .AND. ChokeKroneckerDelta == 1) THEN - OnShakerDensity = 2.0 - ELSE IF (ChokeKroneckerDelta == 0) THEN - OnShakerDensity = FlowEl(AnnulusLastEl)%Density - ELSE IF (ChokeKroneckerDelta == 1) THEN !!!(FlowEl(OpenholeFirstEl - 1)%Flowrate > PressFlowrateTolerance .AND. FlowEl(AnnulusLastEl)%Flowrate < PressFlowrateTolerance) THEN - OnShakerDensity = FlowEl(OpenholeFirstEl - 1)%Density + IF (KickVARIABLES%WellHeadOpen == .FALSE. .OR. (FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%Flowrate < PressFlowrateTolerance .AND. FlowEl(FricPressDropVars%AnnulusLastEl)%Flowrate < PressFlowrateTolerance)) THEN + FricPressDropVars%OnShakerDensity = 0.0 + ELSE IF (FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%MaterialType == 1 .AND. KickVARIABLES%ChokeKroneckerDelta == 1) THEN + FricPressDropVars%OnShakerDensity = 2.0 + ELSE IF (KickVARIABLES%ChokeKroneckerDelta == 0) THEN + FricPressDropVars%OnShakerDensity = FlowEl(FricPressDropVars%AnnulusLastEl)%Density + ELSE IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN !!!(FlowEl(OpenholeFirstEl - 1)%Flowrate > PressFlowrateTolerance .AND. FlowEl(AnnulusLastEl)%Flowrate < PressFlowrateTolerance) THEN + FricPressDropVars%OnShakerDensity = FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%Density ELSE - OnShakerDensity = (FlowEl(OpenholeFirstEl - 1)%Density * FlowEl(OpenholeFirstEl - 1)%Flowrate & - + FlowEl(AnnulusLastEl)%Density * FlowEl(AnnulusLastEl)%Flowrate) / (FlowEl(OpenholeFirstEl - 1)%Flowrate + FlowEl(AnnulusLastEl)%Flowrate) + FricPressDropVars%OnShakerDensity = (FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%Density * FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%Flowrate & + + FlowEl(FricPressDropVars%AnnulusLastEl)%Density * FlowEl(FricPressDropVars%AnnulusLastEl)%Flowrate) / (FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%Flowrate + FlowEl(FricPressDropVars%AnnulusLastEl)%Flowrate) END IF !WRITE (*,*) 'ANINT(OnShakerDensity * 100) / 100', ANINT(OnShakerDensity * 100) / 100 , OnShakerDensity - CALL Set_MudWeightOut(ANINT(OnShakerDensity * 100) / 100) + CALL Set_MudWeightOut(ANINT(FricPressDropVars%OnShakerDensity * 100) / 100) IF (ALLOCATED(FinalFlowEl)) DEALLOCATE(FinalFlowEl) - ALLOCATE(FinalFlowEl(NumbEl)) + ALLOCATE(FinalFlowEl(FricPressDropVars%NumbEl)) FinalFlowEl(:)%StartX = FlowEl(:)%StartX FinalFlowEl(:)%EndX = FlowEl(:)%EndX @@ -685,44 +544,6 @@ SUBROUTINE PressureHorizAndStringDistribution FinalFlowEl(:)%dPdLFric = FlowEl(:)%dPdLFric FinalFlowEl(:)%dPdLGrav = FlowEl(:)%dPdLGrav - !WRITE (*,*) 'FlowRate=', FlowEl(AnnulusFirstEl)%FlowRate - !WRITE (*,*) 'Pressure Loss in Drill String', SUM(FlowEl(StringFirstEl : StringLastEl)%FricPressLoss) - !WRITE (*,*) 'Pressure Loss in Annulus', SUM(FlowEl(AnnulusFirstEl : AnnulusLastEl)%FricPressLoss) - !MDObserve(:) = [3000.0 , 4349.0 , 11880.0 , 19880.0 , 21680.0] - !NomMd (:) = [3000 , 4298 , 11690 , 19690 , 21490] - !DO i = 1 , 5 - ! CALL TVD_Calculator(MDObserve(i) , TVDObserve(i)) - !END DO - ! - !DO i = 1 , 5 - ! - ! WRITE (*,*) 'MDObserve(i)', INT(NomMD(i)) - ! WRITE (*,*) 'TVDObserve(i)', INT(TVDObserve(i)) - ! - ! DO j = StringFirstEl , StringLastEl - ! IF (INT(MDObserve(i)) < INT(FinalFlowEl(j)%EndX)) EXIT - ! END DO - ! StPressObserve(i) = FlowEl(j)%StartPress - (MDObserve(i) - FlowEl(j)%StartX) * FlowEl(j)%dPdLfric + (TVDObserve(i) - FlowEl(j)%StartTVD) * FlowEl(j)%dPdLGrav - ! WRITE (*,*) 'String Pressure', INT(StPressObserve(i)) - ! - ! - ! - ! IF (INT(MDObserve(i)) <= INT(FlowEl(AnnulusFirstEl)%StartX)) THEN !! mouse pointer is in the annulus space - ! DO j = AnnulusFirstEl , AnnulusLastEl - ! IF (INT(FlowEl(j)%EndX) <= INT(MDObserve(i))) EXIT - ! END DO - ! ELSE IF (INT(MDObserve(i)) > INT(FinalFlowEl(NumbEl)%EndX)) THEN ! mouse pointer is in the open hole space - ! DO j = OpenholeFirstEl , NumbEl - ! IF (INT(FinalFlowEl(j)%EndX) <= INT(MDObserve(i))) EXIT - ! END DO - ! END IF - ! AnnPressObserve(i) = FlowEl(j)%StartPress - (FlowEl(j)%StartX - MDObserve(i)) * FlowEl(j)%dPdLfric & - ! - (FlowEl(j)%StartTVD - TVDObserve(i)) * FlowEl(j)%dPdLGrav - ! WRITE (*,*) 'Annulus Pressure', INT(AnnPressObserve(i)) - ! - ! - !END DO - @@ -736,7 +557,7 @@ SUBROUTINE SOLVE_LINEAR_EQUATIONS(A , x , b , error, dim) !! if vaiable erorr changed its value to .FALSE. means that the system of equations cab not be solved !! I use this subroutine to solve the linearized equations which uprising in calculation of volume and pressure of gas kick pockets - USE KickVARIABLES + use KickVARIABLESModule IMPLICIT NONE INTEGER , INTENT(IN) :: dim diff --git a/FluidFlow/Pressure_Display_VARIABLES.f90 b/FluidFlow/Pressure_Display_VARIABLES.f90 index dc7e9ce..a31bc24 100644 --- a/FluidFlow/Pressure_Display_VARIABLES.f90 +++ b/FluidFlow/Pressure_Display_VARIABLES.f90 @@ -1,20 +1,24 @@ -MODULE PressureDisplayVARIABLES +module PressureDisplayVARIABLESModule USE DynamicRealArray IMPLICIT NONE - - INTEGER :: NoGauges - REAL , DIMENSION(6) :: PressureGauges + TYPE PressureDisplayVARIABLESTYPE + INTEGER :: NoGauges + REAL , DIMENSION(6) :: PressureGauges + INTEGER , DIMENSION(3) :: PressureTimeStepDelay + END TYPE PressureDisplayVARIABLESTYPE + + TYPE(PressureDisplayVARIABLESTYPE) :: PressureDisplayVARIABLES + INTEGER :: SoundSpeed ! speed of sound [ft/s] - INTEGER , DIMENSION(3) :: PressureTimeStepDelay + TYPE(DynamicRealArrayType) :: PumpPressureDelay TYPE(DynamicRealArrayType) :: CasingPressureDelay TYPE(DynamicRealArrayType) :: BottomHolePressureDelay TYPE(DynamicRealArrayType) :: ShoePressureDelay - - + TYPE :: ObservationAndGaugePointsInformations ! We have some gauges and may be have many observation points like casing shoe, bottomhole , etc. ! This module stores information of these points to calculate pressure, density and other desired properties diff --git a/FluidFlow/Pressure_Distribution_VARIABLES.f90 b/FluidFlow/Pressure_Distribution_VARIABLES.f90 index 5cd2042..33ffead 100644 --- a/FluidFlow/Pressure_Distribution_VARIABLES.f90 +++ b/FluidFlow/Pressure_Distribution_VARIABLES.f90 @@ -1,6 +1,4 @@ -MODULE FricPressDropVars - - +MODULE FricPressDropVarsModule !! Record of revisions !! Date Programmer Discription of change !! ------ ------------ ----------------------- @@ -9,64 +7,69 @@ MODULE FricPressDropVars IMPLICIT NONE + TYPE :: FricPressDropVarsTYPE + + REAL :: TotFricPressLoss ! Total Frictional Pressure Loss [psi] + REAL :: FlowrateNearShoe + INTEGER :: NoHorizontalEl ! number of elements in horizontal pump to string line + INTEGER :: NoStringEl ! number of elements in string + INTEGER :: NoAnnulusEl ! number of elements in annulus space + INTEGER :: NoWellToChokeEl ! number of elements in well head to choke manifold + INTEGER :: NoOpenHoleEl ! number of elements in openhole + INTEGER :: NumbEl ! number of flow elements in horizontal line, string, annulus and openhole + INTEGER :: StringFirstEl ! number of first string element + INTEGER :: StringLastEl ! number of last string element + INTEGER :: AnnulusFirstEl ! number of first annulus element + INTEGER :: AnnulusLastEl ! number of last annulus element + INTEGER :: ChokeFirstEl ! number of first choke element + INTEGER :: ChokeLastEl ! number of last choke element + INTEGER :: OpenholeFirstEl ! number of first openhole element + REAL :: KBOP ! DeltaPBOP = KBOP * Q**2 [psi * min^2 / gal^2] + REAL :: KBit ! DeltaPBit = KBit * Q**2 [psi * min^2 / gal^2] + + !!!! Choke Variables + REAL :: BackPressure , NewBackPressure ! back pressure at riser or choke line [psi] + REAL :: Kchoke ! DeltaPchoke = Kchoke * Q**2 [psi * min^2 / gal^2] + REAL :: TotalOpenChokeArea , OldTotalOpenChokeArea , ChokeBypassArea , NewTotalOpenChokeArea , AreaChange + REAL :: BHPSafetyMargin , AChBHPTol ! BHP safety margin and BHP Tolerance in Auto Choke mode [psi] + REAL(8) :: OnShakerDensity ! Outlet Density of well for displaying in drillwatch and data [ppg] + + LOGICAL :: FloatValveIn + LOGICAL :: FloatValveOpen , FloatValveWasOpen + LOGICAL :: BitTotallyPluged + + REAL :: StMudVol ! Total mud volume of Horizontal and String that may be compressed [gal] + REAL :: AnnMudVol ! Total mud volume of Bottom hole, Annulus and Choke line that may be compressed [gal] + REAL :: PumpToManifoldMudVol + REAL :: StCompressedMudVol ! Compressed mud volume in Horizontal and String [gal] + REAL :: AnnCompressedMudVol ! Compressed mud volume in Bottom hole, Annulus and Choke line [gal] + REAL :: PumpToManifoldCompressedMudVol + REAL :: StDeltaPDueToCompressibility ! Pressure increase due to mud compressibility in Horizontal and String [psi] + REAL :: AnnDeltaPDueToCompressibility ! Pressure increase due to mud compressibility in Bottom hole, Annulus and Choke line [psi] (usually when wellhead is closed) + REAL :: PumpToManifoldDeltaPDueToCompressibility + REAL :: StDeltaPtoDeltaVCompressibility ! string pressure change due to compressibility [psi/gal] + REAL :: AnnDeltaPtoDeltaVCompressibility ! annulus and openhole pressure change due to compressibility [psi/gal] + + + !!!! Problem Variables (Choke and Bit) + + INTEGER :: ManChoke1Plug , ManChoke2Plug ! = 1 if choke is plugged , = 0 else + INTEGER :: ManChoke1Washout , ManChoke2Washout ! = 1 if choke is washed out , = 0 else + INTEGER :: BitJetsPlugged , BitJetsWashedOut + INTEGER :: CasingPressure_DataDisplayMalF, CasingPressure_ChokeMalF + + !!!!!! Note that bit is not an element in these calculations + END TYPE FricPressDropVarsTYPE - - REAL :: TotFricPressLoss ! Total Frictional Pressure Loss [psi] - REAL :: FlowrateNearShoe - INTEGER :: NoHorizontalEl ! number of elements in horizontal pump to string line - INTEGER :: NoStringEl ! number of elements in string - INTEGER :: NoAnnulusEl ! number of elements in annulus space - INTEGER :: NoWellToChokeEl ! number of elements in well head to choke manifold - INTEGER :: NoOpenHoleEl ! number of elements in openhole - INTEGER :: NumbEl ! number of flow elements in horizontal line, string, annulus and openhole - INTEGER :: StringFirstEl ! number of first string element - INTEGER :: StringLastEl ! number of last string element - INTEGER :: AnnulusFirstEl ! number of first annulus element - INTEGER :: AnnulusLastEl ! number of last annulus element - INTEGER :: ChokeFirstEl ! number of first choke element - INTEGER :: ChokeLastEl ! number of last choke element - INTEGER :: OpenholeFirstEl ! number of first openhole element + TYPE(FricPressDropVarsTYPE) :: FricPressDropVars + INTEGER :: ShoeFlowElNo ! the flow element that starts from shoe, in other word the number of upper element adjacent to shoe - REAL :: KBOP ! DeltaPBOP = KBOP * Q**2 [psi * min^2 / gal^2] - REAL :: KBit ! DeltaPBit = KBit * Q**2 [psi * min^2 / gal^2] - - !!!! Choke Variables - REAL :: BackPressure , NewBackPressure ! back pressure at riser or choke line [psi] - REAL :: Kchoke ! DeltaPchoke = Kchoke * Q**2 [psi * min^2 / gal^2] - REAL :: TotalOpenChokeArea , OldTotalOpenChokeArea , ChokeBypassArea , NewTotalOpenChokeArea , AreaChange - REAL :: BHPSafetyMargin , AChBHPTol ! BHP safety margin and BHP Tolerance in Auto Choke mode [psi] - REAL(8) :: OnShakerDensity ! Outlet Density of well for displaying in drillwatch and data [ppg] - - LOGICAL :: FloatValveIn - LOGICAL :: FloatValveOpen , FloatValveWasOpen - LOGICAL :: BitTotallyPluged REAL :: ClingingFactor = 0.45 ! in calculating surge and swab pressure changes REAL :: MudCompressibility = 2.7E-6 ! Volumne change relative to Volume/1psi, for example for change of 1000 psi in pressure, volume changes 0.27% [1/psi] REAL :: FloatValveMinOpenPressure = 1.0 ! minimum pressure that opens the float valve [psi] - REAL :: StMudVol ! Total mud volume of Horizontal and String that may be compressed [gal] - REAL :: AnnMudVol ! Total mud volume of Bottom hole, Annulus and Choke line that may be compressed [gal] - REAL :: PumpToManifoldMudVol - REAL :: StCompressedMudVol ! Compressed mud volume in Horizontal and String [gal] - REAL :: AnnCompressedMudVol ! Compressed mud volume in Bottom hole, Annulus and Choke line [gal] - REAL :: PumpToManifoldCompressedMudVol - REAL :: StDeltaPDueToCompressibility ! Pressure increase due to mud compressibility in Horizontal and String [psi] - REAL :: AnnDeltaPDueToCompressibility ! Pressure increase due to mud compressibility in Bottom hole, Annulus and Choke line [psi] (usually when wellhead is closed) - REAL :: PumpToManifoldDeltaPDueToCompressibility - REAL :: StDeltaPtoDeltaVCompressibility ! string pressure change due to compressibility [psi/gal] - REAL :: AnnDeltaPtoDeltaVCompressibility ! annulus and openhole pressure change due to compressibility [psi/gal] - - - !!!! Problem Variables (Choke and Bit) - - INTEGER :: ManChoke1Plug , ManChoke2Plug ! = 1 if choke is plugged , = 0 else - INTEGER :: ManChoke1Washout , ManChoke2Washout ! = 1 if choke is washed out , = 0 else - INTEGER :: BitJetsPlugged , BitJetsWashedOut - INTEGER :: CasingPressure_DataDisplayMalF, CasingPressure_ChokeMalF - !!!!!! Note that bit is not an element in these calculations - - + TYPE, PUBLIC :: PressDropCalcElemInfo !! Geometrical variables @@ -110,9 +113,7 @@ MODULE FricPressDropVars END TYPE PressDropCalcElemInfo TYPE (PressDropCalcElemInfo) , ALLOCATABLE :: FlowEl(:) ! FlowEl: Pressure Drop Calculation Elements The dimension is equal to the number of flow elements - - - + TYPE, PUBLIC :: FinalPressDropCalcElemInfo @@ -132,22 +133,27 @@ MODULE FricPressDropVars - END MODULE FricPressDropVars +END MODULE FricPressDropVarsModule + +MODULE UTUBEVARSModule + + TYPE :: UTUBEVARSTYPE - MODULE UTUBEVARS + REAL :: QUTubeInput ! flow rate from string to annulus which caused by head difference at two sides of U-tube [gpm] + REAL :: QUtubeOutput ! flow rate from annulus to string which caused by head difference at two sides of U-tube [gpm] + REAL :: PressureDp ! pressure at bit or end of drill string from drill string path [psi] + REAL :: PressureAnn ! pressure at bit or end of drill string from annular path [psi] - REAL :: QUTubeInput ! flow rate from string to annulus which caused by head difference at two sides of U-tube [gpm] - REAL :: QUtubeOutput ! flow rate from annulus to string which caused by head difference at two sides of U-tube [gpm] - REAL :: PressureDp ! pressure at bit or end of drill string from drill string path [psi] - REAL :: PressureAnn ! pressure at bit or end of drill string from annular path [psi] + END TYPE UTUBEVARSTYPE + TYPE(UTUBEVARSTYPE) :: UTUBEVARS - END MODULE +END MODULE UTUBEVARSModule - SUBROUTINE DeallocateFlowTypes +SUBROUTINE DeallocateFlowTypes - USE FricPressDropVars - USE PressureDisplayVARIABLES - USE KickVariables + USE FricPressDropVarsModule + use PressureDisplayVARIABLESModule + use KickVARIABLESModule IMPLICIT NONE @@ -166,13 +172,13 @@ MODULE FricPressDropVars IF (ALLOCATED(GasPocketFlowInduced%Array)) CALL GasPocketFlowInduced%Empty() IF (ALLOCATED(GasPocketDensity%Array)) CALL GasPocketDensity%Empty() IF (ALLOCATED(GasPocketCompressibility%Array)) CALL GasPocketCompressibility%Empty() - IF (ALLOCATED(GasPocketFlowEl)) DEALLOCATE(GasPocketFlowEl) - IF (ALLOCATED(KickJacobian)) DEALLOCATE(KickJacobian) - IF (ALLOCATED(OldKickJacobian)) DEALLOCATE(OldKickJacobian) - IF (ALLOCATED(KickVandPFunction)) DEALLOCATE(KickVandPFunction) - IF (ALLOCATED(KickUnknownVector)) DEALLOCATE(KickUnknownVector) - IF (ALLOCATED(KickCorrectionVector)) DEALLOCATE(KickCorrectionVector) + IF (ALLOCATED(KickVARIABLES%GasPocketFlowEl)) DEALLOCATE(KickVARIABLES%GasPocketFlowEl) + IF (ALLOCATED(KickVARIABLES%KickJacobian)) DEALLOCATE(KickVARIABLES%KickJacobian) + IF (ALLOCATED(KickVARIABLES%OldKickJacobian)) DEALLOCATE(KickVARIABLES%OldKickJacobian) + IF (ALLOCATED(KickVARIABLES%KickVandPFunction)) DEALLOCATE(KickVARIABLES%KickVandPFunction) + IF (ALLOCATED(KickVARIABLES%KickUnknownVector)) DEALLOCATE(KickVARIABLES%KickUnknownVector) + IF (ALLOCATED(KickVARIABLES%KickCorrectionVector)) DEALLOCATE(KickVARIABLES%KickCorrectionVector) - END SUBROUTINE +END SUBROUTINE DeallocateFlowTypes \ No newline at end of file diff --git a/FluidFlow/String_Property_Calculator.f90 b/FluidFlow/String_Property_Calculator.f90 index bbc0617..9b96367 100644 --- a/FluidFlow/String_Property_Calculator.f90 +++ b/FluidFlow/String_Property_Calculator.f90 @@ -1,10 +1,10 @@ SUBROUTINE StringPropertyCalculator (md, den, pre, tem) !!! This subroutine gets location of a guage or an observation point and determines information of that point such as pressure, density, velocity and temperature later. - USE PressureDisplayVARIABLES + use PressureDisplayVARIABLESModule USE Fluid_Flow_Startup_Vars !USE MudSystemVARIABLES - USE FricPressDropVars + USE FricPressDropVarsModule !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure !USE CDataDisplayConsoleVariables , CasingPressureDataDisplay=>CasingPressure!, StandPipePressureDataDisplay=>StandPipePressure USE CDrillWatchVariables @@ -20,7 +20,7 @@ SUBROUTINE StringPropertyCalculator (md, den, pre, tem) CALL TVD_Calculator(md * 1.d0 , TVD) - DO ilocal = StringFirstEl , StringLastEl + DO ilocal = FricPressDropVars%StringFirstEl , FricPressDropVars%StringLastEl IF (md < INT(FinalFlowEl(ilocal)%EndX)) EXIT END DO den = FinalFlowEl(ilocal)%Density diff --git a/FluidFlow/Utube.f90 b/FluidFlow/Utube.f90 index e45d758..dfeee21 100644 --- a/FluidFlow/Utube.f90 +++ b/FluidFlow/Utube.f90 @@ -10,9 +10,9 @@ SUBROUTINE Utube !! 1396/08/09 Sheikh Two-side U-tube !! - USE FricPressDropVars + USE FricPressDropVarsModule USE MudSystemVARIABLES - USE UTUBEVARS + use UTUBEVARSModule USE Fluid_Flow_Startup_Vars IMPLICIT NONE @@ -22,25 +22,25 @@ SUBROUTINE Utube INTEGER :: i ,j, ibit , ij , ijk REAL :: AreaBeforeBit !!! Area of element before bit in U-Tube condition [in^2] - QUTubeInput = 1.0 - QUTubeOutput = 1.0 - TotFricPressLoss = 0 + UTUBEVARS%QUTubeInput = 1.0 + UTUBEVARS%QUTubeOutput = 1.0 + FricPressDropVars%TotFricPressLoss = 0 BitPressLoss = 0 - PressureDp = 0 - PressureAnn = 0 + UTUBEVARS%PressureDp = 0 + UTUBEVARS%PressureAnn = 0 !!!!!!!!!!!!!!!!!!!!!! Bit !!!!!!!!!!!! Calculating Pressure at the bottom of drill string from mud columns in drill pipes and annulus space - PressureDp = SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + UTUBEVARS%PressureDp = SUM(FlowEl(FricPressDropVars%StringFirstEl : FricPressDropVars%StringLastEl)%StaticPressDiff) - PressureAnn = SUM(FlowEl(AnnulusFirstEl : AnnulusLastEl)%StaticPressDiff) + UTUBEVARS%PressureAnn = SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%AnnulusLastEl)%StaticPressDiff) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!! U tube:: flow from string to annulus - IF ((PressureDp - PressureAnn) > UTubePressTolerance) THEN + IF ((UTUBEVARS%PressureDp - UTUBEVARS%PressureAnn) > UTubePressTolerance) THEN DO ijk = 1 , 10 - FlowEl(StringFirstEl : AnnulusLastEl)%Flowrate = QUTubeInput + FlowEl(FricPressDropVars%StringFirstEl : FricPressDropVars%AnnulusLastEl)%Flowrate = UTUBEVARS%QUTubeInput !WRITE (*,*) 'QUTubeInput', FlowEl(AnnulusLastEl)%Flowrate - DO ij = StringFirstEl , AnnulusLastEl !!!!! Updating values of flowrates + DO ij = FricPressDropVars%StringFirstEl , FricPressDropVars%AnnulusLastEl !!!!! Updating values of flowrates CALL FricPressDrop(ij) CALL PartialDerivativeFricToFlowRate(ij) !WRITE (*,*) 'FricPressDrop, PartialDerivative', FlowEl(ij)%FricPressLoss, FlowEl(ij)%FricToQPartialDiff, FlowEl(ij)%Length @@ -48,70 +48,63 @@ SUBROUTINE Utube !!!!!!!!!!!!!! Bit pressure drop calculation IF (BitTrue) THEN - i = NoHorizontalEl + NoStringEl + i = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl AreaBeforeBit = FlowEl(i)%Area * Convfttoinch**2 BitPressLoss = FlowEl(i)%density * Convft3toUSgal * (FlowEl(i)%vel**2 * ((AreaBeforeBit/BitTotNozzArea)**2 - 1.)) / 2. / Convlbftolbm / Convfttoinch**2 END IF !!!!!!!!!!!!!!!!!!!!!!!!!!! - i = NoHorizontalEl + 1 - j = NoHorizontalEl + NoStringEl + NoAnnulusEl - !IF (ALLOCATED(FlowEl)) THEN - ! WRITE (*,*) ' H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl - !END IF + i = FricPressDropVars%NoHorizontalEl + 1 + j = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl - TotFricPressLoss = SUM(FlowEl(i : j)%FricPressLoss) + BitPressLoss - IF (ABS((PressureDp - PressureAnn) - TotFricPressLoss) <= UTubePressTolerance .OR. QUTubeInput < 1.0) EXIT ! tolerance set to 1.0 psi - IF ((PressureDp - PressureAnn) > TotFricPressLoss) THEN - QUTubeInput = QUTubeInput + ((PressureDp - PressureAnn) - TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff) - ELSE IF ((PressureDp - PressureAnn) < TotFricPressLoss) THEN - QUTubeInput = QUTubeInput + ((PressureDp - PressureAnn) - TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff) + FricPressDropVars%TotFricPressLoss = SUM(FlowEl(i : j)%FricPressLoss) + BitPressLoss + IF (ABS((UTUBEVARS%PressureDp - UTUBEVARS%PressureAnn) - FricPressDropVars%TotFricPressLoss) <= UTubePressTolerance .OR. UTUBEVARS%QUTubeInput < 1.0) EXIT ! tolerance set to 1.0 psi + IF ((UTUBEVARS%PressureDp - UTUBEVARS%PressureAnn) > FricPressDropVars%TotFricPressLoss) THEN + UTUBEVARS%QUTubeInput = UTUBEVARS%QUTubeInput + ((UTUBEVARS%PressureDp - UTUBEVARS%PressureAnn) - FricPressDropVars%TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff) + ELSE IF ((UTUBEVARS%PressureDp - UTUBEVARS%PressureAnn) < FricPressDropVars%TotFricPressLoss) THEN + UTUBEVARS%QUTubeInput = UTUBEVARS%QUTubeInput + ((UTUBEVARS%PressureDp - UTUBEVARS%PressureAnn) - FricPressDropVars%TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff) END IF !WRITE (*,*) 'QUTubeInput, TotFricPressLoss', QUTubeInput, TotFricPressLoss !WRITE (*,*) '1) PressureDp, PressureAnn', PressureDp, PressureAnn, TotFricPressLoss, QUTubeInput END DO - QUTubeOutput = 0.0 + UTUBEVARS%QUTubeOutput = 0.0 !!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!! U tube:: flow from annulus to string - ELSE IF ((PressureAnn - PressureDp) > UTubePressTolerance) THEN + ELSE IF ((UTUBEVARS%PressureAnn - UTUBEVARS%PressureDp) > UTubePressTolerance) THEN DO ijk = 1 , 10 - DO ij = NoHorizontalEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl !!!!! Updating values of flowrates - FlowEl(ij)%Flowrate = QUTubeOutput + DO ij = FricPressDropVars%NoHorizontalEl + 1 , FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl !!!!! Updating values of flowrates + FlowEl(ij)%Flowrate = UTUBEVARS%QUTubeOutput CALL FricPressDrop(ij) CALL PartialDerivativeFricToFlowRate(ij) END DO !!!!!!!!!!!!!! Bit pressure drop calculation IF (BitTrue) THEN - !DO i = NumbEl , 1 , -1 !! This loop starts from the first elements of string and check the elements to reach the bit at the bottom of string - ! IF (FlowEl(i)%Id==0) CYCLE - i = NoHorizontalEl + NoStringEl + 1 + i = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + 1 AreaBeforeBit = FlowEl(i)%Area * Convfttoinch**2 BitPressLoss = FlowEl(i)%density * Convft3toUSgal * (FlowEl(i)%vel**2 * ((AreaBeforeBit/BitTotNozzArea)**2 - 1.)) / 2. / Convlbftolbm / Convfttoinch**2 - !IF (FlowEl(i)%Id>0) EXIT - !END DO END IF !!!!!!!!!!!!!!!!!!!!!!!!!!! - i = NoHorizontalEl + 1 - j = NoHorizontalEl + NoStringEl + NoAnnulusEl - TotFricPressLoss = SUM(FlowEl(i : j)%FricPressLoss) + BitPressLoss + i = FricPressDropVars%NoHorizontalEl + 1 + j = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl + FricPressDropVars%TotFricPressLoss = SUM(FlowEl(i : j)%FricPressLoss) + BitPressLoss - IF (ABS((PressureDp - PressureAnn) - TotFricPressLoss) <= UTubePressTolerance) EXIT ! tolerance set to 1.0 psi - IF ((PressureAnn - PressureDp) > TotFricPressLoss) THEN - QUTubeOutput = QUTubeOutput - (((PressureAnn - PressureDp) - TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff)) - ELSE IF ((PressureAnn - PressureDp) < TotFricPressLoss) THEN - QUTubeOutput = QUTubeOutput + (((PressureAnn - PressureDp) - TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff)) + IF (ABS((UTUBEVARS%PressureDp - UTUBEVARS%PressureAnn) - FricPressDropVars%TotFricPressLoss) <= UTubePressTolerance) EXIT ! tolerance set to 1.0 psi + IF ((UTUBEVARS%PressureAnn - UTUBEVARS%PressureDp) > FricPressDropVars%TotFricPressLoss) THEN + UTUBEVARS%QUTubeOutput = UTUBEVARS%QUTubeOutput - (((UTUBEVARS%PressureAnn - UTUBEVARS%PressureDp) - FricPressDropVars%TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff)) + ELSE IF ((UTUBEVARS%PressureAnn - UTUBEVARS%PressureDp) < FricPressDropVars%TotFricPressLoss) THEN + UTUBEVARS%QUTubeOutput = UTUBEVARS%QUTubeOutput + (((UTUBEVARS%PressureAnn - UTUBEVARS%PressureDp) - FricPressDropVars%TotFricPressLoss) / SUM(FlowEl(i : j)%FricToQPartialDiff)) END IF !WRITE (*,*) 'QUTubeOutput, TotFricPressLoss', QUTubeOutput, TotFricPressLoss - WRITE (*,*) '2) PressureDp, PressureAnn', PressureDp, PressureAnn, TotFricPressLoss + WRITE (*,*) '2) PressureDp, PressureAnn', UTUBEVARS%PressureDp, UTUBEVARS%PressureAnn, FricPressDropVars%TotFricPressLoss END DO - QUTubeInput = 0.0 + UTUBEVARS%QUTubeInput = 0.0 !!!!!!!!!!!! No U-Tube ELSE - QUTubeInput = 0.0 - QUTubeOutput = 0.0 + UTUBEVARS%QUTubeInput = 0.0 + UTUBEVARS%QUTubeOutput = 0.0 END IF END SUBROUTINE \ No newline at end of file diff --git a/FluidFlow/Well_Pressure_Data_Transfer.f90 b/FluidFlow/Well_Pressure_Data_Transfer.f90 index 81d8b6d..daf9dd0 100644 --- a/FluidFlow/Well_Pressure_Data_Transfer.f90 +++ b/FluidFlow/Well_Pressure_Data_Transfer.f90 @@ -13,13 +13,13 @@ SUBROUTINE WellPressureDataTransfer !! frictional pressure drop calculated by subroutine Sub_Press_Drop_Calculator !! This subroutine includes hydrostatic pressure and later will include effect of corss-section area change !! which causes acceleration or decceleration of flow - Use ConfigurationVariables - USE FricPressDropVars + + USE FricPressDropVarsModule use MudSystemModule USE MudSystemVARIABLES USE GeoElements_FluidModule USE Fluid_Flow_Startup_Vars - USE KickVariables + use KickVARIABLESModule USE CMudPropertiesVariables USE CBopStackVariables USE sROP_Variables @@ -29,17 +29,17 @@ SUBROUTINE WellPressureDataTransfer USE CChokeProblemsVariables USE CStringConfigurationVariables USE CDrillWatchVariables - USE CDataDisplayConsoleVariables - + USE CDataDisplayConsoleVariables + use ConfigurationVariables IMPLICIT NONE INTEGER :: i , j REAL :: InstantaneousTotalOpenChokeArea , VolumeDensityProduct - ChokeIsClosing = .FALSE. - Kchoke = 0.0 - KBit = 0.0 + KickVARIABLES%ChokeIsClosing = .FALSE. + FricPressDropVars%Kchoke = 0.0 + FricPressDropVars%KBit = 0.0 !!!!!!!!!!!!!!!! bit is present @@ -47,15 +47,15 @@ SUBROUTINE WellPressureDataTransfer BitCd = 0.98 BitNozzDia = 32.0 * Configuration%StringConfiguration%BitDefinition%BitNozzleSize ! nozzle diameter in 1/32 in BitNozzleArea = 7.6699E-4 * BitNozzDia**2 - BitNozzleNum = Configuration%StringConfiguration%BitDefinition%BitNozzleNo - BitJetsPlugged * BitProblems%PlugJetsCount - BitTotNozzArea = BitNozzleNum * BitNozzleArea + 0.5 * BitJetsWashedOut * BitProblems%JetWashoutCount * BitNozzleArea + BitNozzleNum = Configuration%StringConfiguration%BitDefinition%BitNozzleNo - FricPressDropVars%BitJetsPlugged * BitProblems%PlugJetsCount + BitTotNozzArea = BitNozzleNum * BitNozzleArea + 0.5 * FricPressDropVars%BitJetsWashedOut * BitProblems%JetWashoutCount * BitNozzleArea IF (BitNozzleNum == 0) THEN - BitTotallyPluged = .TRUE. + FricPressDropVars%BitTotallyPluged = .TRUE. ELSE - BitTotallyPluged = .FALSE. + FricPressDropVars%BitTotallyPluged = .FALSE. END IF - FloatValveIn = Configuration%StringConfiguration%BitDefinition%FloatValve + FricPressDropVars%FloatValveIn = Configuration%StringConfiguration%BitDefinition%FloatValve !FloatValveOpen = .TRUE. !IF (JetWashoutCount > 0 .OR. PlugJetsCount > 0) THEN ! WRITE (*,*) 'PlugJetsCount' , PlugJetsCount @@ -68,41 +68,40 @@ SUBROUTINE WellPressureDataTransfer !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - IF(ALLOCATED(GasPocketFlowEl)) DEALLOCATE(GasPocketFlowEl) + IF(ALLOCATED(KickVARIABLES%GasPocketFlowEl)) DEALLOCATE(KickVARIABLES%GasPocketFlowEl) !!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed ) - ChokeKroneckerDelta = 0 + KickVARIABLES%ChokeKroneckerDelta = 0 IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN - WellHeadOpen = .FALSE. + KickVARIABLES%WellHeadOpen = .FALSE. !WRITE (*,*) ' Well Head is closed ' ELSE - WellHeadOpen = .TRUE. + KickVARIABLES%WellHeadOpen = .TRUE. END IF - IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen) ChokeKroneckerDelta = 1 + IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen) KickVARIABLES%ChokeKroneckerDelta = 1 !WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - NoHorizontalEl = MudSystem%NoHorizontalMudElements - NoStringEl = MudSystem%NoStringMudElements - NoAnnulusEl = MudSystem%NoCasingMudElements - NoWellToChokeEl = 0 - 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 + FricPressDropVars%NoHorizontalEl = MudSystem%NoHorizontalMudElements + FricPressDropVars%NoStringEl = MudSystem%NoStringMudElements + FricPressDropVars%NoAnnulusEl = MudSystem%NoCasingMudElements + FricPressDropVars%NoWellToChokeEl = 0 + IF (KickVARIABLES%ChokeKroneckerDelta == 1) FricPressDropVars%NoWellToChokeEl = MudSystem%ChokeLine_Density%Length() + FricPressDropVars%NoOpenHoleEl = MudSystem%NoBottomHoleMudElements + FricPressDropVars%NumbEl = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl + FricPressDropVars%NoWellToChokeEl + FricPressDropVars%NoOpenHoleEl IF(ALLOCATED(FlowEl)) DEALLOCATE(FlowEl) - ALLOCATE(FlowEl(NumbEl)) + ALLOCATE(FlowEl(FricPressDropVars%NumbEl)) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Transfering Data from module:MudSystemVARIABLES to module:FricPressDropVars to calculate Pressure distribution in flow path !!!!!!!!!!!!!!!!!!!!!!! Horizontal line !WRITE (*,*) 'H', NoHorizontalEl - DO i = 1 , NoHorizontalEl + DO i = 1 , FricPressDropVars%NoHorizontalEl FlowEl(i)%StartX = MudSystem%Xstart_MudElement%Array(i) FlowEl(i)%EndX = MudSystem%Xend_MudElement%Array(i) FlowEl(i)%StartTVD = 0.d0 @@ -126,18 +125,15 @@ SUBROUTINE WellPressureDataTransfer FlowEl(i)%dPdLgrav = 0.0 FlowEl(i)%StaticPressDiff = 0.0 - !WRITE (*,*) 'H density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType END DO - !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!! String - !WRITE (*,*) 'S', NoStringEl - StringFirstEl = NoHorizontalEl + 1 - StringLastEl = NoHorizontalEl + NoStringEl - DO i = NoHorizontalEl + 1 , NoHorizontalEl + NoStringEl + FricPressDropVars%StringFirstEl = FricPressDropVars%NoHorizontalEl + 1 + FricPressDropVars%StringLastEl = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + DO i = FricPressDropVars%NoHorizontalEl + 1 , FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl !WRITE (*,*) 'ST , i' , i FlowEl(i)%StartX = MudSystem%Xstart_MudElement%Array(i) !WRITE (*,*) 'StartX', FlowEl(i)%StartX @@ -177,19 +173,16 @@ SUBROUTINE WellPressureDataTransfer END IF FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff) - !WRITE (*,*) 'S density, length, DeltaPStatic' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%StaticPressDiff, FlowEl(i)%MaterialType END DO - !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!! Annulus - !WRITE (*,*) 'A', NoAnnulusEl - AnnulusFirstEl = NoHorizontalEl + NoStringEl + 1 - AnnulusLastEl = NoHorizontalEl + NoStringEl + NoAnnulusEl - DO i = NoHorizontalEl + NoStringEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl + FricPressDropVars%AnnulusFirstEl = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + 1 + FricPressDropVars%AnnulusLastEl = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl + DO i = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + 1 , FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl FlowEl(i)%StartX = MudSystem%Xstart_MudElement%Array(i) FlowEl(i)%EndX = MudSystem%Xend_MudElement%Array(i) FlowEl(i)%StartTVD = MudSystem%TVDstart_MudElement%Array(i) @@ -218,18 +211,14 @@ SUBROUTINE WellPressureDataTransfer END IF FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff) - !WRITE (*,*) 'A density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType END DO - !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!! Well to choke manifold path - !ChokeFirstEl = AnnulusLastEl + 1 - !ChokeLastEl = OpenholeFirstEl - 1 j = 1 - DO i = NoHorizontalEl + NoStringEl + NoAnnulusEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWelltoChokeEl + DO i = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl + 1 , FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl + FricPressDropVars%NoWelltoChokeEl 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 @@ -259,13 +248,12 @@ SUBROUTINE WellPressureDataTransfer END DO - !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!! Open Hole - OpenholeFirstEl = NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWelltoChokeEl + 1 + FricPressDropVars%OpenholeFirstEl = FricPressDropVars%NoHorizontalEl + FricPressDropVars%NoStringEl + FricPressDropVars%NoAnnulusEl + FricPressDropVars%NoWelltoChokeEl + 1 j = 1 - DO i = OpenholeFirstEl , NumbEl ! = NoHorizontalEl + NoStringEl + NoCasingEl + NoOpenHoleEl + DO i = FricPressDropVars%OpenholeFirstEl , FricPressDropVars%NumbEl ! = NoHorizontalEl + NoStringEl + NoCasingEl + NoOpenHoleEl FlowEl(i)%StartX = MudSystem%Xstart_OpMudElement%Array(j) FlowEl(i)%EndX = MudSystem%Xend_OpMudElement%Array(j) FlowEl(i)%StartTVD = MudSystem%TVDstart_OpMudElement%Array(j) @@ -299,22 +287,17 @@ SUBROUTINE WellPressureDataTransfer !WRITE (*,*) 'O density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType END DO - !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600 - - !DO i = NoHorizontalEl + 1, NoHorizontalEl + NoStringEl - ! WRITE (*,*) 'element No, Start , Length, DeltaPSt', i, FlowEl(i)%StartX, FlowEl(i)%Length, FlowEl(i)%StaticPressDiff - !END DO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!! Mud Element Viscosity Calculation - DO i = 1 , NumbEl + DO i = 1 , FricPressDropVars%NumbEl IF (FlowEl(i)%MaterialType /= 0) CYCLE IF (FlowEl(i)%density < 8.33) THEN - WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , StringFirstEl , AnnulusFirstEl , NoWellToChokeEl , OpenHoleFirstEl + WRITE (*,*) 'H, S, A, Ch, O', FricPressDropVars%NoHorizontalEl , FricPressDropVars%StringFirstEl , FricPressDropVars%AnnulusFirstEl , FricPressDropVars%NoWellToChokeEl , FricPressDropVars%OpenHoleFirstEl WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type' - DO j = 1 , NumbEl + DO j = 1 , FricPressDropVars%NumbEl WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType END DO @@ -341,37 +324,36 @@ SUBROUTINE WellPressureDataTransfer !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - MudSystem%OpenArea32 = ((ChokeManifold%LeftManualChoke * (1.0 - ManChoke1Plug * REAL(ChokeProblems%ManualChoke1PluggedPercent)) / 100.0) + 0.5 * ManChoke1Washout) * Choke%ChokeAreaFullyOpen + MudSystem%OpenArea32 = ((ChokeManifold%LeftManualChoke * (1.0 - FricPressDropVars%ManChoke1Plug * REAL(ChokeProblems%ManualChoke1PluggedPercent)) / 100.0) + 0.5 * FricPressDropVars%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 + MudSystem%OpenArea35 = ((ChokeManifold%RightManualChoke * (1.0 - FricPressDropVars%ManChoke2Plug * REAL(ChokeProblems%ManualChoke2PluggedPercent)) / 100.0) + 0.5 * FricPressDropVars%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 = MudSystem%OpenArea32 * active32 + MudSystem%OpenArea33 * active33 + MudSystem%OpenArea34 * active34 + MudSystem%OpenArea35 * active35 + ChokeBypassArea * active29 - OldTotalOpenChokeArea = TotalOpenChokeArea + InstantaneousTotalOpenChokeArea = MudSystem%OpenArea32 * active32 + MudSystem%OpenArea33 * active33 + MudSystem%OpenArea34 * active34 + MudSystem%OpenArea35 * active35 + FricPressDropVars%ChokeBypassArea * active29 + FricPressDropVars%OldTotalOpenChokeArea = FricPressDropVars%TotalOpenChokeArea !WRITE (*,*) 'Instantaneous / Old TotalOpenChokeArea', InstantaneousTotalOpenChokeArea, OldTotalOpenChokeArea - IF (OldTotalOpenChokeArea <= 0.01 * Choke%ChokeAreaFullyOpen) OldTotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen + IF (FricPressDropVars%OldTotalOpenChokeArea <= 0.01 * Choke%ChokeAreaFullyOpen) FricPressDropVars%OldTotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen IF (InstantaneousTotalOpenChokeArea <= 0.01 * Choke%ChokeAreaFullyOpen) THEN MudSystem%WellToChokeManifoldOpen = .FALSE. - OldTotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen + FricPressDropVars%OldTotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen !WRITE (*,*) ' Choke Controler Here 2' 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 + FricPressDropVars%TotalOpenChokeArea = InstantaneousTotalOpenChokeArea !WRITE (*,*) ' Choke Controler Here 1' ELSE - IF (InstantaneousTotalOpenChokeArea > OldTotalOpenChokeArea) THEN - TotalOpenChokeArea = MIN(1.1 * OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea) + IF (InstantaneousTotalOpenChokeArea > FricPressDropVars%OldTotalOpenChokeArea) THEN + FricPressDropVars%TotalOpenChokeArea = MIN(1.1 * FricPressDropVars%OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea) WRITE (*,*) ' Choke is opening' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea - ELSE IF (InstantaneousTotalOpenChokeArea < OldTotalOpenChokeArea) THEN - TotalOpenChokeArea = MAX(0.9 * OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea) + ELSE IF (InstantaneousTotalOpenChokeArea < FricPressDropVars%OldTotalOpenChokeArea) THEN + FricPressDropVars%TotalOpenChokeArea = MAX(0.9 * FricPressDropVars%OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea) WRITE (*,*) ' Choke is closing' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea - !ExitMass = 0.1 * ExitMass ! for decreasing mass exit due to expansion ELSE - TotalOpenChokeArea = InstantaneousTotalOpenChokeArea + FricPressDropVars%TotalOpenChokeArea = InstantaneousTotalOpenChokeArea END IF END IF !WRITE (*,*) 'TotalOpenChokeArea=', TotalOpenChokeArea @@ -383,33 +365,32 @@ SUBROUTINE WellPressureDataTransfer !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed ) - ChokeKroneckerDelta = 0 + KickVARIABLES%ChokeKroneckerDelta = 0 !WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen !WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN !WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen !WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen - WellHeadOpen = .FALSE. + KickVARIABLES%WellHeadOpen = .FALSE. !WRITE (*,*) ' Well Head is closed ' ELSE - WellHeadOpen = .TRUE. + KickVARIABLES%WellHeadOpen = .TRUE. END IF - IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen) ChokeKroneckerDelta = 1 + IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen) KickVARIABLES%ChokeKroneckerDelta = 1 !WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen - !WRITE (*,*) 'WellToChokeOpen , WellToChokeWasOpen', WellToChokeManifoldOpen, WellToChokeManifoldWasOpen + !WRITE (*,*) 'WellToChokeOpen , WellToChokeWasOpen', WellToChokeManifoldOpen, KickVARIABLES%WellToChokeManifoldWasOpen !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - IF (NoGasPocket > 0) THEN - !IF (NoWelltoChokeEl > 0 .AND. (FlowEl(OpenholeFirstEl - 1)%MaterialType == 1 .OR. KickWasExitingThroughChoke) .AND. WellHeadOpen) THEN + IF (KickVARIABLES%NoGasPocket > 0) 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(MudSystem%Choke_Kick_Saved_Volume_Final / (GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal)) * GasPocketWeight%Array(NoGasPocket) + KickVARIABLES%ExitMass = REAL(MudSystem%Choke_Kick_Saved_Volume_Final / (GasPocketModifiedVol%Array(KickVARIABLES%NoGasPocket) * Convft3ToUSgal)) * GasPocketWeight%Array(KickVARIABLES%NoGasPocket) !IF (NoGasPocket > 1) ExitMass = ExitMass + (SUM(GasPocketDeltaVol%Array(1 : NoGasPocket - 1)) / GasPocketNewVol%Array(NoGasPocket)) * GasPocketWeight%Array(NoGasPocket) !WRITE (*,*) 'Total Exit mass=' , ExitMass !, DeltaVolumePipe, MudSystem%StringFlowRate * dt / ConvMinToSec - IF (FlowEl(OpenholeFirstEl - 1)%MaterialType /= 1) THEN - CALL RemoveGasPocket(NoGasPocket) + IF (FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%MaterialType /= 1) THEN + CALL RemoveGasPocket(KickVARIABLES%NoGasPocket) WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', MudSystem%Choke_Kick_Saved_Volume_Final END IF @@ -417,31 +398,23 @@ SUBROUTINE WellPressureDataTransfer !NoGasPocket = SIZE(GasPocketWeight%Array) - IF (NoGasPocket > 0) CALL GasPocketFlowElementTransformer + IF (KickVARIABLES%NoGasPocket > 0) CALL GasPocketFlowElementTransformer END IF - IF (NoWelltoChokeEl > 0) THEN - OldChokeDensity = ChokeDensity - !ChokeDensity = SUM(FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Density * FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Volume) / SUM(FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Volume) - !ChokeDensity = MAX(ChokeDensity , ChokeMinDensity) + IF (FricPressDropVars%NoWelltoChokeEl > 0) THEN + KickVARIABLES%OldChokeDensity = KickVARIABLES%ChokeDensity VolumeDensityProduct = 0.0 - Do i = AnnulusLastEl + 1 , OpenholeFirstEl - 1 - VolumeDensityProduct = VolumeDensityProduct + ((MAX(FlowEl(i)%Density , ChokeMinDensity)) * FlowEl(i)%Volume) + Do i = FricPressDropVars%AnnulusLastEl + 1 , FricPressDropVars%OpenholeFirstEl - 1 + VolumeDensityProduct = VolumeDensityProduct + ((MAX(FlowEl(i)%Density , KickVARIABLES%ChokeMinDensity)) * FlowEl(i)%Volume) End Do - ChokeDensity = VolumeDensityProduct / SUM(FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Volume) - - !IF ((ChokeDensity - OldChokeDensity) > (MaxChokeDensityChange * dt / Convmintosec)) THEN - ! ChokeDensity = OldChokeDensity + (MaxChokeDensityChange * dt / Convmintosec) - !ELSE IF ((OldChokeDensity - ChokeDensity) > (MaxChokeDensityChange * dt / Convmintosec)) THEN - ! ChokeDensity = OldChokeDensity - (MaxChokeDensityChange * dt / Convmintosec) - !END IF - - !WRITE (*,*) 'ChokeDensity=', ChokeDensity - Kchoke = (ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * TotalOpenChokeArea)**2)) * 4.d0 ! *4.d0: seyyed gofte + KickVARIABLES%ChokeDensity = VolumeDensityProduct / SUM(FlowEl(FricPressDropVars%AnnulusLastEl + 1 : FricPressDropVars%OpenholeFirstEl - 1)%Volume) + + !WRITE (*,*) 'ChokeDensity=', KickVARIABLES%ChokeDensity + FricPressDropVars%Kchoke = (KickVARIABLES%ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * FricPressDropVars%TotalOpenChokeArea)**2)) * 4.d0 ! *4.d0: seyyed gofte END IF - IF (BitTotallyPluged == .FALSE.) THEN - KBit = FlowEl(StringLastEl)%density / 12042.0 / BitCd**2 / BitTotNozzArea**2 + IF (FricPressDropVars%BitTotallyPluged == .FALSE.) THEN + FricPressDropVars%KBit = FlowEl(FricPressDropVars%StringLastEl)%density / 12042.0 / BitCd**2 / BitTotNozzArea**2 END IF @@ -458,11 +431,11 @@ SUBROUTINE GasPocketFlowElementTransformer !! GasPocketFlowEl(1,:) = [12 , 3 , 4] and GasPocketFlowEl(2,:) = [7 , 8 , 0] - USE FricPressDropVars + USE FricPressDropVarsModule USE MudSystemVARIABLES USE GeoElements_FluidModule USE Fluid_Flow_Startup_Vars - USE KickVariables + use KickVARIABLESModule USE CMudPropertiesVariables USE CBopStackVariables USE CDownHoleVariables @@ -474,78 +447,72 @@ SUBROUTINE GasPocketFlowElementTransformer REAL :: PressureCorrection PressureCorrection = 1.0 - ALLOCATE(GasPocketFlowEl(NoGasPocket , 1)) - GasPocketFlowEl(:,:) = 0 + ALLOCATE(KickVARIABLES%GasPocketFlowEl(KickVARIABLES%NoGasPocket , 1)) + KickVARIABLES%GasPocketFlowEl(:,:) = 0 !WRITE (*,*) 'NoGasPocket=' , NoGasPocket i = 1 j = 1 - DO k = OpenholeFirstEl , NumbEl + DO k = FricPressDropVars%OpenholeFirstEl , FricPressDropVars%NumbEl IF (FlowEl(k)%MaterialType == 1) THEN IF (j > 1) THEN - IF (GasPocketFlowEl(i , j - 1) /= k - 1) THEN + IF (KickVARIABLES%GasPocketFlowEl(i , j - 1) /= k - 1) THEN i = i + 1 j = 1 END IF END IF - IF (SIZE(GasPocketFlowEl , dim = 2) < j) THEN - ALLOCATE(tempGasPocketFlowEl(SIZE(GasPocketFlowEl , dim = 1) , SIZE(GasPocketFlowEl , dim = 2))) - tempGasPocketFlowEl = GasPocketFlowEl - DEALLOCATE(GasPocketFlowEl) - ALLOCATE(GasPocketFlowEl(SIZE(tempGasPocketFlowEl , dim = 1) , SIZE(tempGasPocketFlowEl , dim = 2) + 1)) - GasPocketFlowEl(: , 1 : SIZE(tempGasPocketFlowEl , dim = 2)) = tempGasPocketFlowEl - GasPocketFlowEl(: , SIZE(GasPocketFlowEl , dim = 2)) = 0 - DEALLOCATE(tempGasPocketFlowEl) + IF (SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2) < j) THEN + ALLOCATE(KickVARIABLES%tempGasPocketFlowEl(SIZE(KickVARIABLES%GasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2))) + KickVARIABLES%tempGasPocketFlowEl = KickVARIABLES%GasPocketFlowEl + DEALLOCATE(KickVARIABLES%GasPocketFlowEl) + ALLOCATE(KickVARIABLES%GasPocketFlowEl(SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2) + 1)) + KickVARIABLES%GasPocketFlowEl(: , 1 : SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2)) = KickVARIABLES%tempGasPocketFlowEl + KickVARIABLES%GasPocketFlowEl(: , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)) = 0 + DEALLOCATE(KickVARIABLES%tempGasPocketFlowEl) END IF - GasPocketFlowEl(i , j) = k + KickVARIABLES%GasPocketFlowEl(i , j) = k j = j + 1 END IF END DO !WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl - DO k = AnnulusFirstEl , OpenholeFirstEl - 1 + DO k = FricPressDropVars%AnnulusFirstEl , FricPressDropVars%OpenholeFirstEl - 1 IF (FlowEl(k)%MaterialType == 1) THEN IF (j > 1) THEN - IF (k == AnnulusFirstEl .AND. GasPocketFlowEl(i , j - 1) == NumbEl) THEN + IF (k == FricPressDropVars%AnnulusFirstEl .AND. KickVARIABLES%GasPocketFlowEl(i , j - 1) == FricPressDropVars%NumbEl) THEN !WRITE (*,*) 'Kick is Around Bit' - ELSE IF (GasPocketFlowEl(i , j - 1) /= k - 1) THEN + ELSE IF (KickVARIABLES%GasPocketFlowEl(i , j - 1) /= k - 1) THEN i = i + 1 j = 1 !WRITE (*,*) 'i, j, k', i, j, k, FlowEl(k)%MaterialType END IF END IF - IF (j > SIZE(GasPocketFlowEl , dim = 2)) THEN - ALLOCATE(tempGasPocketFlowEl(SIZE(GasPocketFlowEl , dim = 1) , SIZE(GasPocketFlowEl , dim = 2))) - tempGasPocketFlowEl = GasPocketFlowEl - DEALLOCATE(GasPocketFlowEl) - ALLOCATE(GasPocketFlowEl(SIZE(tempGasPocketFlowEl , dim = 1) , SIZE(tempGasPocketFlowEl , dim = 2) + 1)) - GasPocketFlowEl(: , 1 : SIZE(tempGasPocketFlowEl , dim = 2)) = tempGasPocketFlowEl - GasPocketFlowEl(: , SIZE(GasPocketFlowEl , dim = 2)) = 0 - DEALLOCATE(tempGasPocketFlowEl) + IF (j > SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)) THEN + ALLOCATE(KickVARIABLES%tempGasPocketFlowEl(SIZE(KickVARIABLES%GasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2))) + KickVARIABLES%tempGasPocketFlowEl = KickVARIABLES%GasPocketFlowEl + DEALLOCATE(KickVARIABLES%GasPocketFlowEl) + ALLOCATE(KickVARIABLES%GasPocketFlowEl(SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2) + 1)) + KickVARIABLES%GasPocketFlowEl(: , 1 : SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2)) = KickVARIABLES%tempGasPocketFlowEl + KickVARIABLES%GasPocketFlowEl(: , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)) = 0 + DEALLOCATE(KickVARIABLES%tempGasPocketFlowEl) END IF - IF (i > NoGasPocket) THEN - WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl + IF (i > KickVARIABLES%NoGasPocket) THEN + WRITE (*,*) 'GasPocketFlowEl', KickVARIABLES%GasPocketFlowEl WRITE (*,*) 'i , j , k', i, j, k - WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , StringFirstEl , AnnulusFirstEl , NoWellToChokeEl , OpenHoleFirstEl + WRITE (*,*) 'H, S, A, Ch, O', FricPressDropVars%NoHorizontalEl , FricPressDropVars%StringFirstEl , FricPressDropVars%AnnulusFirstEl , FricPressDropVars%NoWellToChokeEl , FricPressDropVars%OpenHoleFirstEl WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type' - DO j = 1 , NumbEl + DO j = 1 , FricPressDropVars%NumbEl WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType END DO - !WRITE (*,*) 'Op Last: Volume(gal), Type', NumbEl, FlowEl(NumbEl)%Volume * ConvFt3ToUSgal , FlowEl(NumbEl)%MaterialType - !WRITE (*,*) 'Ann First: Volume(gal), Type', AnnulusFirstEl, FlowEl(AnnulusFirstEl)%Volume * ConvFt3ToUSgal , FlowEl(AnnulusFirstEl)%MaterialType - !IF (ChokeKroneckerDelta == 1) THEN - ! WRITE (*,*) 'Ann Last: Volume(gal), Type', AnnulusLastEl, FlowEl(AnnulusLastEl)%Volume * ConvFt3ToUSgal , FlowEl(AnnulusLastEl)%MaterialType - ! WRITE (*,*) 'Ch First: Volume(gal), Type', AnnulusLastEl + 1 , FlowEl(AnnulusLastEl + 1)%Volume * ConvFt3ToUSgal , FlowEl(AnnulusLastEl + 1)%MaterialType - !END IF - + CALL ErrorStop('Error in calculating GasPocketFlowEl') END IF - GasPocketFlowEl(i , j) = k + KickVARIABLES%GasPocketFlowEl(i , j) = k !WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl j = j + 1 @@ -553,126 +520,94 @@ SUBROUTINE GasPocketFlowElementTransformer !IF (i > NoGasPocket) CALL ErrorStop('Error in GasPocketFlowEl' , i) END DO - !i = SIZE(GasPocketFlowEl , dim = 1) - !j = SIZE(GasPocketFlowEl , dim = 2) - !WRITE(*,*) 'GasPocketFlowEl Data' , GasPocketFlowEl - + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GasPocketModifiedVol%Array(:) = 0.d0 - DO i = 1 , NoGasPocket + DO i = 1 , KickVARIABLES%NoGasPocket !WRITE(*,*) 'GasPocketFlowEl Data' , i , GasPocketFlowEl(: , i) - DO j = 1 , SIZE(GasPocketFlowEl , dim = 2) - IF (GasPocketFlowEl(i , j) > 0) GasPocketModifiedVol%Array(i) = GasPocketModifiedVol%Array(i) + FlowEl(GasPocketFlowEl(i , j))%Volume + DO j = 1 , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2) + IF (KickVARIABLES%GasPocketFlowEl(i , j) > 0) GasPocketModifiedVol%Array(i) = GasPocketModifiedVol%Array(i) + FlowEl(KickVARIABLES%GasPocketFlowEl(i , j))%Volume END DO END DO - i = AnnulusLastEl - j = OpenholeFirstEl - 1 - !WRITE (*,*) ' b) GasPocketModifiedVol (ft3)=', GasPocketModifiedVol(1) - !WRITE (*,*) ' b) GasPocketModifiedVol (gal)=' , GasPocketModifiedVol(1) * 7.48 - !IF (NoWelltoChokeEl > 0 .AND. ANY(FlowEl(i : j)%MaterialType == 1) .AND. FlowEl(j)%MaterialType == 0) THEN - ! BehindKickMudDensity = FlowEl(GasPocketFlowEl(NoGasPocket , 1) - 1)%Density - ! FrontKickMudDensity = FlowEl(MAXVAL(GasPocketFlowEl(NoGasPocket , :)) + 1)%Density - ! KickVolBeforeChoke = REAL(GasPocketModifiedVol%Array(NoGasPocket)) - ! WRITE (*,*) 'BehindKickMudDensity', BehindKickMudDensity - ! WRITE (*,*) 'FrontKickMudDensity' , FrontKickMudDensity - ! WRITE (*,*) 'KickVolBeforeChoke', KickVolBeforeChoke - !END IF + i = FricPressDropVars%AnnulusLastEl + j = FricPressDropVars%OpenholeFirstEl - 1 GasPocketOldVol%Array(:) = GasPocketModifiedVol%Array(:) GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) !WRITE (*,*) ' GasPocketweight%Array(1)', GasPocketweight%Array(1) - IF (GasPocketWeight%Array(1) < 0.0) CALL ErrorStop(' Error in Calculating Mass ' , KickmdotBCoef) + IF (GasPocketWeight%Array(1) < 0.0) CALL ErrorStop(' Error in Calculating Mass ' , KickVARIABLES%KickmdotBCoef) GasPocketDensity%Array(:) = (GasPocketweight%Array(:) / GasPocketModifiedVol%Array(:)) / convft3toUSgal ! [lbm/ft^3 to ppg] - DO i = 1 , SIZE(GasPocketFlowEl , dim = 1) - DO j = 1 , SIZE(GasPocketFlowEl , dim = 2) - IF (GasPocketFlowEl(i , j) > 0) FlowEl(GasPocketFlowEl(i , j))%Density = GasPocketDensity%Array(i) + DO i = 1 , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 1) + DO j = 1 , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2) + IF (KickVARIABLES%GasPocketFlowEl(i , j) > 0) FlowEl(KickVARIABLES%GasPocketFlowEl(i , j))%Density = GasPocketDensity%Array(i) END DO END DO !WRITE (*,*) 'Kick density (ppg)=' , GasPocketDensity(1) - DownHole%InfluxRate = MAX(((KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1))) / GasPocketDensity%Array(1) * ConvMinToSec) , 0.0) + DownHole%InfluxRate = MAX(((KickVARIABLES%KickmdotACoef * (KickVARIABLES%KickmdotBCoef - GasPocketNewPress%Array(1))) / GasPocketDensity%Array(1) * ConvMinToSec) , 0.0) !WRITE (*,*) ' InfluxRate (gpm) =', InfluxRate - 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 (MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0 .AND. WellHeadOpen) THEN + i = FricPressDropVars%OpenholeFirstEl - 1 + IF (MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0 .AND. KickVARIABLES%WellHeadOpen) THEN WRITE (*,*) 'Kick is exiting through the choke' - !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 * & - GasPocketCompressibility%Array(NoGasPocket) * GasPocketNewTemp%Array(NoGasPocket) / GasPocketModifiedVol%Array(NoGasPocket) - GasPocketDensity%Array(NoGasPocket) = (GasPocketweight%Array(NoGasPocket) / GasPocketModifiedVol%Array(NoGasPocket)) / convft3toUSgal + !KickVARIABLES%ExitMass = GasPocketDensity%Array(NoGasPocket) * (SUM(GasPocketFlowInduced%Array(:)) + (DeltaVolumePipe * ConvMinToSec / dt) + MudSystem%StringFlowRate) / ConvMinToSec * dt + GasPocketWeight%Array(KickVARIABLES%NoGasPocket) = GasPocketweight%Array(KickVARIABLES%NoGasPocket) - KickVARIABLES%ExitMass + IF (GasPocketWeight%Array(KickVARIABLES%NoGasPocket) > 0.0) THEN + GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) = GasPocketWeight%Array(KickVARIABLES%NoGasPocket) * GasType(KickVARIABLES%KickGasType)%GasConstant * & + GasPocketCompressibility%Array(KickVARIABLES%NoGasPocket) * GasPocketNewTemp%Array(KickVARIABLES%NoGasPocket) / GasPocketModifiedVol%Array(KickVARIABLES%NoGasPocket) + GasPocketDensity%Array(KickVARIABLES%NoGasPocket) = (GasPocketweight%Array(KickVARIABLES%NoGasPocket) / GasPocketModifiedVol%Array(KickVARIABLES%NoGasPocket)) / convft3toUSgal GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:) - !FlowEl(i)%Density = GasPocketDensity%Array(NoGasPocket) ! for choke pressure drop calculation - !WRITE (*,*) 'kick weight, pressure & density', GasPocketWeight%Array(NoGasPocket), GasPocketOldPress%Array(NoGasPocket), FlowEl(i)%Density ELSE ! gas pocket is escaped from the well completely WRITE (*,*) ' Last Pocket Removed' - WRITE (*,*) ' GasPocketFlowEl', GasPocketFlowEl - CALL RemoveGasPocket(NoGasPocket) + WRITE (*,*) ' GasPocketFlowEl', KickVARIABLES%GasPocketFlowEl + CALL RemoveGasPocket(KickVARIABLES%NoGasPocket) !WRITE (*,*) ' GasPocketFlowEl', GasPocketFlowEl END IF - ELSE IF (NoGasPocket == 1 .OR. WellHeadOpen) THEN ! kick is not last element of choke line or well head is closed - !WRITE (*,*) ' Gas Kick Pressure (psi) (before) = ' , GasPocketNewPress(1) - !DO j = 1 , NoGasPocket + ELSE IF (KickVARIABLES%NoGasPocket == 1 .OR. KickVARIABLES%WellHeadOpen) THEN ! kick is not last element of choke line or well head is closed GasPocketNewPress%Array(:) = GasPocketNewPress%Array(:) * REAL(GasPocketNewVol%Array(:) / GasPocketOldVol%Array(:)) GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:) - !WRITE (*,*) ' Gas Kick Pressure (psi) (after) = ' , GasPocketOldPress(1), REAL(GasPocketNewVol(1) / GasPocketOldVol(1)) - !END DO ELSE ! Many gas pocket is in the well and well head is closed 103 FORMAT (2I, 4X, (F9.3), 5X, (F9.3)) - !WRITE (*,*) 'Before 0' - !DO i = 1 , NoGasPocket - ! WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL(GasPocketNewVol%Array(i) * Convft3toUSgal), REAL(GasPocketOldVol%Array(i) * Convft3toUSgal) - !END DO - GasPocketNewPress%Array(NoGasPocket) = GasPocketOldPress%Array(NoGasPocket) - GasPocketNewVol%Array(NoGasPocket) = GasPocketCompressibility%Array(NoGasPocket) * GasType(KickGasType)%GasConstant * & - GasPocketNewTemp%Array(NoGasPocket) * GasPocketWeight%Array(NoGasPocket) / GasPocketNewPress%Array(NoGasPocket) - + GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) = GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) + GasPocketNewVol%Array(KickVARIABLES%NoGasPocket) = GasPocketCompressibility%Array(KickVARIABLES%NoGasPocket) * GasType(KickVARIABLES%KickGasType)%GasConstant * & + GasPocketNewTemp%Array(KickVARIABLES%NoGasPocket) * GasPocketWeight%Array(KickVARIABLES%NoGasPocket) / GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) - !GasPocketNewPress%Array(:) = GasPocketNewPress%Array(:) * REAL(GasPocketNewVol%Array(:) / GasPocketOldVol%Array(:)) - !GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) - !WRITE (*,*) 'Before 1' - !DO i = 1 , NoGasPocket - ! WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL((GasPocketNewVol%Array(i) * Convft3toUSgal)) - !END DO !WRITE (*,*) 'Mid' DO WHILE (ABS(PressureCorrection * 10.0) > KickConvergenceTolerance) - DO j = NoGasPocket - 1 , 1 , -1 + DO j = KickVARIABLES%NoGasPocket - 1 , 1 , -1 CALL KickFunctionsCalculator(GasPocketNewPress%Array(j) , j , 5) - GasPocketNewVol%Array(j) = GasPocketCompressibility%Array(j) * GasType(KickGasType)%GasConstant * & + GasPocketNewVol%Array(j) = GasPocketCompressibility%Array(j) * GasType(KickVARIABLES%KickGasType)%GasConstant * & GasPocketNewTemp%Array(j) * GasPocketWeight%Array(j) / GasPocketNewPress%Array(j) !WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal) END DO PressureCorrection = (SUM(GasPocketNewVol%Array(:)) - SUM(GasPocketOldVol%Array(:))) / SUM(GasPocketNewVol%Array(:) / GasPocketNewPress%Array(:)) - GasPocketNewPress%Array(NoGasPocket) = GasPocketNewPress%Array(NoGasPocket) + PressureCorrection - GasPocketNewVol%Array(NoGasPocket) = GasPocketCompressibility%Array(NoGasPocket) * GasType(KickGasType)%GasConstant * & - GasPocketNewTemp%Array(NoGasPocket) * GasPocketWeight%Array(NoGasPocket) / GasPocketNewPress%Array(NoGasPocket) - j = NoGasPocket + GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) = GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) + PressureCorrection + GasPocketNewVol%Array(KickVARIABLES%NoGasPocket) = GasPocketCompressibility%Array(KickVARIABLES%NoGasPocket) * GasType(KickVARIABLES%KickGasType)%GasConstant * & + GasPocketNewTemp%Array(KickVARIABLES%NoGasPocket) * GasPocketWeight%Array(KickVARIABLES%NoGasPocket) / GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) + j = KickVARIABLES%NoGasPocket !WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal) END DO !WRITE (*,*) 'Pressure Correction = ', PressureCorrection WRITE (*,*) 'After' - DO i = 1 , NoGasPocket + DO i = 1 , KickVARIABLES%NoGasPocket WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL((GasPocketNewVol%Array(i) * Convft3toUSgal)) END DO @@ -681,7 +616,7 @@ SUBROUTINE GasPocketFlowElementTransformer END IF - IF (GasPocketFlowEl(NoGasPocket , 1) == 0) THEN + IF (KickVARIABLES%GasPocketFlowEl(KickVARIABLES%NoGasPocket , 1) == 0) THEN CALL RemoveGasPocket(1) !WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl @@ -704,14 +639,14 @@ SUBROUTINE GasPocketFlowElementTransformer SUBROUTINE RemoveGasPocket(ilocal) - USE KickVARIABLES + use KickVARIABLESModule USE MudSystemVARIABLES IMPLICIT NONE INTEGER :: ilocal - DEALLOCATE(KickJacobian , OldKickJacobian , KickVandPFunction , KickUnknownVector , KickCorrectionVector) + DEALLOCATE(KickVARIABLES%KickJacobian , KickVARIABLES%OldKickJacobian , KickVARIABLES%KickVandPFunction , KickVARIABLES%KickUnknownVector , KickVARIABLES%KickCorrectionVector) WRITE (*,*) 'Gas Pocket Will be Removed', ilocal @@ -728,19 +663,19 @@ SUBROUTINE RemoveGasPocket(ilocal) call GasPocketDensity%Remove(ilocal) call GasPocketCompressibility%Remove(ilocal) - NoGasPocket = NoGasPocket - 1 + KickVARIABLES%NoGasPocket = KickVARIABLES%NoGasPocket - 1 - IF (NoGasPocket > 0) THEN - ALLOCATE(KickJacobian(2 * NoGasPocket , 2 * NoGasPocket) , OldKickJacobian(2 * NoGasPocket , 2 * NoGasPocket) , KickVandPFunction(2 * NoGasPocket)) - ALLOCATE(KickUnknownVector(2 * NoGasPocket) , KickCorrectionVector(2 * NoGasPocket)) - - IF (ALLOCATED(GasPocketFlowEl)) THEN - ALLOCATE(tempGasPocketFlowEl(NoGasPocket , SIZE(GasPocketFlowEl , dim = 2))) - tempGasPocketFlowEl = GasPocketFlowEl(1 : NoGasPocket , :) - DEALLOCATE(GasPocketFlowEl) - ALLOCATE(GasPocketFlowEl(SIZE(tempGasPocketFlowEl , dim = 1) , SIZE(tempGasPocketFlowEl , dim = 2))) - GasPocketFlowEl = tempGasPocketFlowEl - DEALLOCATE(tempGasPocketFlowEl) + IF (KickVARIABLES%NoGasPocket > 0) THEN + ALLOCATE(KickVARIABLES%KickJacobian(2 * KickVARIABLES%NoGasPocket , 2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%OldKickJacobian(2 * KickVARIABLES%NoGasPocket , 2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%KickVandPFunction(2 * KickVARIABLES%NoGasPocket)) + ALLOCATE(KickVARIABLES%KickUnknownVector(2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%KickCorrectionVector(2 * KickVARIABLES%NoGasPocket)) + + IF (ALLOCATED(KickVARIABLES%GasPocketFlowEl)) THEN + ALLOCATE(KickVARIABLES%tempGasPocketFlowEl(KickVARIABLES%NoGasPocket , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2))) + KickVARIABLES%tempGasPocketFlowEl = KickVARIABLES%GasPocketFlowEl(1 : KickVARIABLES%NoGasPocket , :) + DEALLOCATE(KickVARIABLES%GasPocketFlowEl) + ALLOCATE(KickVARIABLES%GasPocketFlowEl(SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2))) + KickVARIABLES%GasPocketFlowEl = KickVARIABLES%tempGasPocketFlowEl + DEALLOCATE(KickVARIABLES%tempGasPocketFlowEl) END IF ELSE ! NoGasPocket = 0 diff --git a/FluidFlow/kick/Formation_Information.f90 b/FluidFlow/kick/Formation_Information.f90 index 1341cc6..b11e59e 100644 --- a/FluidFlow/kick/Formation_Information.f90 +++ b/FluidFlow/kick/Formation_Information.f90 @@ -1,46 +1,45 @@ SUBROUTINE FormationInformationCalculator - USE KickVariables + use KickVARIABLESModule Use TD_WellGeometry Use CReservoirVariables Use CFormationVariables - Use ConfigurationVariables USE Fluid_Flow_Startup_Vars USE CLog2 USE CDownHoleVariables USE MudSystemVARIABLES - + use ConfigurationVariables IMPLICIT NONE INTEGER :: i REAL(8) :: WellGeoTopTVD - KickGasType = 1 ! methane + KickVARIABLES%KickGasType = 1 ! methane !==================================================== ! Formation Length Calculation !==================================================== WellGeoTopTVD = 0. - KickFormTopMD = 0. - KickFormDownMD = 0. + KickVARIABLES%KickFormTopMD = 0. + KickVARIABLES%KickFormDownMD = 0. !===> Top Measured Depth of Formation Do i = 1 , TD_WellGeneral%WellIntervalsCount if ( Reservoir%FormationTop >= TD_WellGeo(i)%VerticalDepth ) then - KickFormTopMD = KickFormTopMD + TD_WellGeo(i)%IntervalLength + KickVARIABLES%KickFormTopMD = KickVARIABLES%KickFormTopMD + TD_WellGeo(i)%IntervalLength !WRITE (*,*) ' here 11' , TD_WellGeo(i)%IntervalLength !WRITE (*,*) ' here v11' , TD_WellGeo(i)%VerticalDepth WellGeoTopTVD = TD_WellGeo(i)%VerticalDepth else if ( Reservoir%FormationTop < TD_WellGeo(i)%VerticalDepth ) then if ( TD_WellGeo(i)%HoleType == 0 ) then - KickFormTopMD = KickFormTopMD + ((Reservoir%FormationTop - WellGeoTopTVD)& + KickVARIABLES%KickFormTopMD = KickVARIABLES%KickFormTopMD + ((Reservoir%FormationTop - WellGeoTopTVD)& / cos(TD_WellGeo(i)%StartAngle)) !WRITE (*,*) ' here 12' , (FormationTop - WellGeoTopTVD) / cos(TD_WellGeo(i)%StartAngle) else - KickFormTopMD = KickFormTopMD + (TD_WellGeo(i)%RCurvature & + KickVARIABLES%KickFormTopMD = KickVARIABLES%KickFormTopMD + (TD_WellGeo(i)%RCurvature & * Asin((Reservoir%FormationTop - WellGeoTopTVD) / TD_WellGeo(i)%RCurvature)) !WRITE (*,*) ' here 13' , TD_WellGeo(i)%RCurvature * Asin((FormationTop - WellGeoTopTVD) / TD_WellGeo(i)%RCurvature) @@ -53,14 +52,14 @@ SUBROUTINE FormationInformationCalculator WellGeoTopTVD = 0. Do i = 1 , TD_WellGeneral%WellIntervalsCount if ( (Reservoir%FormationTop + Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness)>=TD_WellGeo(i)%VerticalDepth ) then - KickFormDownMD = KickFormDownMD + TD_WellGeo(i)%IntervalLength + KickVARIABLES%KickFormDownMD = KickVARIABLES%KickFormDownMD + TD_WellGeo(i)%IntervalLength WellGeoTopTVD = TD_WellGeo(i)%VerticalDepth else if ( (Reservoir%FormationTop+Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness) Determination of Formation Length for Kick Modeling if (TD_WellGeneral%WellTotalVerticalLength >= Reservoir%FormationTop .AND. TD_WellGeneral%WellTotalVerticalLength < (Reservoir%FormationTop+Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness)) then - KickFormLength = TD_WellGeneral%WellTotalLength - KickFormTopMD ![ft] + KickVARIABLES%KickFormLength = TD_WellGeneral%WellTotalLength - KickVARIABLES%KickFormTopMD ![ft] else if ( TD_WellGeneral%WellTotalVerticalLength >= (Reservoir%FormationTop + Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness) ) then - KickFormLength = KickFormDownMD - KickFormTopMD ![ft] + KickVARIABLES%KickFormLength = KickVARIABLES%KickFormDownMD - KickVARIABLES%KickFormTopMD ![ft] else - KickFormLength = 0. + KickVARIABLES%KickFormLength = 0. end if - !PermeabilityExposedHeight = KickFormLength * FormationPermeability + !PermeabilityExposedHeight = KickVARIABLES%KickFormLength * FormationPermeability DownHole%PermeabilityExposedHeight = MudSystem%FluidFlowCounter - MudSystem%MudSys_timeCounter !==================================================== ! Reservoir Data !==================================================== - FormPermeability = Reservoir%FormationPermeability ! [mD] + KickVARIABLES%FormPermeability = Reservoir%FormationPermeability ! [mD] - FormPressure = TD_WellGeneral%WellTotalVerticalLength * Configuration%Formation%Formations(Reservoir%FormationNo)%PorePressureGradient ![psia] - DownHole%FormationPressure = INT(FormPressure) - !CALL Log_2('FormPressure =' , FormPressure) + KickVARIABLES%FormPressure = TD_WellGeneral%WellTotalVerticalLength * Configuration%Formation%Formations(Reservoir%FormationNo)%PorePressureGradient ![psia] + DownHole%FormationPressure = INT(KickVARIABLES%FormPressure) + !CALL Log_2('FormPressure =' , KickVARIABLES%FormPressure) !print*, 'Formations(FormationNo)%PorePressureGradient=', Formations(FormationNo)%PorePressureGradient !print * , 'FormationNo=' , FormationNo !print * , 'TD_WellGeneral%WellTotalVerticalLength=' , TD_WellGeneral%WellTotalVerticalLength - FormTemperature = 600 ! [Ra] - !WRITE (*,*) ' Formation pressure ' , FormPressure + KickVARIABLES%FormTemperature = 600 ! [Ra] + !WRITE (*,*) ' Formation pressure ' , KickVARIABLES%FormPressure !==================================================== ! Gas Properties (Methane Gas) !==================================================== - GasResTemperature = FormTemperature - GasResPressure = FormPressure + KickVARIABLES%GasResTemperature = KickVARIABLES%FormTemperature + KickVARIABLES%GasResPressure = KickVARIABLES%FormPressure !!!! Methane , Gas type =1 - GasKickMolarMass = GasType(KickGasType)%MolarWt ! Methane Gas [gr/mol] - GasSpecGravity = GasKickMolarMass / GasDensityRefrence + KickVARIABLES%GasKickMolarMass = GasType(KickVARIABLES%KickGasType)%MolarWt ! Methane Gas [gr/mol] + KickVARIABLES%GasSpecGravity = KickVARIABLES%GasKickMolarMass / GasDensityRefrence - KickTc = GasType(KickGasType)%CritTemp - KickPc = GasType(KickGasType)%CritPress + KickVARIABLES%KickTc = GasType(KickVARIABLES%KickGasType)%CritTemp + KickVARIABLES%KickPc = GasType(KickVARIABLES%KickGasType)%CritPress !!!!!!!! Calculating Compressibility, viscosity for influx condition (Average of reservoir and bottomhole) - KickTr = GasResTemperature / KickTc - KickPr = GasResPressure / KickPc + KickVARIABLES%KickTr = KickVARIABLES%GasResTemperature / KickVARIABLES%KickTc + KickVARIABLES%KickPr = KickVARIABLES%GasResPressure / KickVARIABLES%KickPc - K_A_Res = 3.53 * KickPr - K_B_Res = 10.0**(0.9813 * KickTr) - K_C_Res = 0.274 * (KickPr**2) - K_D_Res = 10.0**(0.8157 * KickTr) + KickVARIABLES%K_A_Res = 3.53 * KickVARIABLES%KickPr + KickVARIABLES%K_B_Res = 10.0**(0.9813 * KickVARIABLES%KickTr) + KickVARIABLES%K_C_Res = 0.274 * (KickVARIABLES%KickPr**2) + KickVARIABLES%K_D_Res = 10.0**(0.8157 * KickVARIABLES%KickTr) - GasResCompressibility = 0.98 !1. - (K_A_Res / K_B_Res) + (K_C_Res / K_D_Res) + KickVARIABLES%GasResCompressibility = 0.98 !1. - (K_A_Res / K_B_Res) + (K_C_Res / K_D_Res) - GasReservoirDensity = GasResPressure / (GasResCompressibility * & - GasResTemperature * GasType(KickGasType)%GasConstant) / Convft3toUSgal ! [ppg] + KickVARIABLES%GasReservoirDensity = KickVARIABLES%GasResPressure / (KickVARIABLES%GasResCompressibility * & + KickVARIABLES%GasResTemperature * GasType(KickVARIABLES%KickGasType)%GasConstant) / Convft3toUSgal ! [ppg] END SUBROUTINE \ No newline at end of file diff --git a/FluidFlow/kick/Gas_Kick_Calculator.f90 b/FluidFlow/kick/Gas_Kick_Calculator.f90 index bd8df89..b2192fc 100644 --- a/FluidFlow/kick/Gas_Kick_Calculator.f90 +++ b/FluidFlow/kick/Gas_Kick_Calculator.f90 @@ -1,12 +1,12 @@ SUBROUTINE GasKickCalculator - USE KickVariables + use KickVARIABLESModule Use TD_WellGeometry Use CReservoirVariables Use CFormationVariables USE Fluid_Flow_Startup_Vars - USE PressureDisplayVARIABLES - USE FricPressDropVars + use PressureDisplayVARIABLESModule + USE FricPressDropVarsModule USE MudSystemVARIABLES USE CMudPropertiesVariables USE CError @@ -22,212 +22,183 @@ SUBROUTINE GasKickCalculator INTEGER :: i , j , k , l - SolvingEquationError = .FALSE. - KickVandPFunction(:) = 0.d0 - KickJacobian(: , :) = 0.d0 + KickVARIABLES%SolvingEquationError = .FALSE. + KickVARIABLES%KickVandPFunction(:) = 0.d0 + KickVARIABLES%KickJacobian(: , :) = 0.d0 !==================================================== ! Gas Properties (Methane Gas) !==================================================== !GasPocketNewTemp%Array(1) = 600 - BottomHoleTemperature = 600 - KickFluxAvgPressure = (BottomHolePress + FormPressure) / 2 + StandardPress - KickFluxAvgTemperature = (FormTemperature + BottomHoleTemperature) / 2 - KickFluxAvgCompressibility = 0.98d0 - - K_Aa = (5.8742362 * 10.**(-3) * KickFluxAvgTemperature**1.2288) / (511.1728532 + KickFluxAvgTemperature) - K_Bb = 5.5565586 + (1000.01 / KickFluxAvgTemperature) - K_Cc = 2.47862 - 0.12294 * K_Bb - GasKickSIDensity = KickFluxAvgPressure / (KickFluxAvgCompressibility * & - KickFluxAvgTemperature * GasType(KickGasType)%GasConstant) * Convpcftogpcm3 - - GasKickViscosity = K_Aa * EXP(K_Bb * GasKickSIDensity**K_Cc) + KickVARIABLES%BottomHoleTemperature = 600 + KickVARIABLES%KickFluxAvgPressure = (KickVARIABLES%BottomHolePress + KickVARIABLES%FormPressure) / 2 + StandardPress + KickVARIABLES%KickFluxAvgTemperature = (KickVARIABLES%FormTemperature + KickVARIABLES%BottomHoleTemperature) / 2 + KickVARIABLES%KickFluxAvgCompressibility = 0.98d0 + + KickVARIABLES%K_Aa = (5.8742362 * 10.**(-3) * KickVARIABLES%KickFluxAvgTemperature**1.2288) / (511.1728532 + KickVARIABLES%KickFluxAvgTemperature) + KickVARIABLES%K_Bb = 5.5565586 + (1000.01 / KickVARIABLES%KickFluxAvgTemperature) + KickVARIABLES%K_Cc = 2.47862 - 0.12294 * KickVARIABLES%K_Bb + KickVARIABLES%GasKickSIDensity = KickVARIABLES%KickFluxAvgPressure / (KickVARIABLES%KickFluxAvgCompressibility * & + KickVARIABLES%KickFluxAvgTemperature * GasType(KickVARIABLES%KickGasType)%GasConstant) * Convpcftogpcm3 + + KickVARIABLES%GasKickViscosity = KickVARIABLES%K_Aa * EXP(KickVARIABLES%K_Bb * KickVARIABLES%GasKickSIDensity**KickVARIABLES%K_Cc) !!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!! Calculating compressibility for bottom hole condition - !K_BHTpr = BottomHoleTemperature / KickTc - !K_BHPpr = (BottomHolePress + StandardPress) / KickPc - - !K_A_Bottomhole = 3.53 * K_BHPpr - !K_B_Bottomhole = 10.0**(0.9813 * K_BHTpr) - !K_C_Bottomhole = 0.274 * (K_BHPpr**2) - !K_D_Bottomhole = 10.0**(0.8157 * K_BHTpr) + - BottomHoleCompressibility = 0.98d0 !1. - (K_A_Bottomhole / K_B_Bottomhole) + (K_C_Bottomhole / K_D_Bottomhole) + KickVARIABLES%BottomHoleCompressibility = 0.98d0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - GasKickBg = 0.00504 * KickFluxAvgCompressibility * KickFluxAvgTemperature / KickFluxAvgPressure ![bbl/SCF] + KickVARIABLES%GasKickBg = 0.00504 * KickVARIABLES%KickFluxAvgCompressibility * KickVARIABLES%KickFluxAvgTemperature / KickVARIABLES%KickFluxAvgPressure ![bbl/SCF] !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !WRITE (*,*) 'Gas Kick Top' !===> Kick Flow Rate Calculation - IF (FormPressure > BottomHolePress) THEN - KickmdotACoef = 10.0**(-8) * 1.15741d0 * 7.080 * FormPermeability * REAL(KickFormLength) * GasType(KickGasType)%StDensity / & - (GasKickViscosity * GasKickBg * LOG(10000.0)) - !IF (WellHeadOpen .AND. NoGasPocket == 1) KickmdotACoef = (1.d0 + 2.d0) * KickmdotACoef + IF (KickVARIABLES%FormPressure > KickVARIABLES%BottomHolePress) THEN + KickVARIABLES%KickmdotACoef = 10.0**(-8) * 1.15741d0 * 7.080 * KickVARIABLES%FormPermeability * REAL(KickVARIABLES%KickFormLength) * GasType(KickVARIABLES%KickGasType)%StDensity / & + (KickVARIABLES%GasKickViscosity * KickVARIABLES%GasKickBg * LOG(10000.0)) + !IF (WellHeadOpen .AND. NoGasPocket == 1) KickVARIABLES%KickmdotACoef = (1.d0 + 2.d0) * KickmdotACoef ELSE - KickmdotACoef = 0.0 + KickVARIABLES%KickmdotACoef = 0.0 END IF - i = StringLastEl - j = OpenholeFirstEl - 1 - k = GasPocketFlowEl(1 , 1) - KickmdotBCoef = FormPressure + StandardPress !! - Sum(static and friction pressure loss) of flow elements below gas pocket, see below - IF (FormPressure > BottomHolePress) THEN + i = FricPressDropVars%StringLastEl + j = FricPressDropVars%OpenholeFirstEl - 1 + k = KickVARIABLES%GasPocketFlowEl(1 , 1) + KickVARIABLES%KickmdotBCoef = KickVARIABLES%FormPressure + StandardPress !! - Sum(static and friction pressure loss) of flow elements below gas pocket, see below + IF (KickVARIABLES%FormPressure > KickVARIABLES%BottomHolePress) THEN !WRITE (*,*) 'k , i, j' , k , i, j - IF (k >= OpenholeFirstEl) THEN ! Bottom of active kick is in openhole - KickmdotBCoef = KickmdotBCoef - (SUM(FlowEl(OpenholeFirstEl : k)%StaticPressDiff)) !+ SUM(FlowEl(j + 1 : GasPocketFlowEl(1 , 1) - 1)%FricPressLoss + IF (k >= FricPressDropVars%OpenholeFirstEl) THEN ! Bottom of active kick is in openhole + KickVARIABLES%KickmdotBCoef = KickVARIABLES%KickmdotBCoef - (SUM(FlowEl(FricPressDropVars%OpenholeFirstEl : k)%StaticPressDiff)) !+ SUM(FlowEl(j + 1 : GasPocketFlowEl(1 , 1) - 1)%FricPressLoss !WRITE (*,*) '1 SUM(FlowEl(j + 1 : k)%FricPressLoss', k, SUM(FlowEl(j + 1 : k)%FricPressLoss) - ELSE IF (k < OpenholeFirstEl) THEN ! bottom of 1st gas pocket (active kick) is in annulus ond/or choke line only - KickmdotBCoef = KickmdotBCoef - SUM(FlowEl(OpenholeFirstEl : NumbEl)%StaticPressDiff) & - - (SUM(FlowEl(AnnulusFirstEl : k)%StaticPressDiff) + SUM(FlowEl(AnnulusFirstEl : k)%FricPressLoss)) - !WRITE (*,*) '2 SUM(FlowEl(j + 1 : NumbEl)%FricPressLoss', k, SUM(FlowEl(j + 1 : NumbEl)%FricPressLoss) + ELSE IF (k < FricPressDropVars%OpenholeFirstEl) THEN ! bottom of 1st gas pocket (active kick) is in annulus ond/or choke line only + KickVARIABLES%KickmdotBCoef = KickVARIABLES%KickmdotBCoef - SUM(FlowEl(FricPressDropVars%OpenholeFirstEl : FricPressDropVars%NumbEl)%StaticPressDiff) & + - (SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : k)%StaticPressDiff) + SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : k)%FricPressLoss)) END IF - !WRITE (*,*) ' KickmdotBCoef=', KickmdotBCoef END IF - !WRITE (*,*) 'Kick A, B', KickmdotACoef, KickmdotBCoef - DO l = 1 , NoGasPocket - KickUnknownVector(2 * l - 1) = GasPocketNewVol%Array(l) - KickUnknownVector(2 * l) = GasPocketNewPress%Array(l) + DO l = 1 , KickVARIABLES%NoGasPocket + KickVARIABLES%KickUnknownVector(2 * l - 1) = GasPocketNewVol%Array(l) + KickVARIABLES%KickUnknownVector(2 * l) = GasPocketNewPress%Array(l) END DO - IF (WellHeadOpen) THEN + IF (KickVARIABLES%WellHeadOpen) THEN !!!!!!!!!! Calculation of functions of pocket Pressure and gas Volumes !IF (GasPocketElementNo(1) > 0) WRITE (*,*) ' GasPocketElementNo(1) ' , GasPocketElementNo(1) !WRITE (*,*) ' Kick Unknown Vector' , KickUnknownVector!(1) , KickUnknownVector(2) IF (KickIteration == 1) THEN ! updating initial guess based on previous time step data - DO l = 1 , NoGasPocket - KickUnknownVector(2 * l - 1) = KickUnknownVector(2 * l - 1) + GasPocketDeltaVol%Array(l) + DO l = 1 , KickVARIABLES%NoGasPocket + KickVARIABLES%KickUnknownVector(2 * l - 1) = KickVARIABLES%KickUnknownVector(2 * l - 1) + GasPocketDeltaVol%Array(l) END DO END IF - KickVandPFunction(1) = KickUnknownVector(1) - GasPocketCompressibility%Array(1) * GasType(KickGasType)%GasConstant * & ! VandP(1) = V(1) - GasPocketNewTemp%Array(1) * (GasPocketWeight%Array(1) + KickmdotACoef * MAX(((KickmdotBCoef - KickUnknownVector(2)) * dt) , 0.0)) / KickUnknownVector(2) + KickVARIABLES%KickVandPFunction(1) = KickVARIABLES%KickUnknownVector(1) - GasPocketCompressibility%Array(1) * GasType(KickVARIABLES%KickGasType)%GasConstant * & ! VandP(1) = V(1) + GasPocketNewTemp%Array(1) * (GasPocketWeight%Array(1) + KickVARIABLES%KickmdotACoef * MAX(((KickVARIABLES%KickmdotBCoef - KickVARIABLES%KickUnknownVector(2)) * dt) , 0.0)) / KickVARIABLES%KickUnknownVector(2) !WRITE (*,*) 'KickVandPFunction(1)',KickVandPFunction(1) - l = 2 * NoGasPocket - CALL KickFunctionsCalculator(KickVandPFunction(l) , NoGasPocket , 2) ! VandP(last) = P(last) + l = 2 * KickVARIABLES%NoGasPocket + CALL KickFunctionsCalculator(KickVARIABLES%KickVandPFunction(l) , KickVARIABLES%NoGasPocket , 2) ! VandP(last) = P(last) !WRITE (*,*) 'KickVandPFunction(l)', l, KickVandPFunction(l) - DO l = 2 , NoGasPocket ! VandP(Odd) = V(l, l > 1) - KickVandPFunction(2 * l - 1) = KickUnknownVector(2 * l - 1) - GasPocketCompressibility%Array(l) * GasType(KickGasType)%GasConstant * & - GasPocketNewTemp%Array(l) * GasPocketWeight%Array(l) / KickUnknownVector(2 * l) + DO l = 2 , KickVARIABLES%NoGasPocket ! VandP(Odd) = V(l, l > 1) + KickVARIABLES%KickVandPFunction(2 * l - 1) = KickVARIABLES%KickUnknownVector(2 * l - 1) - GasPocketCompressibility%Array(l) * GasType(KickVARIABLES%KickGasType)%GasConstant * & + GasPocketNewTemp%Array(l) * GasPocketWeight%Array(l) / KickVARIABLES%KickUnknownVector(2 * l) !WRITE(*,*) 'KickVandPFunction(V)', l, KickVandPFunction(2 * l - 1) END DO - DO l = NoGasPocket - 1 , 1 , -1 - CALL KickFunctionsCalculator(KickVandPFunction(2 * l) , l , 1) ! VandP(Even) = P(l, l < NoGasPocket) + DO l = KickVARIABLES%NoGasPocket - 1 , 1 , -1 + CALL KickFunctionsCalculator(KickVARIABLES%KickVandPFunction(2 * l) , l , 1) ! VandP(Even) = P(l, l < KickVARIABLES%NoGasPocket) !WRITE(*,*) 'KickVandPFunction(P)', l , KickVandPFunction(2 * l) END DO !!!!!!!!!! END - Calculation of functions of pocket Pressure and gas Volumes !!!!!!!!!! Calculation of Jacobian - DO k = 1 , 2 * NoGasPocket ! Main Diagonal - KickJacobian(k , k) = 1.d0 + DO k = 1 , 2 * KickVARIABLES%NoGasPocket ! Main Diagonal + KickVARIABLES%KickJacobian(k , k) = 1.d0 END DO - KickJacobian(1,2) = (GasPocketCompressibility%Array(1) * GasType(KickGasType)%GasConstant * GasPocketNewTemp%Array(1) & - * (GasPocketWeight%Array(1) + KickmdotACoef * KickmdotBCoef * dt) / KickUnknownVector(2)**2) ! Row 1 Finished - IF (KickJacobian(1,2) == 0.d0) THEN + KickVARIABLES%KickJacobian(1,2) = (GasPocketCompressibility%Array(1) * GasType(KickVARIABLES%KickGasType)%GasConstant * GasPocketNewTemp%Array(1) & + * (GasPocketWeight%Array(1) + KickVARIABLES%KickmdotACoef * KickVARIABLES%KickmdotBCoef * dt) / KickVARIABLES%KickUnknownVector(2)**2) ! Row 1 Finished + IF (KickVARIABLES%KickJacobian(1,2) == 0.d0) THEN CALL Error('KickJacobian(1,2) = 0.0') - KickJacobian(1,2) = OldKickJacobian(1,2) + KickVARIABLES%KickJacobian(1,2) = KickVARIABLES%OldKickJacobian(1,2) END IF !WRITE(*,*) 'KickJacobian(1,2)', KickJacobian(1,2) - l = NoGasPocket - CALL KickFunctionsCalculator(KickJacobian(2 * l , 2 * l - 1) , NoGasPocket , 4) ! for last Row - IF (KickJacobian(2 * l , 2 * l - 1) == 0.d0) THEN + l = KickVARIABLES%NoGasPocket + CALL KickFunctionsCalculator(KickVARIABLES%KickJacobian(2 * l , 2 * l - 1) , KickVARIABLES%NoGasPocket , 4) ! for last Row + IF (KickVARIABLES%KickJacobian(2 * l , 2 * l - 1) == 0.d0) THEN CALL Error ('KickJacobian(Last,Odd) = 0.0') - KickJacobian(2 * l , 2 * l - 1) = OldKickJacobian(2 * l , 2 * l - 1) + KickVARIABLES%KickJacobian(2 * l , 2 * l - 1) = KickVARIABLES%OldKickJacobian(2 * l , 2 * l - 1) END IF - DO k = NoGasPocket - 1 , 1 , -1 - KickJacobian(2 * l , 2 * k - 1) = KickJacobian(2 * l , 2 * l - 1) + DO k = KickVARIABLES%NoGasPocket - 1 , 1 , -1 + KickVARIABLES%KickJacobian(2 * l , 2 * k - 1) = KickVARIABLES%KickJacobian(2 * l , 2 * l - 1) END DO ! Last Row Finished !WRITE(*,*) 'KickJacobian(2,1)', KickJacobian(2,1) - DO k = 2 , NoGasPocket - KickJacobian(2 * k - 1 , 2 * k) = GasPocketCompressibility%Array(k) * GasType(KickGasType)%GasConstant * GasPocketNewTemp%Array(k) & - * GasPocketWeight%Array(k) / KickUnknownVector(2 * k)**2 + DO k = 2 , KickVARIABLES%NoGasPocket + KickVARIABLES%KickJacobian(2 * k - 1 , 2 * k) = GasPocketCompressibility%Array(k) * GasType(KickVARIABLES%KickGasType)%GasConstant * GasPocketNewTemp%Array(k) & + * GasPocketWeight%Array(k) / KickVARIABLES%KickUnknownVector(2 * k)**2 END DO ! Odd Rows (V equations) Finished - DO k = 1 , NoGasPocket - 1 - KickJacobian(2 * k , 2 * k + 2) = -1.d0 + DO k = 1 , KickVARIABLES%NoGasPocket - 1 + KickVARIABLES%KickJacobian(2 * k , 2 * k + 2) = -1.d0 END DO ! Even Rows (P equations) effect of upper pocket - DO k = 2 , 2 * (NoGasPocket - 1) , 2 + DO k = 2 , 2 * (KickVARIABLES%NoGasPocket - 1) , 2 DO l = 1 , k - 1 , 2 - CALL KickFunctionsCalculator(KickJacobian(k , l) , k / 2 , 3) - IF (KickJacobian(k , l) == 0.d0) THEN + CALL KickFunctionsCalculator(KickVARIABLES%KickJacobian(k , l) , k / 2 , 3) + IF (KickVARIABLES%KickJacobian(k , l) == 0.d0) THEN WRITE (*,*) 'Jacobian Array = 0.0', k , l CALL Error ('KickJacobian(k , l) = 0.0') - KickJacobian(k , l) = OldKickJacobian(k , l) + KickVARIABLES%KickJacobian(k , l) = KickVARIABLES%OldKickJacobian(k , l) END IF END DO END DO - IF (ANY(IEEE_IS_NaN(KickJacobian))) CALL ErrorStop ('NaN in calculating Kick Jacobian, Call your Service Provider') + IF (ANY(IEEE_IS_NaN(KickVARIABLES%KickJacobian))) CALL ErrorStop ('NaN in calculating Kick Jacobian, Call your Service Provider') !!!!!!!!!! Solving linear equation in order to finding correction vector for correcting pocket pressure and gas induced flowrates - KickVandPFunction = -1.d0 * KickVandPFunction - !WRITE (*,*) 'Max Remainder', MAXVAL(ABS(KickVandPFunction)) , MAXLOC(ABS(KickVandPFunction)) - !WRITE (*,*) 'SIZE(A , dim = 1), SIZE(A , dim = 2), SIZE(b)', SIZE(KickJacobian , dim = 1), SIZE(KickJacobian , dim = 2), SIZE(KickVandPFunction) - CALL SOLVE_LINEAR_EQUATIONS(KickJacobian , KickCorrectionVector , KickVandPFunction , SolvingEquationError, SIZE(KickCorrectionVector)) - IF (SolvingEquationError) CALL ErrorStop( ' Error in solving kick equation ' ) + KickVARIABLES%KickVandPFunction = -1.d0 * KickVARIABLES%KickVandPFunction + CALL SOLVE_LINEAR_EQUATIONS(KickVARIABLES%KickJacobian , KickVARIABLES%KickCorrectionVector , KickVARIABLES%KickVandPFunction , KickVARIABLES%SolvingEquationError, SIZE(KickVARIABLES%KickCorrectionVector)) + IF (KickVARIABLES%SolvingEquationError) CALL ErrorStop( ' Error in solving kick equation ' ) - KickUnknownVector = KickUnknownVector + KickCorrectionUnderRelaxation * KickCorrectionVector + KickVARIABLES%KickUnknownVector = KickVARIABLES%KickUnknownVector + KickVARIABLES%KickCorrectionUnderRelaxation * KickVARIABLES%KickCorrectionVector - DO l = 1 , NoGasPocket - GasPocketNewVol%Array(l) = KickUnknownVector(2 * l - 1) + DO l = 1 , KickVARIABLES%NoGasPocket + GasPocketNewVol%Array(l) = KickVARIABLES%KickUnknownVector(2 * l - 1) IF (IEEE_IS_NaN(GasPocketNewVol%Array(l))) CALL ErrorStop('Volume of this pocket is Not a Number:', l) IF (GasPocketNewVol%Array(l) <= 0.d0) CALL Error('Volume of this pocket is Negative or Zero:', l) - GasPocketNewPress%Array(l) = KickUnknownVector(2 * l) + GasPocketNewPress%Array(l) = KickVARIABLES%KickUnknownVector(2 * l) IF (IEEE_IS_NaN(GasPocketNewPress%Array(l))) CALL ErrorStop('Pressure of this Pocket is Not a Number:', l) IF (GasPocketNewPress%Array(l) <= 0.d0) CALL ErrorStop('Pressure of this Pocket is Negative or Zero:', l) END DO - !WRITE(*,*) 'GasPocketDeltaVol (gal)' , GasPocketDeltaVol(1) * 7.48 - !WRITE (*,*) 'GasPocketFlowInduced (gpm), GasPocketNewVol' , GasPocketFlowInduced(1), GasPocketNewVol(1) - !IF (Kchoke > 0.0) - !WRITE(*,*) ' New Vol (ft3), New Press (psi)', GasPocketNewVol(1), GasPocketNewPress(1) ELSE ! well haed is closed, so build up process or migration occurs !WRITE (*,*) 'GasPocketOldPress (before)' , GasPocketOldPress(1) GasPocketNewPress%Array(1) = GasPocketOldPress%Array(1) * & - (REAL((GasPocketWeight%Array(1) + KickmdotACoef * KickmdotBCoef * dt) / (GasPocketWeight%Array(1) + KickmdotACoef * GasPocketOldPress%Array(1) * dt))) - !WRITE (*,*) 'GasPocketNewPress (after)' , GasPocketNewPress(1), ((GasPocketWeight(1) + KickmdotACoef * KickmdotBCoef * dt) / (GasPocketWeight(1) + KickmdotACoef * GasPocketOldPress(1) * dt)) + (REAL((GasPocketWeight%Array(1) + KickVARIABLES%KickmdotACoef * KickVARIABLES%KickmdotBCoef * dt) / (GasPocketWeight%Array(1) + KickVARIABLES%KickmdotACoef * GasPocketOldPress%Array(1) * dt))) - !WRITE (*,*) ' Well head is closed, GasPocketNewPress =' , GasPocketNewPress(1) - !WRITE (*,*) 'Old Press, Weight, A, B' , GasPocketOldPress(1), GasPocketWeight(1), KickmdotACoef, KickmdotBCoef - !WRITE (*,*) 'Numerator and denumerator Gas kick' , KickmdotACoef * KickmdotBCoef * dt , KickmdotACoef * GasPocketOldPress(1) * dt - - !WRITE (*,*) ' Gas Kick Volume (ft^3) = ' , GasPocketNewVol(1) END IF - !DO l = 1 , NoGasPocket + !DO l = 1 , KickVARIABLES%NoGasPocket GasPocketDeltaVol%Array(:) = GasPocketNewVol%Array(:) - GasPocketOldVol%Array(:) GasPocketFlowInduced%Array(:) = (GasPocketDeltaVol%Array(:)) / dt * 448.8 ! gpm !END DO - GasKickPumpFlowRate = 0.0 - IF (NOT(KickOffBottom) .AND. WellHeadOpen) GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) + KickVARIABLES%GasKickPumpFlowRate = 0.0 + IF (NOT(KickVARIABLES%KickOffBottom) .AND. KickVARIABLES%WellHeadOpen) KickVARIABLES%GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) - !WRITE (*,*) ' No Iteration, KickCorrectionVector =' , KickIteration , KickCorrectionVector(1) , KickCorrectionVector(2) - !WRITE (*,*) ' Kick Jacobian ', REAL(KickJacobian) - !WRITE (*,*) ' KickVandPFunction = ' , REAL(KickVandPFunction) - !WRITE (*,*) ' Kick Unknown Vector = ' , REAL(-KickUnknownVector) - - - - !WRITE (*,*) 'Gas Kick Bottom' END SUBROUTINE @@ -236,8 +207,8 @@ SUBROUTINE GasKickCalculator SUBROUTINE KickFunctionsCalculator(ExitValue , GasPocketNo , CalcMode) - USE KickVARIABLES - USE FricPressDropVars + use KickVARIABLESModule + USE FricPressDropVarsModule USE Fluid_Flow_Startup_Vars USE CError USE , INTRINSIC :: IEEE_Arithmetic @@ -251,10 +222,10 @@ SUBROUTINE GasKickCalculator INTEGER :: y INTEGER :: z , i , j - x = GasPocketFlowEl(GasPocketNo , 1) - IF (GasPocketNo < NoGasPocket) y = GasPocketFlowEl(GasPocketNo + 1 , 1) - i = StringLastEl - j = OpenholeFirstEl - 1 + x = KickVARIABLES%GasPocketFlowEl(GasPocketNo , 1) + IF (GasPocketNo < KickVARIABLES%NoGasPocket) y = KickVARIABLES%GasPocketFlowEl(GasPocketNo + 1 , 1) + i = FricPressDropVars%StringLastEl + j = FricPressDropVars%OpenholeFirstEl - 1 ! Case 1: gas pocket is completely in OP and STARTX of upper gas pocket is also ! Case 2: gas pocket is completely in OP and STARTX of upper gas pocket is above Bit @@ -270,29 +241,29 @@ SUBROUTINE GasKickCalculator IF (CalcMode == 1) THEN ! calculating pressure difference between two pocket, include static pressure difference and frictional ! pressure difference, use in calculating 'KickVandPFunction' - ExitValue = KickUnknownVector(2 * GasPocketNo) - KickUnknownVector(2 * GasPocketNo + 2) - IF (x >= OpenholeFirstEl .AND. y < OpenholeFirstEl) THEN ! Case 2 , Case 3 - ExitValue = ExitValue - SUM(FlowEl(x : NumbEl)%StaticPressDiff) - SUM(FlowEl(x : NumbEl)%FricPressLoss) & - - SUM(FlowEl(AnnulusFirstEl : y)%StaticPressDiff) - SUM(FlowEl(AnnulusFirstEl : y)%FricPressLoss) + ExitValue = KickVARIABLES%KickUnknownVector(2 * GasPocketNo) - KickVARIABLES%KickUnknownVector(2 * GasPocketNo + 2) + IF (x >= FricPressDropVars%OpenholeFirstEl .AND. y < FricPressDropVars%OpenholeFirstEl) THEN ! Case 2 , Case 3 + ExitValue = ExitValue - SUM(FlowEl(x : FricPressDropVars%NumbEl)%StaticPressDiff) - SUM(FlowEl(x : FricPressDropVars%NumbEl)%FricPressLoss) & + - SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : y)%StaticPressDiff) - SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : y)%FricPressLoss) ELSE ! Case 1 , Case 4 ExitValue = ExitValue - SUM(FlowEl(x : y)%StaticPressDiff) - SUM(FlowEl(x : y)%FricPressLoss) END IF ELSE IF (CalcMode == 2) THEN - ExitValue = KickUnknownVector(2 * GasPocketNo) - StandardPress - Kchoke * FlowEl(OpenholeFirstEl - 1)%Flowrate**2 - IF (x >= OpenholeFirstEl) THEN ! Gas Pocket is in Openhole - ExitValue = ExitValue - SUM(FlowEl(x : NumbEl)%StaticPressDiff) - SUM(FlowEl(x : NumbEl)%FricPressLoss) & - - SUM(FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%StaticPressDiff) - SUM(FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FricPressLoss) + ExitValue = KickVARIABLES%KickUnknownVector(2 * GasPocketNo) - StandardPress - FricPressDropVars%Kchoke * FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%Flowrate**2 + IF (x >= FricPressDropVars%OpenholeFirstEl) THEN ! Gas Pocket is in Openhole + ExitValue = ExitValue - SUM(FlowEl(x : FricPressDropVars%NumbEl)%StaticPressDiff) - SUM(FlowEl(x : FricPressDropVars%NumbEl)%FricPressLoss) & + - SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%StaticPressDiff) - SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FricPressLoss) ELSE ! Gas Pocket is in Annulus - ExitValue = ExitValue - SUM(FlowEl(x : OpenholeFirstEl - 1)%StaticPressDiff) - SUM(FlowEl(x : OpenholeFirstEl - 1)%FricPressLoss) + ExitValue = ExitValue - SUM(FlowEl(x : FricPressDropVars%OpenholeFirstEl - 1)%StaticPressDiff) - SUM(FlowEl(x : FricPressDropVars%OpenholeFirstEl - 1)%FricPressLoss) END IF ELSE IF (CalcMode == 3) THEN ! calculating derivative of pressure difference between two pocket, relative to change in flowrate ! use in calculating 'KickJacobian' - IF (x >= OpenholeFirstEl .AND. y < OpenholeFirstEl) THEN ! Top kick STARTX is in Annulus - DO z = x , NumbEl ! open hole elements + IF (x >= FricPressDropVars%OpenholeFirstEl .AND. y < FricPressDropVars%OpenholeFirstEl) THEN ! Top kick STARTX is in Annulus + DO z = x , FricPressDropVars%NumbEl ! open hole elements CALL PartialDerivativeFricToFlowRate(z) IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe @@ -300,7 +271,7 @@ SUBROUTINE GasKickCalculator CALL ErrorStop('NaN in calculating partial derivative') END IF END DO - DO z = AnnulusFirstEl , y ! Annulus elements + DO z = FricPressDropVars%AnnulusFirstEl , y ! Annulus elements CALL PartialDerivativeFricToFlowRate(z) IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe @@ -308,7 +279,7 @@ SUBROUTINE GasKickCalculator CALL ErrorStop('NaN in calculating partial derivative') END IF END DO - ExitValue = ExitValue - (SUM(FlowEl(x : NumbEl)%FricToQPartialDiff) + SUM(FlowEl(AnnulusFirstEl : y)%FricToQPartialDiff)) * 448.8 / dt + ExitValue = ExitValue - (SUM(FlowEl(x : FricPressDropVars%NumbEl)%FricToQPartialDiff) + SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : y)%FricToQPartialDiff)) * 448.8 / dt ELSE ! both pockets are one side of bit DO z = x , y CALL PartialDerivativeFricToFlowRate(z) @@ -323,9 +294,9 @@ SUBROUTINE GasKickCalculator ELSE IF (CalcMode == 4) THEN ! partial derivative of frictional pressure drop relative to flowrate for top gas pocket - ExitValue = - 2.d0 * Kchoke * FlowEl(OpenholeFirstEl - 1)%Flowrate * 448.8 / dt - IF (x >= OpenholeFirstEl) THEN ! kick STARTX is in openhole - DO z = x , NumbEl ! open hole elements + ExitValue = - 2.d0 * FricPressDropVars%Kchoke * FlowEl(FricPressDropVars%OpenholeFirstEl - 1)%Flowrate * 448.8 / dt + IF (x >= FricPressDropVars%OpenholeFirstEl) THEN ! kick STARTX is in openhole + DO z = x , FricPressDropVars%NumbEl ! open hole elements CALL PartialDerivativeFricToFlowRate(z) IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe @@ -333,7 +304,7 @@ SUBROUTINE GasKickCalculator CALL ErrorStop('NaN in calculating partial derivative') END IF END DO - DO z = AnnulusFirstEl , OpenholeFirstEl - 1 ! Annulus elements + DO z = FricPressDropVars%AnnulusFirstEl , FricPressDropVars%OpenholeFirstEl - 1 ! Annulus elements CALL PartialDerivativeFricToFlowRate(z) IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe @@ -341,9 +312,9 @@ SUBROUTINE GasKickCalculator CALL ErrorStop('NaN in calculating partial derivative') END IF END DO - ExitValue = ExitValue - (SUM(FlowEl(x : NumbEl)%FricToQPartialDiff) + SUM(FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FricToQPartialDiff)) * 448.8 / dt + ExitValue = ExitValue - (SUM(FlowEl(x : FricPressDropVars%NumbEl)%FricToQPartialDiff) + SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : FricPressDropVars%OpenholeFirstEl - 1)%FricToQPartialDiff)) * 448.8 / dt ELSE - DO z = x , OpenholeFirstEl - 1 ! Annulus elements + DO z = x , FricPressDropVars%OpenholeFirstEl - 1 ! Annulus elements CALL PartialDerivativeFricToFlowRate(z) IF (IEEE_IS_NaN(FlowEl(z)%FricToQPartialDiff)) THEN WRITE (*,*) ' FricToQPartialDiff , GenRe ' , x , FlowEl(z)%FricToQPartialDiff , FlowEl(z)%GenRe @@ -351,14 +322,14 @@ SUBROUTINE GasKickCalculator CALL ErrorStop('NaN in calculating partial derivative') END IF END DO - ExitValue = ExitValue - SUM(FlowEl(x : OpenholeFirstEl - 1)%FricToQPartialDiff) * 448.8 / dt + ExitValue = ExitValue - SUM(FlowEl(x : FricPressDropVars%OpenholeFirstEl - 1)%FricToQPartialDiff) * 448.8 / dt END IF ELSE IF (CalcMode == 5) THEN - IF (x >= OpenholeFirstEl .AND. y < OpenholeFirstEl) THEN ! Gas Pocket is in Openhole and upper pocket is in annulus + IF (x >= FricPressDropVars%OpenholeFirstEl .AND. y < FricPressDropVars%OpenholeFirstEl) THEN ! Gas Pocket is in Openhole and upper pocket is in annulus !WRITE (*,*) 'x , y 1' , x, y - ExitValue = GasPocketNewPress%Array(GasPocketNo + 1) + SUM(FlowEl(x : NumbEl)%StaticPressDiff) + SUM(FlowEl(AnnulusFirstEl : y)%StaticPressDiff) + ExitValue = GasPocketNewPress%Array(GasPocketNo + 1) + SUM(FlowEl(x : FricPressDropVars%NumbEl)%StaticPressDiff) + SUM(FlowEl(FricPressDropVars%AnnulusFirstEl : y)%StaticPressDiff) ELSE ! Both gas pockets are in Annulus or openhole !WRITE (*,*) 'x , y 2' , x, y ExitValue = GasPocketNewPress%Array(GasPocketNo + 1) + SUM(FlowEl(x : y)%StaticPressDiff) @@ -373,13 +344,13 @@ SUBROUTINE GasKickCalculator SUBROUTINE NewGasKick - USE KickVariables + use KickVARIABLESModule Use TD_WellGeometry Use CReservoirVariables Use CFormationVariables USE Fluid_Flow_Startup_Vars - USE PressureDisplayVARIABLES - USE FricPressDropVars + use PressureDisplayVARIABLESModule + USE FricPressDropVarsModule USE MudSystemVARIABLES USE CMudPropertiesVariables USE CError @@ -398,15 +369,15 @@ SUBROUTINE NewGasKick IF (NOT(ALLOCATED(GasPocketWeight%Array))) THEN ! 1st kick WRITE (*,*) ' New Influx 1' - NoGasPocket = 1 + KickVARIABLES%NoGasPocket = 1 MudSystem%NewInfluxNumber = MudSystem%NewInfluxNumber + 1 MudSystem%NewInfluxElementCreated = 0 - KickOffBottom = .FALSE. + KickVARIABLES%KickOffBottom = .FALSE. - CALL GasPocketOldPress%AddToFirst((BottomHolePress + StandardPress) * 1.d0) - CALL GasPocketNewPress%AddToFirst((BottomHolePress + StandardPress) * 1.d0) + CALL GasPocketOldPress%AddToFirst((KickVARIABLES%BottomHolePress + StandardPress) * 1.d0) + CALL GasPocketNewPress%AddToFirst((KickVARIABLES%BottomHolePress + StandardPress) * 1.d0) CALL GasPocketOldTemp%AddToFirst(600.0) CALL GasPocketNewTemp%AddToFirst(600.0) CALL GasPocketOldVol%AddToFirst(0.d0) @@ -418,72 +389,47 @@ SUBROUTINE NewGasKick CALL GasPocketDensity%AddToFirst(2.0) CALL GasPocketCompressibility%AddToFirst(0.98) - ALLOCATE(KickJacobian(2 , 2) , OldKickJacobian(2 , 2) , KickVandPFunction(2) , KickUnknownVector(2) , KickCorrectionVector(2)) + ALLOCATE(KickVARIABLES%KickJacobian(2 , 2) , KickVARIABLES%OldKickJacobian(2 , 2) , KickVARIABLES%KickVandPFunction(2) , KickVARIABLES%KickUnknownVector(2) , KickVARIABLES%KickCorrectionVector(2)) - BottomHoleTemperature = 600 - KickFluxAvgPressure = (BottomHolePress + FormPressure) / 2 + StandardPress - KickFluxAvgTemperature = (FormTemperature + BottomHoleTemperature) / 2 - KickFluxAvgCompressibility = 0.98 - - !K_Aa = (5.8742362 * 10.**(-3) * KickFluxAvgTemperature**1.2288) / (511.1728532 + KickFluxAvgTemperature) - !K_Bb = 5.5565586 + (1000.01 / KickFluxAvgTemperature) - !K_Cc = 2.47862 - 0.12294 * K_Bb - GasKickSIDensity = KickFluxAvgPressure / (KickFluxAvgCompressibility * & - KickFluxAvgTemperature * GasType(KickGasType)%GasConstant) * Convpcftogpcm3 - GasKickDensity = GasKickSIDensity * 8.3523 - - !GasKickViscosity = K_Aa * EXP(K_Bb * GasKickSIDensity**K_Cc) - ! - !K_BHTpr = BottomHoleTemperature / KickTc - !K_BHPpr = (BottomHolePress + StandardPress) / KickPc - ! - !K_A_Bottomhole = 3.53 * K_BHPpr - !K_B_Bottomhole = 10.0**(0.9813 * K_BHTpr) - !K_C_Bottomhole = 0.274 * (K_BHPpr**2) - !K_D_Bottomhole = 10.0**(0.8157 * K_BHTpr) - ! - !BottomHoleCompressibility = 0.98 !1. - (K_A_Bottomhole / K_B_Bottomhole) + (K_C_Bottomhole / K_D_Bottomhole) - ! - !GasKickBg = 0.00504 * KickFluxAvgCompressibility * KickFluxAvgTemperature / KickFluxAvgPressure ![bbl/SCF] - - - !KickmdotACoef = 10.**(-8) * 1.15741d0 * 7.08d0 * FormPermeability * REAL(KickFormLength) * GasType(KickGasType)%StDensity / & - !(GasKickViscosity * GasKickBg * LOG(10000.d0)) - !IF (WellHeadOpen) KickmdotACoef = (1.0 + 2.0) * KickmdotACoef - - !KickmdotBCoef = FormPressure + StandardPress !! - Sum(static and friction pressure loss) of flow elements below gas pocket, see below + KickVARIABLES%BottomHoleTemperature = 600 + KickVARIABLES%KickFluxAvgPressure = (KickVARIABLES%BottomHolePress + KickVARIABLES%FormPressure) / 2 + StandardPress + KickVARIABLES%KickFluxAvgTemperature = (KickVARIABLES%FormTemperature + KickVARIABLES%BottomHoleTemperature) / 2 + KickVARIABLES%KickFluxAvgCompressibility = 0.98 + - !GasPocketWeight%Array(1) = GasKickDensity * 0.05 !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt - GasPocketWeight%Array(1) = GasKickDensity * MinKickVol !1.0:seyyed gofte !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + KickVARIABLES%GasKickSIDensity = KickVARIABLES%KickFluxAvgPressure / (KickVARIABLES%KickFluxAvgCompressibility * & + KickVARIABLES%KickFluxAvgTemperature * GasType(KickVARIABLES%KickGasType)%GasConstant) * Convpcftogpcm3 + KickVARIABLES%GasKickDensity = KickVARIABLES%GasKickSIDensity * 8.3523 + GasPocketWeight%Array(1) = KickVARIABLES%GasKickDensity * KickVARIABLES%MinKickVol !1.0:seyyed gofte !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt - GasPocketNewVol%Array(1) = GasPocketCompressibility%Array(1) * GasType(KickGasType)%GasConstant * & + GasPocketNewVol%Array(1) = GasPocketCompressibility%Array(1) * GasType(KickVARIABLES%KickGasType)%GasConstant * & GasPocketNewTemp%Array(1) * GasPocketWeight%Array(1) / GasPocketNewPress%Array(1) GasPocketDeltaVol%Array(1) = 0.05 !GasPocketNewVol%Array(1) GasPocketFlowInduced%Array(1) = (GasPocketDeltaVol%Array(1)) / dt * 448.8 ! gpm - GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) + KickVARIABLES%GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) - WRITE (*,*) ' FormPressure , BottomHolePress' , FormPressure , BottomHolePress, GasKickDensity + WRITE (*,*) ' FormPressure , BottomHolePress' , KickVARIABLES%FormPressure , KickVARIABLES%BottomHolePress, KickVARIABLES%GasKickDensity WRITE (*,*) ' No Press(psia) Vol(gal) Weight(lbm) Flow Induced(gpm)' - DO i = 1 , NoGasPocket + DO i = 1 , KickVARIABLES%NoGasPocket WRITE (*,102) i , GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * Convft3toUSgal, GasPocketWeight%Array(i), GasPocketFlowInduced%Array(i) END DO - !ELSE IF (NoGasPocket < MaxGasPocket .AND. KickOffBottom .AND. (GasPocketNewVol%Array(1) > MinAllowableKickVol .OR. KickWasExitingThroughChoke)) THEN - ELSE IF (NoGasPocket < MaxGasPocket .AND. KickOffBottom .AND. (GasPocketNewVol%Array(1) > MinAllowableKickVol .OR. ANY(GasPocketFlowEl(1 , :) == OpenholeFirstEl - 1))) THEN - WRITE (*,*) ' New Influx', NoGasPocket + 1 + !ELSE IF (NoGasPocket < MaxGasPocket .AND. KickVARIABLES%KickOffBottom .AND. (GasPocketNewVol%Array(1) > KickVARIABLES%MinAllowableKickVol .OR. KickWasExitingThroughChoke)) THEN + ELSE IF (KickVARIABLES%NoGasPocket < KickVARIABLES%MaxGasPocket .AND. KickVARIABLES%KickOffBottom .AND. (GasPocketNewVol%Array(1) > KickVARIABLES%MinAllowableKickVol .OR. ANY(KickVARIABLES%GasPocketFlowEl(1 , :) == FricPressDropVars%OpenholeFirstEl - 1))) THEN + WRITE (*,*) ' New Influx', KickVARIABLES%NoGasPocket + 1 102 FORMAT (I2, 4X, (F8.1), 3X, (F8.3), 2X, (F8.3), 8X, (F8.3)) - NoGasPocket = NoGasPocket + 1 + KickVARIABLES%NoGasPocket = KickVARIABLES%NoGasPocket + 1 MudSystem%NewInfluxNumber = MudSystem%NewInfluxNumber + 1 MudSystem%NewInfluxElementCreated = 0 - KickOffBottom = .FALSE. + KickVARIABLES%KickOffBottom = .FALSE. - CALL GasPocketOldPress%AddToFirst((BottomHolePress + StandardPress) * 1.d0) - CALL GasPocketNewPress%AddToFirst((BottomHolePress + StandardPress) * 1.d0) + CALL GasPocketOldPress%AddToFirst((KickVARIABLES%BottomHolePress + StandardPress) * 1.d0) + CALL GasPocketNewPress%AddToFirst((KickVARIABLES%BottomHolePress + StandardPress) * 1.d0) CALL GasPocketOldTemp%AddToFirst(600.0) CALL GasPocketNewTemp%AddToFirst(600.0) CALL GasPocketOldVol%AddToFirst(0.d0) @@ -495,68 +441,45 @@ SUBROUTINE NewGasKick CALL GasPocketDensity%AddToFirst(2.0) CALL GasPocketCompressibility%AddToFirst(0.98) - DEALLOCATE(KickJacobian , OldKickJacobian , KickVandPFunction , KickUnknownVector , KickCorrectionVector) + DEALLOCATE(KickVARIABLES%KickJacobian , KickVARIABLES%OldKickJacobian , KickVARIABLES%KickVandPFunction , KickVARIABLES%KickUnknownVector , KickVARIABLES%KickCorrectionVector) - ALLOCATE(KickJacobian(2 * NoGasPocket , 2 * NoGasPocket) , OldKickJacobian(2 * NoGasPocket , 2 * NoGasPocket)) - ALLOCATE(KickUnknownVector(2 * NoGasPocket) , KickCorrectionVector(2 * NoGasPocket) , KickVandPFunction(2 * NoGasPocket)) + ALLOCATE(KickVARIABLES%KickJacobian(2 * KickVARIABLES%NoGasPocket , 2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%OldKickJacobian(2 * KickVARIABLES%NoGasPocket , 2 * KickVARIABLES%NoGasPocket)) + ALLOCATE(KickVARIABLES%KickUnknownVector(2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%KickCorrectionVector(2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%KickVandPFunction(2 * KickVARIABLES%NoGasPocket)) - BottomHoleTemperature = 600 - KickFluxAvgPressure = (BottomHolePress + FormPressure) / 2 + StandardPress - KickFluxAvgTemperature = (FormTemperature + BottomHoleTemperature) / 2 - KickFluxAvgCompressibility = 0.98 - - !K_Aa = (5.8742362 * 10.**(-3) * KickFluxAvgTemperature**1.2288) / (511.1728532 + KickFluxAvgTemperature) - !K_Bb = 5.5565586 + (1000.01 / KickFluxAvgTemperature) - !K_Cc = 2.47862 - 0.12294 * K_Bb - GasKickSIDensity = KickFluxAvgPressure / (KickFluxAvgCompressibility * & - KickFluxAvgTemperature * GasType(KickGasType)%GasConstant) * Convpcftogpcm3 - GasKickDensity = GasKickSIDensity * 8.3523 + KickVARIABLES%BottomHoleTemperature = 600 + KickVARIABLES%KickFluxAvgPressure = (KickVARIABLES%BottomHolePress + KickVARIABLES%FormPressure) / 2 + StandardPress + KickVARIABLES%KickFluxAvgTemperature = (KickVARIABLES%FormTemperature + KickVARIABLES%BottomHoleTemperature) / 2 + KickVARIABLES%KickFluxAvgCompressibility = 0.98 + - !GasKickViscosity = K_Aa * EXP(K_Bb * GasKickSIDensity**K_Cc) - ! - !K_BHTpr = BottomHoleTemperature / KickTc - !K_BHPpr = (BottomHolePress + StandardPress) / KickPc - ! - !K_A_Bottomhole = 3.53 * K_BHPpr - !K_B_Bottomhole = 10.0**(0.9813 * K_BHTpr) - !K_C_Bottomhole = 0.274 * (K_BHPpr**2) - !K_D_Bottomhole = 10.0**(0.8157 * K_BHTpr) - ! - !BottomHoleCompressibility = 0.98 !1. - (K_A_Bottomhole / K_B_Bottomhole) + (K_C_Bottomhole / K_D_Bottomhole) - ! - !GasKickBg = 0.00504 * KickFluxAvgCompressibility * KickFluxAvgTemperature / KickFluxAvgPressure ![bbl/SCF] - ! - ! - !KickmdotACoef = 10.**(-8) * 1.15741d0 * 7.08d0 * FormPermeability * REAL(KickFormLength) * GasType(KickGasType)%StDensity / & - ! (GasKickViscosity * GasKickBg * LOG(10000.d0)) - !IF (WellHeadOpen) KickmdotACoef = (1.0 + 2.0) * KickmdotACoef - ! - !KickmdotBCoef = FormPressure + StandardPress !! - Sum(static and friction pressure loss) of flow elements below gas pocket, see below + KickVARIABLES%GasKickSIDensity = KickVARIABLES%KickFluxAvgPressure / (KickVARIABLES%KickFluxAvgCompressibility * & + KickVARIABLES%KickFluxAvgTemperature * GasType(KickVARIABLES%KickGasType)%GasConstant) * Convpcftogpcm3 + KickVARIABLES%GasKickDensity = KickVARIABLES%GasKickSIDensity * 8.3523 - !GasPocketWeight%Array(1) = GasKickDensity * 0.05 !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt - GasPocketWeight%Array(1) = GasKickDensity * MinKickVol !1.0:seyyed gofte !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + !GasPocketWeight%Array(1) = KickVARIABLES%GasKickDensity * 0.05 !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + GasPocketWeight%Array(1) = KickVARIABLES%GasKickDensity * KickVARIABLES%MinKickVol !1.0:seyyed gofte !KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt - GasPocketNewVol%Array(1) = GasPocketCompressibility%Array(1) * GasType(KickGasType)%GasConstant * & + GasPocketNewVol%Array(1) = GasPocketCompressibility%Array(1) * GasType(KickVARIABLES%KickGasType)%GasConstant * & GasPocketNewTemp%Array(1) * GasPocketWeight%Array(1) / GasPocketNewPress%Array(1) GasPocketDeltaVol%Array(1) = 0.05 !GasPocketNewVol%Array(1) GasPocketFlowInduced%Array(1) = (GasPocketDeltaVol%Array(1)) / dt * 448.8 ! gpm - GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) + KickVARIABLES%GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) - WRITE (*,*) ' FormPressure , BottomHolePress' , FormPressure , BottomHolePress, GasKickDensity + WRITE (*,*) ' FormPressure , BottomHolePress' , KickVARIABLES%FormPressure , KickVARIABLES%BottomHolePress, KickVARIABLES%GasKickDensity WRITE (*,*) ' No Press(psia) Vol(gal) Weight(lbm) Flow Induced(gpm)' - DO i = 1 , NoGasPocket + DO i = 1 , KickVARIABLES%NoGasPocket WRITE (*,102) i , GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * Convft3toUSgal, GasPocketWeight%Array(i), GasPocketFlowInduced%Array(i) END DO ELSE ! no new kick, so mass of 1st kick should increase - GasPocketWeight%Array(1) = GasPocketweight%Array(1) + KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt - GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) + GasPocketWeight%Array(1) = GasPocketweight%Array(1) + KickVARIABLES%KickmdotACoef * (KickVARIABLES%KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + KickVARIABLES%GasKickPumpFlowRate = GasPocketFlowInduced%Array(1) - IF (NoGasPocket > 1 .OR. SecondaryKickWeight > 0.0) THEN - SecondaryKickWeight = SecondaryKickWeight + KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1)) * dt - SecondaryKickVol = SecondaryKickWeight / GasReservoirDensity / 42.0 ! 42 USGal = 1bbl + IF (KickVARIABLES%NoGasPocket > 1 .OR. KickVARIABLES%SecondaryKickWeight > 0.0) THEN + KickVARIABLES%SecondaryKickWeight = KickVARIABLES%SecondaryKickWeight + KickVARIABLES%KickmdotACoef * (KickVARIABLES%KickmdotBCoef - GasPocketNewPress%Array(1)) * dt + KickVARIABLES%SecondaryKickVol = KickVARIABLES%SecondaryKickWeight / KickVARIABLES%GasReservoirDensity / 42.0 ! 42 USGal = 1bbl END IF END IF diff --git a/FluidFlow/kick/Kick_VARIABLES.f90 b/FluidFlow/kick/Kick_VARIABLES.f90 index b7efd7f..a96b058 100644 --- a/FluidFlow/kick/Kick_VARIABLES.f90 +++ b/FluidFlow/kick/Kick_VARIABLES.f90 @@ -1,4 +1,4 @@ -MODULE KickVARIABLES +MODULE KickVARIABLESModule USE DynamicDoubleArray USE DynamicIntegerArray @@ -6,67 +6,85 @@ MODULE KickVARIABLES IMPLICIT NONE + TYPE :: KickVARIABLESTYPE + + REAL :: DrillStringSpeed ! drill string speed during surge and swab [ft/s] + + REAL :: ChokeDensity , OldChokeDensity ! density of fluid that exits through choke [ppg] + REAL :: ChokeMinDensity ! [ppg] + REAL :: MaxChokeDensityChange ! [ppg/min] - REAL :: DrillStringSpeed ! drill string speed during surge and swab [ft/s] + INTEGER :: TotalGasKicks ! Number of gas kicks enetered well + REAL :: GasKickMolarMass ! molar mass of gas kick [lbm/lbmole] + REAL :: GasKickBg ! Gas formation volume factor [bbl/SCF] + REAL :: GasResPressure , GasResTemperature , GasResCompressibility ! pressure [psi] , temperature [R] and compressibility [-] at reservoir condition + REAL :: GasReservoirDensity ! density of gas kick in reservoir condition [ppg] + REAL :: BottomHolePress , BottomHoleTemperature , BottomHoleCompressibility ! pressure [psi] , temperature [R] and compressibility [-] at bottom hole condition + REAL :: KickFluxAvgTemperature , KickFluxAvgPressure , KickFluxAvgCompressibility ! Average pressure [psia] and temperature [R] for calculating gas kick flux + REAL :: GasKickViscosity ! Gas kick viscosity at average condition [cp] + REAL :: GasKickSIDensity ! density of gas kick in average condition and in SI units [gr/cm^3] + REAL :: GasKickDensity ! [ppg] + REAL :: GasKickPumpFlowRate ! change of volume of gas kick in sense of flow rate [gpm] + REAL :: FormPressure , FormTemperature + REAL(8) :: KickFormLength , KickFormTopMD , KickFormDownMD ! [ft] + REAL :: FormPermeability ! formation permeability [mD] + REAL :: GasSpecGravity ! specific gravity of gas kick relative to air [-] + REAL :: KickTc , KickPc ! critical temperature [R] and pressure [psi] of gas kick + REAL :: KickTr , KickPr ! Reduced temperature and pressure of gas kick at reservoir condition + REAL :: K_BHTpr , K_BHPpr ! Reduced temperature and pressure of gas kick at bottom hole condition + REAL :: K_A_Res , K_B_Res , K_C_Res , K_D_Res ! Coefficients in calculating compressibility at reservoir condition + REAL :: K_A_Bottomhole , K_B_Bottomhole , K_C_Bottomhole , K_D_Bottomhole + ! Coefficients in calculating compressibility at bottomhole condition + + REAL :: K_Aa , K_Bb , K_Cc ! Coefficient in calculating gas viscosity at reservoir condition + REAL :: MinKickVol ! minimum of kick volume at the beginning of entrance to wellbore [gal] + REAL :: MinAllowableKickVol ! minimum allowable kick volume [ft^3] + REAL :: SecondaryKickVol ! Volume of kicks other than first kick in reservoir condition [bbl] + REAL :: SecondaryKickWeight ! Weight of kicks other than first kick in reservoir condition [lbm] + + REAL :: Kickmdot ! mass flow rate of kick [lbm/sec] + REAL :: ExitMass ! escaped mass from choke [lbm] + REAL :: KickmdotACoef ! coefficient in calculating mdot of kick, Eqn. 5 handnote [lbm/(sec.psi)] + REAL :: KickmdotBCoef ! coefficient in calculating mdot of kick, Eqn. 5 handnote [psi] - REAL :: ChokeDensity , OldChokeDensity ! density of fluid that exits through choke [ppg] - REAL :: ChokeMinDensity ! [ppg] - REAL :: MaxChokeDensityChange ! [ppg/min] - - - INTEGER :: TotalGasKicks ! Number of gas kicks enetered well - REAL :: GasKickMolarMass ! molar mass of gas kick [lbm/lbmole] - REAL :: GasKickBg ! Gas formation volume factor [bbl/SCF] - REAL :: GasResPressure , GasResTemperature , GasResCompressibility ! pressure [psi] , temperature [R] and compressibility [-] at reservoir condition - REAL :: GasReservoirDensity ! density of gas kick in reservoir condition [ppg] - REAL :: BottomHolePress , BottomHoleTemperature , BottomHoleCompressibility ! pressure [psi] , temperature [R] and compressibility [-] at bottom hole condition - REAL :: KickFluxAvgTemperature , KickFluxAvgPressure , KickFluxAvgCompressibility ! Average pressure [psia] and temperature [R] for calculating gas kick flux - REAL :: GasKickViscosity ! Gas kick viscosity at average condition [cp] - REAL :: GasKickSIDensity ! density of gas kick in average condition and in SI units [gr/cm^3] - REAL :: GasKickDensity ! [ppg] - REAL :: GasKickPumpFlowRate ! change of volume of gas kick in sense of flow rate [gpm] - REAL :: FormPressure , FormTemperature - REAL(8) :: KickFormLength , KickFormTopMD , KickFormDownMD ! [ft] - REAL :: FormPermeability ! formation permeability [mD] - REAL :: GasSpecGravity ! specific gravity of gas kick relative to air [-] - REAL :: KickTc , KickPc ! critical temperature [R] and pressure [psi] of gas kick - REAL :: KickTr , KickPr ! Reduced temperature and pressure of gas kick at reservoir condition - REAL :: K_BHTpr , K_BHPpr ! Reduced temperature and pressure of gas kick at bottom hole condition - REAL :: K_A_Res , K_B_Res , K_C_Res , K_D_Res ! Coefficients in calculating compressibility at reservoir condition - REAL :: K_A_Bottomhole , K_B_Bottomhole , K_C_Bottomhole , K_D_Bottomhole - ! Coefficients in calculating compressibility at bottomhole condition - REAL :: K_Aa , K_Bb , K_Cc ! Coefficient in calculating gas viscosity at reservoir condition - REAL :: MinKickVol ! minimum of kick volume at the beginning of entrance to wellbore [gal] - REAL :: MinAllowableKickVol ! minimum allowable kick volume [ft^3] - REAL :: SecondaryKickVol ! Volume of kicks other than first kick in reservoir condition [bbl] - REAL :: SecondaryKickWeight ! Weight of kicks other than first kick in reservoir condition [lbm] - - - REAL :: Kickmdot ! mass flow rate of kick [lbm/sec] - REAL :: ExitMass ! escaped mass from choke [lbm] - REAL :: KickmdotACoef ! coefficient in calculating mdot of kick, Eqn. 5 handnote [lbm/(sec.psi)] - REAL :: KickmdotBCoef ! coefficient in calculating mdot of kick, Eqn. 5 handnote [psi] - - LOGICAL :: KickFlux ! .TRUE. = Bottomhole pressure is lower than reservoir pressure and thus gas - ! enters the bottomhole. - LOGICAL :: KickInFluxConditions ! a set of conditions, when all are true, this variable will become true - LOGICAL :: WellHeadOpen ! .TRUE. = wellhead is open or flow on choke line - ! .FALSE. = wellhead is close and no fluid flow out - LOGICAL :: WellHeadWasOpen ! well Head Condition in last time step - LOGICAL :: WellToChokeManifoldWasOpen - LOGICAL :: KickOffBottom ! .TRUE. = kick starts to rise up - LOGICAL :: KickSinglePocket ! when 'MakeKickSinglePacket' is active, only one pocket of kick exists in the well. - LOGICAL :: SolvingEquationError - LOGICAL :: KickWasExitingThroughChoke - LOGICAL :: ChokeIsClosing + LOGICAL :: KickFlux ! .TRUE. = Bottomhole pressure is lower than reservoir pressure and thus gas + ! enters the bottomhole. + LOGICAL :: KickInFluxConditions ! a set of conditions, when all are true, this variable will become true + LOGICAL :: WellHeadOpen ! .TRUE. = wellhead is open or flow on choke line + ! .FALSE. = wellhead is close and no fluid flow out + LOGICAL :: WellHeadWasOpen ! well Head Condition in last time step + LOGICAL :: WellToChokeManifoldWasOpen + LOGICAL :: KickOffBottom ! .TRUE. = kick starts to rise up + LOGICAL :: KickSinglePocket ! when 'MakeKickSinglePacket' is active, only one pocket of kick exists in the well. + LOGICAL :: SolvingEquationError + LOGICAL :: KickWasExitingThroughChoke + LOGICAL :: ChokeIsClosing + + INTEGER :: NoGasPocket ! number of gas pockets (not gas kick) in wellbore which may migrate or expand + INTEGER :: KickType ! = 0 for gas kicks , = 1 for oil kicks and = 2 for water kicks + INTEGER :: KickGasType ! = 1 for methane , = 2 for Hydrogen sulfide + INTEGER :: ChokeKroneckerDelta ! if well to choke manifold is open and well to pit is closed ChokeKroneckerDelta = 1 + INTEGER :: MaxGasPocket ! = 1 if 'single pocket model' is on and = 15 if 'single pocket model' is off + + INTEGER , DIMENSION(:,:) , ALLOCATABLE :: GasPocketFlowEl ! This matrix makes relationship between gas pockets and flow elements, + ! Further information in SUBROUTINE GasPocketFlowElementTransformer + INTEGER , DIMENSION(:,:) , ALLOCATABLE :: tempGasPocketFlowEl ! a temperorary matrix using for data saving during GasPocketFlowEl manipulation + + REAL(8) , DIMENSION(:,:) , ALLOCATABLE :: KickJacobian , OldKickJacobian ! a matrix in which jacibian elements stored + REAL(8) , DIMENSION(:) , ALLOCATABLE :: KickVandPFunction + REAL(8) , DIMENSION(:) , ALLOCATABLE :: KickUnknownVector ! (2*n - 1) elements are flowrate and (2*n) elements are pressure of pockets (n >= 1) + REAL , DIMENSION(:) , ALLOCATABLE :: KickCorrectionVector + REAL :: KickCorrectionUnderRelaxation ! under relaxation parameter for correcting gas Kick Unknown Vector (0,1) + ! = 0 means no correction between two step + ! = 1 for direct correcting and no under relaxation + + + + END TYPE KickVARIABLESTYPE + TYPE(KickVARIABLESTYPE) :: KickVARIABLES - INTEGER :: NoGasPocket ! number of gas pockets (not gas kick) in wellbore which may migrate or expand INTEGER :: KickIteration ! the number of itertion for calculating pressure and flowrate, when kick is in the well - INTEGER :: KickType ! = 0 for gas kicks , = 1 for oil kicks and = 2 for water kicks - INTEGER :: KickGasType ! = 1 for methane , = 2 for Hydrogen sulfide - INTEGER :: ChokeKroneckerDelta ! if well to choke manifold is open and well to pit is closed ChokeKroneckerDelta = 1 - INTEGER :: MaxGasPocket ! = 1 if 'single pocket model' is on and = 15 if 'single pocket model' is off - + !!!!!!!!!!!!!!!!!!!!!!! Gas Pockets Data TYPE(DynamicDoubleArrayType) :: GasPocketOldPress , GasPocketOldVol ! pressure and volume of gas pocket at the beginning of time step [psia , ft^3] TYPE(DynamicDoubleArrayType) :: GasPocketNewPress , GasPocketNewVol ! pressure and volume of gas pocket at the end of time step [psia , ft^3] @@ -79,17 +97,7 @@ MODULE KickVARIABLES TYPE(DynamicRealArrayType) :: GasPocketWeight ! weight of pocket [lbm] TYPE(DynamicRealArrayType) :: GasPocketDensity ! density of gas pocket [ppg] TYPE(DynamicRealArrayType) :: GasPocketCompressibility ! compressibility as a measure of deviation from ideal gas behavior [-] - INTEGER , DIMENSION(:,:) , ALLOCATABLE :: GasPocketFlowEl ! This matrix makes relationship between gas pockets and flow elements, - ! Further information in SUBROUTINE GasPocketFlowElementTransformer - INTEGER , DIMENSION(:,:) , ALLOCATABLE :: tempGasPocketFlowEl ! a temperorary matrix using for data saving during GasPocketFlowEl manipulation !INTEGER , DIMENSION(:) , ALLOCATABLE :: GasPocketGasType ! = 1 for methane , = 2 for Hydrogen Sulfide - REAL(8) , DIMENSION(:,:) , ALLOCATABLE :: KickJacobian , OldKickJacobian ! a matrix in which jacibian elements stored - REAL(8) , DIMENSION(:) , ALLOCATABLE :: KickVandPFunction - REAL(8) , DIMENSION(:) , ALLOCATABLE :: KickUnknownVector ! (2*n - 1) elements are flowrate and (2*n) elements are pressure of pockets (n >= 1) - REAL , DIMENSION(:) , ALLOCATABLE :: KickCorrectionVector - REAL :: KickCorrectionUnderRelaxation ! under relaxation parameter for correcting gas Kick Unknown Vector (0,1) - ! = 0 means no correction between two step - ! = 1 for direct correcting and no under relaxation END MODULE \ No newline at end of file diff --git a/Rop/ROP_MainCalculation.f90 b/Rop/ROP_MainCalculation.f90 index 693bf41..3655efe 100644 --- a/Rop/ROP_MainCalculation.f90 +++ b/Rop/ROP_MainCalculation.f90 @@ -14,9 +14,9 @@ subroutine ROP_MainCalculation use RTable_VARIABLES, only: RTable use TD_DrillStemComponents use TD_WellGeometry - use PressureDisplayVARIABLES + use PressureDisplayVARIABLESModule use MudSystemVARIABLES - use FricPressDropVars + USE FricPressDropVarsModule use CReservoirVariables use CWarningsVariables use TopDrive_VARIABLES, only: TDS @@ -79,7 +79,7 @@ subroutine ROP_MainCalculation ROP_Spec%DiameterOfBitNozzle = Configuration%StringConfiguration%BitDefinition%BitNozzleSize ! unit : [inch] *** basic input: [1/32 in.] (Typical Range: 8.0 to 32.0) ROP_Spec%CriticalMudDensity = Configuration%Formation%Formations(ROP_Spec%FormationNumber)%PorePressureGradient/.465d0*9.d0 ! ????????? delete ,unit : [ppg] or [lb/gal] (Typical Range: 0 to 10.0) ROP_Bit%FormationMudDensity = Configuration%Formation%Formations(ROP_Spec%FormationNumber)%PorePressureGradient/0.052d0 - ROP_Bit%BottomHolePressure = PressureGauges(3) !5200 [psi] + ROP_Bit%BottomHolePressure = PressureDisplayVARIABLES%PressureGauges(3) !5200 [psi] ROP_Bit%ECD = ROP_Bit%BottomHolePressure/(0.052*ROP_Bit%DrillingVerticalDepth) ROP_Spec%CriticalWeightOnBit = (Configuration%Formation%Formations(ROP_Spec%FormationNumber)%ThresholdWeight/5.d0)-(.06d0*(Configuration%Formation%Formations(ROP_Spec%FormationNumber)%ThresholdWeight-10.d0)) ! unit : [klb/in] (Typical Range: 0 to 10 ----> 0.6 to 2) !IF (ALLOCATED(FlowEl)) THEN diff --git a/SimulationCore2.vfproj b/SimulationCore2.vfproj index 59e7c2b..4f6f5e3 100644 --- a/SimulationCore2.vfproj +++ b/SimulationCore2.vfproj @@ -85,22 +85,8 @@ - - - - - - - - - - - - - - diff --git a/TorqueDrag/TD_MainCalculations.f90 b/TorqueDrag/TD_MainCalculations.f90 index 4782906..173a4b3 100644 --- a/TorqueDrag/TD_MainCalculations.f90 +++ b/TorqueDrag/TD_MainCalculations.f90 @@ -8,7 +8,7 @@ subroutine TD_MainCalculations Use TD_WellGeometry Use TD_GeneralData Use TD_StringConnectionData - Use FricPressDropVars + USE FricPressDropVarsModule Use MudSystemVARIABLES diff --git a/TorqueDrag/TD_ReadDataSubroutines/TD_MudPropertiesReadData.f90 b/TorqueDrag/TD_ReadDataSubroutines/TD_MudPropertiesReadData.f90 index b5d9224..99b2481 100644 --- a/TorqueDrag/TD_ReadDataSubroutines/TD_MudPropertiesReadData.f90 +++ b/TorqueDrag/TD_ReadDataSubroutines/TD_MudPropertiesReadData.f90 @@ -4,7 +4,7 @@ subroutine TD_MudPropertiesReadData (i) Use TD_WellElements Use TD_WellGeometry Use TD_GeneralData - Use FricPressDropVars + USE FricPressDropVarsModule Use MudSystemVARIABLES implicit none