@@ -30,7 +30,7 @@ | |||||
"type": "cppdbg", | "type": "cppdbg", | ||||
"request": "launch", | "request": "launch", | ||||
"program": "${workspaceRoot}/SimulationCore2", | "program": "${workspaceRoot}/SimulationCore2", | ||||
"args": ["aberama.iran.liara.ir","32815","4YKFnubfFFjfh4yTK7b0Rg9X","test","5"], | |||||
"args": ["aberama.iran.liara.ir","32815","4YKFnubfFFjfh4yTK7b0Rg9X","4567bdd6-2af8-4d03-ab5e-08db9deec266","5"], | |||||
"stopAtEntry": false, | "stopAtEntry": false, | ||||
"cwd": "${workspaceRoot}", | "cwd": "${workspaceRoot}", | ||||
"externalConsole": false, | "externalConsole": false, | ||||
@@ -0,0 +1,61 @@ | |||||
# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/RigSpecifications/CPower.f90" | |||||
module CPower | |||||
use SimulationVariables | |||||
use json_module | |||||
implicit none | |||||
public | |||||
contains | |||||
subroutine PowerToJson(parent) | |||||
type(json_value),pointer :: parent | |||||
type(json_core) :: json | |||||
type(json_value),pointer :: p | |||||
! 1. create new node | |||||
call json%create_object(p,'Power') | |||||
! 2. add member of data type to new node | |||||
! call StringConfigurationToJson(p) | |||||
! call FormationToJson(p) | |||||
call json%add(p,"CementPump",data%Configuration%Power%CementPump) | |||||
call json%add(p,"Drawworks",data%Configuration%Power%Drawworks) | |||||
call json%add(p,"GeneratorPowerRating",data%Configuration%Power%GeneratorPowerRating) | |||||
call json%add(p,"MudPump1",data%Configuration%Power%MudPump1) | |||||
call json%add(p,"MudPump2",data%Configuration%Power%MudPump2) | |||||
call json%add(p,"NumberOfgenerators",data%Configuration%Power%NumberOfgenerators) | |||||
call json%add(p,"RotaryTable",data%Configuration%Power%RotaryTable) | |||||
call json%add(p,"TopDrive",data%Configuration%Power%TopDrive) | |||||
! 3. add new node to parent | |||||
call json%add(parent,p) | |||||
end subroutine | |||||
subroutine PowerFromJson(parent) | |||||
use json_module,IK =>json_ik | |||||
type(json_value),pointer :: parent | |||||
type(json_core) :: json | |||||
type(json_value),pointer :: p,pitems,pitem,pval,pbit | |||||
call json%get(parent,'Power',p) | |||||
call json%get(p,"CementPump",pitem) | |||||
call json%get(pitem,data%Configuration%Power%CementPump) | |||||
call json%get(p,"Drawworks",pitem) | |||||
call json%get(pitem,data%Configuration%Power%Drawworks) | |||||
call json%get(p,"GeneratorPowerRating",pitem) | |||||
call json%get(pitem,data%Configuration%Power%GeneratorPowerRating) | |||||
call json%get(p,"MudPump1",pitem) | |||||
call json%get(pitem,data%Configuration%Power%MudPump1) | |||||
call json%get(p,"MudPump2",pitem) | |||||
call json%get(pitem,data%Configuration%Power%MudPump2) | |||||
call json%get(p,"NumberOfgenerators",pitem) | |||||
call json%get(pitem,data%Configuration%Power%NumberOfgenerators) | |||||
call json%get(p,"RotaryTable",pitem) | |||||
call json%get(pitem,data%Configuration%Power%RotaryTable) | |||||
call json%get(p,"TopDrive",pitem) | |||||
call json%get(pitem,data%Configuration%Power%TopDrive) | |||||
end subroutine | |||||
end module CPower |
@@ -0,0 +1,17 @@ | |||||
# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/RigSpecifications/CPowerVariables.f90" | |||||
module CPowerVariables | |||||
implicit none | |||||
public | |||||
! variables | |||||
Type::PowerType | |||||
integer :: NumberOfgenerators | |||||
real(8) :: GeneratorPowerRating | |||||
real(8) :: MudPump1 | |||||
real(8) :: MudPump2 | |||||
real(8) :: CementPump | |||||
real(8) :: RotaryTable | |||||
real(8) :: Drawworks | |||||
real(8) :: TopDrive | |||||
End type PowerType | |||||
! Type(PowerType)::Power | |||||
end module CPowerVariables |
@@ -95,7 +95,7 @@ module PumpsMain | |||||
! Call DATE_AND_TIME(values=MP_END_TIME) | ! Call DATE_AND_TIME(values=MP_END_TIME) | ||||
! MP_SolDuration = 100-(MP_END_TIME(5)*3600000+MP_END_TIME(6)*60000+MP_END_TIME(7)*1000+MP_END_TIME(8)-MP_START_TIME(5)*3600000-MP_START_TIME(6)*60000-MP_START_TIME(7)*1000-MP_START_TIME(8)) | ! MP_SolDuration = 100-(MP_END_TIME(5)*3600000+MP_END_TIME(6)*60000+MP_END_TIME(7)*1000+MP_END_TIME(8)-MP_START_TIME(5)*3600000-MP_START_TIME(6)*60000-MP_START_TIME(7)*1000-MP_START_TIME(8)) | ||||
! if(MP_SolDuration > 0.0) then | ! if(MP_SolDuration > 0.0) then | ||||
! Call sleepqq(MP_SolDuration) | |||||
! Call sleepqq(MP_SolDuration) | |||||
! end if | ! end if | ||||
! | ! | ||||
! if (IsStopped == .true.) then | ! if (IsStopped == .true.) then | ||||
@@ -0,0 +1,223 @@ | |||||
# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/Pumps/PumpsMain.f90" | |||||
module PumpsMain | |||||
use SimulationVariables | |||||
implicit none | |||||
public | |||||
contains | |||||
! **************************************** | |||||
! ***** subroutine Pump1MainBody ***** | |||||
! **************************** | |||||
! subroutine Pump1_Setup() | |||||
! use CSimulationVariables | |||||
! implicit none | |||||
! call OnSimulationInitialization%Add(Pump1_Init) | |||||
! call OnSimulationStop%Add(Pump1_Init) | |||||
! call OnPump1Step%Add(Pump1_Step) | |||||
! call OnPump1Output%Add(Pump1_Output) | |||||
! call OnPump1Main%Add(Pump1MainBody) | |||||
! end subroutine | |||||
subroutine Pump1_Init | |||||
Call Pumps_StartUp | |||||
end subroutine Pump1_Init | |||||
subroutine Pump1_Step | |||||
Call Pump1_MainSolver | |||||
end subroutine Pump1_Step | |||||
! subroutine Pump1_Output | |||||
! implicit none | |||||
! end subroutine Pump1_Output | |||||
! subroutine Pump1MainBody | |||||
! use ifport | |||||
! use ifmt | |||||
! implicit none | |||||
! Call Pumps_StartUp | |||||
! loop1 : do | |||||
! Call Pumps_MainSolver | |||||
! end do loop1 | |||||
! end subroutine Pump1MainBody | |||||
! **************************************** | |||||
! ***** subroutine Pump2MainBody ***** | |||||
! **************************** | |||||
! subroutine Pump2_Setup() | |||||
! use CSimulationVariables | |||||
! implicit none | |||||
! call OnSimulationInitialization%Add(Pump2_Init) | |||||
! call OnSimulationStop%Add(Pump2_Init) | |||||
! call OnPump2Step%Add(Pump2_Step) | |||||
! call OnPump2Output%Add(Pump2_Output) | |||||
! call OnPump2Main%Add(Pump2MainBody) | |||||
! end subroutine | |||||
! | |||||
! subroutine Pump2_Init | |||||
! implicit none | |||||
! end subroutine Pump2_Init | |||||
! | |||||
! subroutine Pump2_Step | |||||
! call Pump2_MainSolver | |||||
! end subroutine Pump2_Step | |||||
! | |||||
! subroutine Pump2_Output | |||||
! implicit none | |||||
! end subroutine Pump2_Output | |||||
! | |||||
! subroutine Pump2MainBody | |||||
! use ifport | |||||
! use ifmt | |||||
! use CWarnings | |||||
! implicit none | |||||
! | |||||
! integer,dimension(8) :: MP_START_TIME, MP_END_TIME | |||||
! INTEGER :: MP_SolDuration | |||||
! | |||||
! Call Pump_StartUp | |||||
! | |||||
! loop1 : do | |||||
! | |||||
! Call DATE_AND_TIME(values=MP_START_TIME) | |||||
! | |||||
! Call Pump2_MainSolver | |||||
! | |||||
! Call DATE_AND_TIME(values=MP_END_TIME) | |||||
! MP_SolDuration = 100-(MP_END_TIME(5)*3600000+MP_END_TIME(6)*60000+MP_END_TIME(7)*1000+MP_END_TIME(8)-MP_START_TIME(5)*3600000-MP_START_TIME(6)*60000-MP_START_TIME(7)*1000-MP_START_TIME(8)) | |||||
! if(MP_SolDuration > 0.0) then | |||||
! Call sleepqq(MP_SolDuration) | |||||
! end if | |||||
! | |||||
! if (IsStopped == .true.) then | |||||
! exit loop1 | |||||
! end if | |||||
! | |||||
! end do loop1 | |||||
! | |||||
! | |||||
! end subroutine Pump2MainBody | |||||
! | |||||
! | |||||
! | |||||
! | |||||
!! **************************************** | |||||
!! ***** subroutine Pump3MainBody ***** | |||||
!! **************************** | |||||
! subroutine Pump3_Setup() | |||||
! use CSimulationVariables | |||||
! implicit none | |||||
! call OnSimulationInitialization%Add(Pump3_Init) | |||||
! call OnSimulationStop%Add(Pump3_Init) | |||||
! call OnPump3Step%Add(Pump3_Step) | |||||
! call OnPump3Output%Add(Pump3_Output) | |||||
! call OnPump3Main%Add(Pump3MainBody) | |||||
! end subroutine | |||||
! | |||||
! subroutine Pump3_Init | |||||
! implicit none | |||||
! end subroutine Pump3_Init | |||||
! | |||||
! subroutine Pump3_Step | |||||
! implicit none | |||||
! end subroutine Pump3_Step | |||||
! | |||||
! subroutine Pump3_Output | |||||
! implicit none | |||||
! end subroutine Pump3_Output | |||||
! | |||||
! subroutine Pump3MainBody | |||||
! use ifport | |||||
! use ifmt | |||||
! implicit none | |||||
! | |||||
! | |||||
! integer,dimension(8) :: MP_START_TIME, MP_END_TIME | |||||
! INTEGER :: MP_SolDuration | |||||
! | |||||
! !Call Pump_StartUp | |||||
! !loop1 : do | |||||
! ! | |||||
! ! Call sleepqq(10) | |||||
! ! | |||||
! ! !!! Pump3 Malfunction ----> Power Failure | |||||
! ! !!if (data%State%Pump(1)%PowerFailMalf==1) then | |||||
! ! !! !MP1BLWR=0 | |||||
! ! !! Call Pump3_OffMode_Solver | |||||
! ! !! Call ClosePump1() | |||||
! ! !!end if | |||||
! ! | |||||
! ! !if( (MP1CPSwitch==1) .and. (MP1Throttle==0.) .and. (data%State%Pump(3)%PowerFailMalf==0) ) then | |||||
! !! | |||||
! !! loop2: do | |||||
! !! | |||||
! !! Call DATE_AND_TIME(values=MP_START_TIME) | |||||
! !! | |||||
! !!!! ! Pump3 Malfunction ----> Power Failure | |||||
! !!!! if (data%State%Pump(1)%PowerFailMalf==1) then | |||||
! !!!! !MP1BLWR=0 | |||||
! !!!! Pump3_OffMode_Solver | |||||
! !!!! Call ClosePump1() | |||||
! !!!! exit loop2 | |||||
! !!!! end if | |||||
! !! | |||||
! !! data%State%Pump(3)%N_new = MP1Throttle | |||||
! !! if (((data%State%Pump(3)%N_new-data%State%Pump(3)%N_old)/data%State%Pump(3)%time_step)>193.) then | |||||
! !! data%State%Pump(3)%N_ref =(193.*data%State%Pump(3)%time_step)+data%State%Pump(3)%N_old | |||||
! !! else if (((data%State%Pump(3)%N_old-data%State%Pump(3)%N_new)/data%State%Pump(3)%time_step)>193.) then | |||||
! !! data%State%Pump(3)%N_ref = (-193.*data%State%Pump(3)%time_step)+data%State%Pump(3)%N_old | |||||
! !! else | |||||
! !! data%State%Pump(3)%N_ref = data%State%Pump(3)%N_new | |||||
! !! end if | |||||
! !! | |||||
! !! Call Pump3_OnMode_Solver | |||||
! !! | |||||
! !! IF (data%State%Pump(3)%Flow_Rate>0.) Then | |||||
! !! Call OpenCementPump() | |||||
! !! Else | |||||
! !! Call CloseCementPump() | |||||
! !! End if | |||||
! !! | |||||
! !! data%State%Pump(3)%N_old = data%State%Pump(3)%N_ref | |||||
! !! | |||||
! !! Call DATE_AND_TIME(values=MP_END_TIME) | |||||
! !! MP_SolDuration = 100-(MP_END_TIME(6)*60000+MP_END_TIME(7)*1000+MP_END_TIME(8)-MP_START_TIME(6)*60000-MP_START_TIME(7)*1000-MP_START_TIME(8)) | |||||
! !! !print*, 'MPtime=', MP_SolDuration | |||||
! !! if(MP_SolDuration > 0.0) then | |||||
! !! Call sleepqq(MP_SolDuration) | |||||
! !! end if | |||||
! !! | |||||
! !! if ((MP1CPSwitch==0) .or. (IsStopped == .true.)) then | |||||
! !! Call Pump3_OffMode_Solver | |||||
! !! Call CloseCementPump() | |||||
! !! exit loop2 | |||||
! !! end if | |||||
! !! end do loop2 | |||||
! ! | |||||
! ! else | |||||
! ! | |||||
! ! !Call Pump3_OffMode_Solver | |||||
! ! !Call CloseCementPump() | |||||
! ! | |||||
! ! end if | |||||
! ! | |||||
! ! if (IsStopped == .true.) then | |||||
! ! exit loop1 | |||||
! ! end if | |||||
! ! | |||||
! !end do loop1 | |||||
! | |||||
! | |||||
! end subroutine Pump3MainBody | |||||
end module PumpsMain |
@@ -0,0 +1,50 @@ | |||||
# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/Pumps/Pumps_StartUp.f90" | |||||
subroutine Pumps_StartUp | |||||
use CPumpsVariables | |||||
use CPumps | |||||
use SimulationVariables | |||||
IMPLICIT NONE | |||||
!>>>>>>>>>>>>>>>>>>>>>>> PUMP 1 <<<<<<<<<<<<<<<<<<<<<<<<<<< | |||||
data%State%Pump(1)%FlowRatePerSTK = .04d0 ![bbl] !??????? motaghayere voroudi | |||||
!data%State%Pump(1)%FlowRatePerSTK = data%State%Pump(1)%FlowRatePerSTK*0.0292d0 ![gpm] | |||||
data%State%Pump(1)%RateChange = 4.d0 ![stk/min2 ??] !??????? motaghayere voroudi | |||||
data%State%Pump(1)%Mech_Efficiency = data%Configuration%Pumps%MudPump1MechanicalEfficiency ![dimensionless] | |||||
!data%State%Pump(1)%Vol_Efficiency = MudPump1VolumetricEfficiency !bayad hazf beshe ? | |||||
data%State%Pump(1)%Max_Pressure = 6000.d0 ![psi] !??????? motaghayere voroudi | |||||
data%State%Pump(1)%MaxSPM = data%Configuration%Pumps%MudPump1Maximum ![spm] | |||||
data%State%Pump(1)%Trans_Ratio = 965.d0/data%State%Pump(1)%MaxSPM | |||||
data%State%Pump(1)%time_step = 0.1d0 !?????? niaz hast ya na?? | |||||
data%State%Pump(1)%RateChange = 193.d0!data%State%Pump(1)%RateChange*data%State%Pump(1)%Trans_Ratio ! [rpm/min ??] ??????????????? rpm/s | |||||
data%State%Pump(1)%K_throttle = 0 | |||||
data%State%Pump(1)%N_old = 0.d0 | |||||
Call Pump_OffMode_Solver(1) | |||||
!>>>>>>>>>>>>>>>>>>>>>>> PUMP 2 <<<<<<<<<<<<<<<<<<<<<<<<<<< | |||||
data%State%Pump(2)%FlowRatePerSTK = .04d0 ![bbl] !??????? motaghayere voroudi | |||||
!data%State%Pump(2)%FlowRatePerSTK = data%State%Pump(2)%FlowRatePerSTK*0.0292d0 ![gpm] | |||||
data%State%Pump(2)%RateChange = 4.d0 ![stk/min2 ??] !??????? motaghayere voroudi | |||||
data%State%Pump(2)%Mech_Efficiency = data%Configuration%Pumps%MudPump2MechanicalEfficiency ![dimensionless] | |||||
!data%State%Pump(2)%Vol_Efficiency = MudPump2VolumetricEfficiency !bayad hazf beshe ? | |||||
data%State%Pump(2)%Max_Pressure = 6000.d0 ![psi] !??????? motaghayere voroudi | |||||
data%State%Pump(2)%MaxSPM = data%Configuration%Pumps%MudPump2Maximum ![spm] | |||||
data%State%Pump(2)%Trans_Ratio = 965.d0/data%State%Pump(2)%MaxSPM | |||||
data%State%Pump(2)%time_step = 0.1d0 !?????? niaz hast ya na?? | |||||
data%State%Pump(2)%RateChange = 193.d0!data%State%Pump(2)%RateChange*data%State%Pump(2)%Trans_Ratio ! [rpm/min ??] ??????????????? rpm/s | |||||
data%State%Pump(2)%K_throttle = 0 | |||||
data%State%Pump(2)%N_old = 0.d0 | |||||
Call Pump_OffMode_Solver(2) | |||||
!!>>>>>>>>>>>>>>>>>>>>>>> PUMP 3 <<<<<<<<<<<<<<<<<<<<<<<<<<< | |||||
data%State%Pump(3)%FlowRatePerSTK = .04d0 ![bbl] !??????? motaghayere voroudi | |||||
!data%State%Pump(3)%FlowRatePerSTK = data%State%Pump(3)%FlowRatePerSTK*0.0292d0 ![gpm] | |||||
data%State%Pump(3)%RateChange = 4.d0 ![stk/min2 ??] !??????? motaghayere voroudi | |||||
data%State%Pump(3)%Mech_Efficiency = data%Configuration%Pumps%CementPumpMechanicalEfficiency ![dimensionless] | |||||
!data%State%Pump(3)%Vol_Efficiency = CementPumpVolumetricEfficiency !bayad hazf beshe ? | |||||
data%State%Pump(3)%Max_Pressure = 6000.d0 ![psi] !??????? motaghayere voroudi | |||||
data%State%Pump(3)%MaxSPM = data%Configuration%Pumps%CementPumpMaximum ![spm] | |||||
data%State%Pump(3)%Trans_Ratio = 965.d0/data%State%Pump(3)%MaxSPM | |||||
data%State%Pump(3)%time_step = 0.1d0 !?????? niaz hast ya na?? | |||||
data%State%Pump(3)%RateChange = 193.d0!data%State%Pump(3)%RateChange*data%State%Pump(3)%Trans_Ratio ! [rpm/min ??] ??????????????? rpm/s | |||||
data%State%Pump(3)%K_throttle = 0 | |||||
data%State%Pump(3)%N_old = 0.d0 | |||||
Call Pump_OffMode_Solver(3) | |||||
end subroutine Pumps_StartUp |
@@ -0,0 +1,49 @@ | |||||
# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/Pumps/Pumps_VARIABLES.f90" | |||||
MODULE Pumps_VARIABLES | |||||
IMPLICIT NONE | |||||
PUBLIC | |||||
! REAL , PARAMETER :: pi=3.14159265d0 | |||||
Type, public:: Pumps_Var | |||||
REAL :: Total_Pump_GPM, Total_Pump_SPM, Total_Stroke_Counter_For_Plot | |||||
end Type Pumps_Var | |||||
Type(Pumps_Var) :: MPumps | |||||
!**************************************************************************************************** | |||||
!**************** Define PUMP Array ************************************************************ | |||||
TYPE, PUBLIC :: Pump_Var | |||||
!***** Pump_VARIABLES *************************** | |||||
INTEGER :: AssignmentSwitchh, Switch, K_throttle | |||||
INTEGER :: PowerFailMalf , BlowPopOffMalf , SPMGaugeMalf , Failure | |||||
REAL :: Throttle, RateChange | |||||
REAL :: Mech_Efficiency, Vol_Efficiency, Trans_Ratio | |||||
REAL :: StandPipe_Pressure , Max_Pressure | |||||
REAL :: Speed, N_new, N_old, MaxSPM | |||||
REAL :: Flow_Rate, Hydraulic_HorsePower, Max_Horsepower, FlowRatePerSTK, Max_FlowRate, HorsePower | |||||
REAL :: time_step | |||||
INTEGER :: BLWR ! 1=On , 0=Off | |||||
INTEGER :: Open_Close ! 1=Open , 0=Close | |||||
!************* Sound_VARIABLES ********************** | |||||
INTEGER :: SoundSPM | |||||
Logical :: SoundBlower | |||||
END TYPE Pump_Var | |||||
!*********************************************************************************************** | |||||
!*********************************************************************************************** | |||||
END MODULE Pumps_VARIABLES |
@@ -0,0 +1,231 @@ | |||||
# 1 "/mnt/c/Projects/VSIM/SimulationCore2/FluidFlow/Frictional_Press_Drop_Calc.f90" | |||||
SUBROUTINE FricPressDrop(iloc) | |||||
!! Record of revisions | |||||
!! Date Programmer Discription of change | |||||
!! ------ ------------ ----------------------- | |||||
!! 1396/07/23 Sheikh Original code | |||||
!! | |||||
USE FricPressDropVarsModule | |||||
USE SimulationVariables | |||||
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 (data%Configuration%Mud%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 (data%Configuration%Mud%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 (data%Configuration%Mud%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 (data%Configuration%Mud%ActiveRheologyModel == PowerLaw_RheologyModel .OR. data%Configuration%Mud%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 (data%Configuration%Mud%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 (data%Configuration%Mud%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 SimulationVariables | |||||
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 (data%Configuration%Mud%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 (data%Configuration%Mud%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 |
@@ -66,7 +66,7 @@ OBJ_DIR = $(TOP_DIR)/obj | |||||
# FCFLAGS = -g -J$(MOD_DIR) -fimplicit-none -Wall -cpp -ffree-line-length-256 | # FCFLAGS = -g -J$(MOD_DIR) -fimplicit-none -Wall -cpp -ffree-line-length-256 | ||||
# FCFLAGS = /module:$(MOD_DIR) /fpp | # FCFLAGS = /module:$(MOD_DIR) /fpp | ||||
FCFLAGS = -module $(MOD_DIR) -fpp -debug all -g -traceback | |||||
FCFLAGS = -module $(MOD_DIR) -fpp -debug all -g -traceback -D IFORT | |||||
TARGET = SimulationCore2 | TARGET = SimulationCore2 | ||||
@@ -1,41 +1,41 @@ | |||||
! SimulationCore2.f90 | |||||
! | |||||
! FUNCTIONS: | |||||
! SimulationCore2 - Entry point of console application. | |||||
! | |||||
!**************************************************************************** | |||||
! | |||||
! PROGRAM: SimulationCore2 | |||||
! | |||||
! PURPOSE: Entry point for the console application. | |||||
! | |||||
!**************************************************************************** | |||||
program SimulationCore2 | |||||
use Simulator | |||||
use RedisInterface | |||||
!use testRedisModule | |||||
implicit none | |||||
character(len=100) :: redis_host,redis_password, sim_id, temp | |||||
integer :: redis_port, log_level, stat | |||||
! Variables | |||||
! Body of SimulationCore2 | |||||
! print *, 'Hello World' | |||||
! call read_variables() | |||||
if(command_argument_count()/=5) then | |||||
print *, "Simulator Program must have 5 parameter: redis_host,redisPort,redis_password, sim_id,log_level" | |||||
stop | |||||
endif | |||||
call get_command_argument(1, redis_host) | |||||
call get_command_argument(2, temp) | |||||
read(temp,*,iostat=stat) redis_port | |||||
call get_command_argument(3, redis_password) | |||||
call get_command_argument(4, sim_id) | |||||
call get_command_argument(5, temp) | |||||
read(temp,*,iostat=stat) log_level | |||||
call simulate(trim(redis_host),redis_port,trim(redis_password), trim(sim_id),log_level) | |||||
end program SimulationCore2 | |||||
! SimulationCore2.f90 | |||||
! | |||||
! FUNCTIONS: | |||||
! SimulationCore2 - Entry point of console application. | |||||
! | |||||
!**************************************************************************** | |||||
! | |||||
! PROGRAM: SimulationCore2 | |||||
! | |||||
! PURPOSE: Entry point for the console application. | |||||
! | |||||
!**************************************************************************** | |||||
program SimulationCore2 | |||||
use Simulator | |||||
use RedisInterface | |||||
!use testRedisModule | |||||
implicit none | |||||
character(len=100) :: redis_host,redis_password, sim_id, temp | |||||
integer :: redis_port, log_level, status | |||||
! Variables | |||||
! Body of SimulationCore2 | |||||
! print *, 'Hello World' | |||||
! call read_variables() | |||||
if(command_argument_count()/=5) then | |||||
print *, "Simulator Program must have 5 parameter: redis_host,redisPort,redis_password, sim_id,log_level" | |||||
stop | |||||
endif | |||||
call get_command_argument(1, redis_host) | |||||
call get_command_argument(2, temp) | |||||
read(temp,*,iostat=status) redis_port | |||||
call get_command_argument(3, redis_password) | |||||
call get_command_argument(4, sim_id) | |||||
call get_command_argument(5, temp) | |||||
read(temp,*,iostat=status) log_level | |||||
call simulate(trim(redis_host),redis_port,trim(redis_password), trim(sim_id),log_level) | |||||
end program SimulationCore2 | |||||
@@ -19,7 +19,7 @@ program SimulationCore2 | |||||
!use testRedisModule | !use testRedisModule | ||||
implicit none | implicit none | ||||
character(len=100) :: redis_host,redis_password, sim_id, temp | character(len=100) :: redis_host,redis_password, sim_id, temp | ||||
integer :: redis_port, log_level, stat | |||||
integer :: redis_port, log_level, status | |||||
! Variables | ! Variables | ||||
! Body of SimulationCore2 | ! Body of SimulationCore2 | ||||
@@ -31,11 +31,11 @@ program SimulationCore2 | |||||
endif | endif | ||||
call get_command_argument(1, redis_host) | call get_command_argument(1, redis_host) | ||||
call get_command_argument(2, temp) | call get_command_argument(2, temp) | ||||
read(temp,*,iostat=stat) redis_port | |||||
read(temp,*,iostat=status) redis_port | |||||
call get_command_argument(3, redis_password) | call get_command_argument(3, redis_password) | ||||
call get_command_argument(4, sim_id) | call get_command_argument(4, sim_id) | ||||
call get_command_argument(5, temp) | call get_command_argument(5, temp) | ||||
read(temp,*,iostat=stat) log_level | |||||
read(temp,*,iostat=status) log_level | |||||
call simulate(trim(redis_host),redis_port,trim(redis_password), trim(sim_id),log_level) | call simulate(trim(redis_host),redis_port,trim(redis_password), trim(sim_id),log_level) | ||||
end program SimulationCore2 | end program SimulationCore2 | ||||
@@ -1,4 +1,5 @@ | |||||
module Simulator | module Simulator | ||||
use IFPORT | |||||
use RedisInterface | use RedisInterface | ||||
use Bop | use Bop | ||||
use PumpsMain | use PumpsMain | ||||
@@ -67,7 +68,6 @@ module Simulator | |||||
type(json_file) :: jsonfile | type(json_file) :: jsonfile | ||||
type(json_core):: json | type(json_core):: json | ||||
integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep | integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep | ||||
integer,dimension(8)::timearray | |||||
real :: stepTime !time for each step | real :: stepTime !time for each step | ||||
character(len=:),allocatable::redisInput,redisOutput | character(len=:),allocatable::redisInput,redisOutput | ||||
enum, bind(c) | enum, bind(c) | ||||
@@ -79,10 +79,18 @@ module Simulator | |||||
contains | contains | ||||
FUNCTION time_ms() | |||||
INTEGER(8) :: time_ms | |||||
integer,dimension(8)::timearray | |||||
call date_and_time(values=timearray) | |||||
time_ms = timearray(8)+timearray(7)*1000 + timearray(6)*60000 + timearray(5)*60000*600000 +timearray(4)*24*60000*60000 | |||||
RETURN | |||||
END FUNCTION | |||||
subroutine Simulate(redis_host,redis_port,redis_password, sim_id,log_level) | subroutine Simulate(redis_host,redis_port,redis_password, sim_id,log_level) | ||||
character(len=*) :: redis_host,redis_password, sim_id | character(len=*) :: redis_host,redis_password, sim_id | ||||
integer::t0,t1,t2,t3,t_read=0,t_write=0,t_exec=0,i,status,redis_port,log_level | integer::t0,t1,t2,t3,t_read=0,t_write=0,t_exec=0,i,status,redis_port,log_level | ||||
integer,dimension(12)::t,t_modules | |||||
integer(8),dimension(12)::t,t_modules | |||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||||
do i=1,size(t_modules) | do i=1,size(t_modules) | ||||
@@ -104,45 +112,41 @@ module Simulator | |||||
simulationStep = 1 | simulationStep = 1 | ||||
do while (.true.) | do while (.true.) | ||||
! print *,"simulationStep=",simulationStep | ! print *,"simulationStep=",simulationStep | ||||
call date_and_time(values=timearray) | |||||
t0 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t0 = time_ms() | |||||
! print *,"start reading." | ! print *,"start reading." | ||||
call read_variables() | call read_variables() | ||||
if(simulationStatus==PLAY_TO_DETERMINED_TIME .and. simulationStep>simulationEnd) exit | if(simulationStatus==PLAY_TO_DETERMINED_TIME .and. simulationStep>simulationEnd) exit | ||||
if(simulationStatus==STOP) exit | if(simulationStatus==STOP) exit | ||||
if(simulationStatus==PAUSE) cycle | |||||
if(simulationStatus==PAUSE) then | |||||
print *, "paused" | |||||
go to 211 | |||||
endif | |||||
if(logging>4) print *,"end reading" | if(logging>4) print *,"end reading" | ||||
call date_and_time(values=timearray) | |||||
t1 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t1 = time_ms() | |||||
t_read = t_read+t1-t0 | t_read = t_read+t1-t0 | ||||
if(logging>4) print *,"read completed" | if(logging>4) print *,"read completed" | ||||
!! Rafiee, nothing changed | !! Rafiee, nothing changed | ||||
call BopStack_Step() | call BopStack_Step() | ||||
call date_and_time(values=timearray) | |||||
t(1) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(1) = time_ms() | |||||
t_modules(1) = t_modules(1)+t(1)-t1 | t_modules(1) = t_modules(1)+t(1)-t1 | ||||
!! Tarmigh, now is rewritten | !! Tarmigh, now is rewritten | ||||
call Pump1_Step() | call Pump1_Step() | ||||
call date_and_time(values=timearray) | |||||
t(2) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(2) = time_ms() | |||||
t_modules(2) = t_modules(2)+t(2)-t(1) | t_modules(2) = t_modules(2)+t(2)-t(1) | ||||
!call Pump2_Step() | !call Pump2_Step() | ||||
!! Rafiee | !! Rafiee | ||||
call ChokeControl_Step() | call ChokeControl_Step() | ||||
call date_and_time(values=timearray) | |||||
t(3) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(3) = time_ms() | |||||
t_modules(3) = t_modules(3)+t(3)-t(2) | t_modules(3) = t_modules(3)+t(3)-t(2) | ||||
!! Tarmigh, now is rewritten | !! Tarmigh, now is rewritten | ||||
call RotaryTable_Step() | call RotaryTable_Step() | ||||
call date_and_time(values=timearray) | |||||
t(4) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(4) = time_ms() | |||||
t_modules(4) = t_modules(4)+t(4)-t(3) | t_modules(4) = t_modules(4)+t(4)-t(3) | ||||
!! Tarmigh, now is rewritten | !! Tarmigh, now is rewritten | ||||
call Drawworks_Step() | call Drawworks_Step() | ||||
call date_and_time(values=timearray) | |||||
t(5) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(5) = time_ms() | |||||
t_modules(5) = t_modules(5)+t(5)-t(4) | t_modules(5) = t_modules(5)+t(5)-t(4) | ||||
!! Rafiee | !! Rafiee | ||||
@@ -154,37 +158,31 @@ module Simulator | |||||
!! Rafiee | !! Rafiee | ||||
call KillLine_Step() | call KillLine_Step() | ||||
call date_and_time(values=timearray) | |||||
t(6) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(6) = time_ms() | |||||
t_modules(6) = t_modules(6)+t(6)-t(5) | t_modules(6) = t_modules(6)+t(6)-t(5) | ||||
!! Rafiee | !! Rafiee | ||||
call ChokeLine_Step() | call ChokeLine_Step() | ||||
call date_and_time(values=timearray) | |||||
t(7) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(7) = time_ms() | |||||
t_modules(7) = t_modules(7)+t(7)-t(6) | t_modules(7) = t_modules(7)+t(7)-t(6) | ||||
call BlindRams_Step() | call BlindRams_Step() | ||||
call date_and_time(values=timearray) | |||||
t(8) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(8) = time_ms() | |||||
t_modules(8) = t_modules(8)+t(8)-t(7) | t_modules(8) = t_modules(8)+t(8)-t(7) | ||||
call Annular_Step() | call Annular_Step() | ||||
call date_and_time(values=timearray) | |||||
t(9) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(9) = time_ms() | |||||
t_modules(9) = t_modules(9)+t(9)-t(8) | t_modules(9) = t_modules(9)+t(9)-t(8) | ||||
!!Tarmigh. Step must rewrittem | !!Tarmigh. Step must rewrittem | ||||
call TopDrive_Step() | call TopDrive_Step() | ||||
call date_and_time(values=timearray) | |||||
t(10) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(10) = time_ms() | |||||
t_modules(10) = t_modules(10)+t(10)-t(9) | t_modules(10) = t_modules(10)+t(10)-t(9) | ||||
! call Geo_Step() | ! call Geo_Step() | ||||
!!Ahmadi | !!Ahmadi | ||||
call PathFinding_Step() | call PathFinding_Step() | ||||
call date_and_time(values=timearray) | |||||
t(11) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(11) = time_ms() | |||||
t_modules(11) = t_modules(11)+t(11)-t(10) | t_modules(11) = t_modules(11)+t(11)-t(10) | ||||
!! Sheikh | !! Sheikh | ||||
@@ -192,22 +190,25 @@ module Simulator | |||||
!! Ahmadi | !! Ahmadi | ||||
call OperationScenarios_Step() | call OperationScenarios_Step() | ||||
!! Write variables to shared files | !! Write variables to shared files | ||||
call date_and_time(values=timearray) | |||||
t2 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t2 = time_ms() | |||||
! stepTime = t2-t1 | ! stepTime = t2-t1 | ||||
t_modules(12) = t_modules(12)+t2-t(11) | t_modules(12) = t_modules(12)+t2-t(11) | ||||
t_exec = t_exec+t2-t1 | t_exec = t_exec+t2-t1 | ||||
! call date_and_time(values=timearray) | ! call date_and_time(values=timearray) | ||||
! t0 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
! t0 = time_ms() | |||||
call write_variables() | call write_variables() | ||||
call date_and_time(values=timearray) | |||||
t3 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t3 = time_ms() | |||||
if(t3-t0 < 100) then | |||||
call sleepqq(t3-t0) | |||||
else | |||||
print *,"Simulation step can not be complete in 100 ms. step time=",t3-t0 | |||||
endif | |||||
t_write = t_write+t3-t2 | t_write = t_write+t3-t2 | ||||
! print *,"write completed" | ! print *,"write completed" | ||||
! print *,"t=",t | ! print *,"t=",t | ||||
simulationStep = simulationStep + 1 | simulationStep = simulationStep + 1 | ||||
end do | |||||
211 end do | |||||
! call write_variables() | ! call write_variables() | ||||
! call json%print(jsonroot,'test.json') | ! call json%print(jsonroot,'test.json') | ||||
! call json%destroy(jsonroot) | ! call json%destroy(jsonroot) | ||||
@@ -1,5 +1,6 @@ | |||||
# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Simulator.f90" | # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Simulator.f90" | ||||
module Simulator | module Simulator | ||||
use IFPORT | |||||
use RedisInterface | use RedisInterface | ||||
use Bop | use Bop | ||||
use PumpsMain | use PumpsMain | ||||
@@ -68,7 +69,6 @@ module Simulator | |||||
type(json_file) :: jsonfile | type(json_file) :: jsonfile | ||||
type(json_core):: json | type(json_core):: json | ||||
integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep | integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep | ||||
integer,dimension(8)::timearray | |||||
real :: stepTime !time for each step | real :: stepTime !time for each step | ||||
character(len=:),allocatable::redisInput,redisOutput | character(len=:),allocatable::redisInput,redisOutput | ||||
enum, bind(c) | enum, bind(c) | ||||
@@ -80,10 +80,18 @@ module Simulator | |||||
contains | contains | ||||
FUNCTION time_ms() | |||||
INTEGER(8) :: time_ms | |||||
integer,dimension(8)::timearray | |||||
call date_and_time(values=timearray) | |||||
time_ms = timearray(8)+timearray(7)*1000 + timearray(6)*60000 + timearray(5)*60000*600000 +timearray(4)*24*60000*60000 | |||||
RETURN | |||||
END FUNCTION | |||||
subroutine Simulate(redis_host,redis_port,redis_password, sim_id,log_level) | subroutine Simulate(redis_host,redis_port,redis_password, sim_id,log_level) | ||||
character(len=*) :: redis_host,redis_password, sim_id | character(len=*) :: redis_host,redis_password, sim_id | ||||
integer::t0,t1,t2,t3,t_read=0,t_write=0,t_exec=0,i,status,redis_port,log_level | integer::t0,t1,t2,t3,t_read=0,t_write=0,t_exec=0,i,status,redis_port,log_level | ||||
integer,dimension(12)::t,t_modules | |||||
integer(8),dimension(12)::t,t_modules | |||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||||
do i=1,size(t_modules) | do i=1,size(t_modules) | ||||
@@ -105,45 +113,41 @@ module Simulator | |||||
simulationStep = 1 | simulationStep = 1 | ||||
do while (.true.) | do while (.true.) | ||||
! print *,"simulationStep=",simulationStep | ! print *,"simulationStep=",simulationStep | ||||
call date_and_time(values=timearray) | |||||
t0 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t0 = time_ms() | |||||
! print *,"start reading." | ! print *,"start reading." | ||||
call read_variables() | call read_variables() | ||||
if(simulationStatus==PLAY_TO_DETERMINED_TIME .and. simulationStep>simulationEnd) exit | if(simulationStatus==PLAY_TO_DETERMINED_TIME .and. simulationStep>simulationEnd) exit | ||||
if(simulationStatus==STOP) exit | if(simulationStatus==STOP) exit | ||||
if(simulationStatus==PAUSE) cycle | |||||
if(simulationStatus==PAUSE) then | |||||
print *, "paused" | |||||
go to 211 | |||||
endif | |||||
if(logging>4) print *,"end reading" | if(logging>4) print *,"end reading" | ||||
call date_and_time(values=timearray) | |||||
t1 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t1 = time_ms() | |||||
t_read = t_read+t1-t0 | t_read = t_read+t1-t0 | ||||
if(logging>4) print *,"read completed" | if(logging>4) print *,"read completed" | ||||
!! Rafiee, nothing changed | !! Rafiee, nothing changed | ||||
call BopStack_Step() | call BopStack_Step() | ||||
call date_and_time(values=timearray) | |||||
t(1) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(1) = time_ms() | |||||
t_modules(1) = t_modules(1)+t(1)-t1 | t_modules(1) = t_modules(1)+t(1)-t1 | ||||
!! Tarmigh, now is rewritten | !! Tarmigh, now is rewritten | ||||
call Pump1_Step() | call Pump1_Step() | ||||
call date_and_time(values=timearray) | |||||
t(2) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(2) = time_ms() | |||||
t_modules(2) = t_modules(2)+t(2)-t(1) | t_modules(2) = t_modules(2)+t(2)-t(1) | ||||
!call Pump2_Step() | !call Pump2_Step() | ||||
!! Rafiee | !! Rafiee | ||||
call ChokeControl_Step() | call ChokeControl_Step() | ||||
call date_and_time(values=timearray) | |||||
t(3) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(3) = time_ms() | |||||
t_modules(3) = t_modules(3)+t(3)-t(2) | t_modules(3) = t_modules(3)+t(3)-t(2) | ||||
!! Tarmigh, now is rewritten | !! Tarmigh, now is rewritten | ||||
call RotaryTable_Step() | call RotaryTable_Step() | ||||
call date_and_time(values=timearray) | |||||
t(4) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(4) = time_ms() | |||||
t_modules(4) = t_modules(4)+t(4)-t(3) | t_modules(4) = t_modules(4)+t(4)-t(3) | ||||
!! Tarmigh, now is rewritten | !! Tarmigh, now is rewritten | ||||
call Drawworks_Step() | call Drawworks_Step() | ||||
call date_and_time(values=timearray) | |||||
t(5) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(5) = time_ms() | |||||
t_modules(5) = t_modules(5)+t(5)-t(4) | t_modules(5) = t_modules(5)+t(5)-t(4) | ||||
!! Rafiee | !! Rafiee | ||||
@@ -155,37 +159,31 @@ module Simulator | |||||
!! Rafiee | !! Rafiee | ||||
call KillLine_Step() | call KillLine_Step() | ||||
call date_and_time(values=timearray) | |||||
t(6) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(6) = time_ms() | |||||
t_modules(6) = t_modules(6)+t(6)-t(5) | t_modules(6) = t_modules(6)+t(6)-t(5) | ||||
!! Rafiee | !! Rafiee | ||||
call ChokeLine_Step() | call ChokeLine_Step() | ||||
call date_and_time(values=timearray) | |||||
t(7) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(7) = time_ms() | |||||
t_modules(7) = t_modules(7)+t(7)-t(6) | t_modules(7) = t_modules(7)+t(7)-t(6) | ||||
call BlindRams_Step() | call BlindRams_Step() | ||||
call date_and_time(values=timearray) | |||||
t(8) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(8) = time_ms() | |||||
t_modules(8) = t_modules(8)+t(8)-t(7) | t_modules(8) = t_modules(8)+t(8)-t(7) | ||||
call Annular_Step() | call Annular_Step() | ||||
call date_and_time(values=timearray) | |||||
t(9) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(9) = time_ms() | |||||
t_modules(9) = t_modules(9)+t(9)-t(8) | t_modules(9) = t_modules(9)+t(9)-t(8) | ||||
!!Tarmigh. Step must rewrittem | !!Tarmigh. Step must rewrittem | ||||
call TopDrive_Step() | call TopDrive_Step() | ||||
call date_and_time(values=timearray) | |||||
t(10) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(10) = time_ms() | |||||
t_modules(10) = t_modules(10)+t(10)-t(9) | t_modules(10) = t_modules(10)+t(10)-t(9) | ||||
! call Geo_Step() | ! call Geo_Step() | ||||
!!Ahmadi | !!Ahmadi | ||||
call PathFinding_Step() | call PathFinding_Step() | ||||
call date_and_time(values=timearray) | |||||
t(11) = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t(11) = time_ms() | |||||
t_modules(11) = t_modules(11)+t(11)-t(10) | t_modules(11) = t_modules(11)+t(11)-t(10) | ||||
!! Sheikh | !! Sheikh | ||||
@@ -193,22 +191,25 @@ module Simulator | |||||
!! Ahmadi | !! Ahmadi | ||||
call OperationScenarios_Step() | call OperationScenarios_Step() | ||||
!! Write variables to shared files | !! Write variables to shared files | ||||
call date_and_time(values=timearray) | |||||
t2 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t2 = time_ms() | |||||
! stepTime = t2-t1 | ! stepTime = t2-t1 | ||||
t_modules(12) = t_modules(12)+t2-t(11) | t_modules(12) = t_modules(12)+t2-t(11) | ||||
t_exec = t_exec+t2-t1 | t_exec = t_exec+t2-t1 | ||||
! call date_and_time(values=timearray) | ! call date_and_time(values=timearray) | ||||
! t0 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
! t0 = time_ms() | |||||
call write_variables() | call write_variables() | ||||
call date_and_time(values=timearray) | |||||
t3 = timearray(8)+timearray(7)*1000+timearray(6)*60000 | |||||
t3 = time_ms() | |||||
if(t3-t0 < 100) then | |||||
call sleepqq(t3-t0) | |||||
else | |||||
print *,"Simulation step can not be complete in 100 ms. step time=",t3-t0 | |||||
endif | |||||
t_write = t_write+t3-t2 | t_write = t_write+t3-t2 | ||||
! print *,"write completed" | ! print *,"write completed" | ||||
! print *,"t=",t | ! print *,"t=",t | ||||
simulationStep = simulationStep + 1 | simulationStep = simulationStep + 1 | ||||
end do | |||||
211 end do | |||||
! call write_variables() | ! call write_variables() | ||||
! call json%print(jsonroot,'test.json') | ! call json%print(jsonroot,'test.json') | ||||
! call json%destroy(jsonroot) | ! call json%destroy(jsonroot) | ||||
@@ -35,12 +35,8 @@ if __name__=='__main__': | |||||
break | break | ||||
if not process_exists: | if not process_exists: | ||||
subprocess.Popen(['./SimulationCore2', redis_address,str(redis_port),redis_password,simulation_id,str(log_level)], cwd=work_dir) | subprocess.Popen(['./SimulationCore2', redis_address,str(redis_port),redis_password,simulation_id,str(log_level)], cwd=work_dir) | ||||
time.sleep(5) | time.sleep(5) | ||||
# Connect to Redis server | # Connect to Redis server | ||||
redis_host = 'localhost' # Replace with your Redis server's host | redis_host = 'localhost' # Replace with your Redis server's host | ||||
redis_port = 6379 # Replace with your Redis server's port | redis_port = 6379 # Replace with your Redis server's port | ||||