@@ -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","4567bdd6-2af8-4d03-ab5e-08db9deec266","5"], | "args": ["aberama.iran.liara.ir","32815","4YKFnubfFFjfh4yTK7b0Rg9X","60f8144a-c1b7-4d1a-5d99-08db9e4e35f5","5","1000"], | ||||
"stopAtEntry": false, | "stopAtEntry": false, | ||||
"cwd": "${workspaceRoot}", | "cwd": "${workspaceRoot}", | ||||
"externalConsole": false, | "externalConsole": false, | ||||
@@ -18,14 +18,14 @@ 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, status | integer :: redis_port, log_level, status,stepTime | ||||
! Variables | ! Variables | ||||
! Body of SimulationCore2 | ! Body of SimulationCore2 | ||||
! print *, 'Hello World' | ! print *, 'Hello World' | ||||
! call read_variables() | ! call read_variables() | ||||
if(command_argument_count()/=5) then | if(command_argument_count()/=6) then | ||||
print *, "Simulator Program must have 5 parameter: redis_host,redisPort,redis_password, sim_id,log_level" | print *, "Simulator Program must have 6 parameter: redis_host,redisPort,redis_password, sim_id,log_level" | ||||
stop | stop | ||||
endif | endif | ||||
call get_command_argument(1, redis_host) | call get_command_argument(1, redis_host) | ||||
@@ -35,7 +35,9 @@ program SimulationCore2 | |||||
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=status) log_level | read(temp,*,iostat=status) log_level | ||||
call get_command_argument(6, temp) | |||||
read(temp,*,iostat=status) stepTime | |||||
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,stepTime) | ||||
end program SimulationCore2 | end program SimulationCore2 | ||||
@@ -19,14 +19,14 @@ 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, status | integer :: redis_port, log_level, status,stepTime | ||||
! Variables | ! Variables | ||||
! Body of SimulationCore2 | ! Body of SimulationCore2 | ||||
! print *, 'Hello World' | ! print *, 'Hello World' | ||||
! call read_variables() | ! call read_variables() | ||||
if(command_argument_count()/=5) then | if(command_argument_count()/=6) then | ||||
print *, "Simulator Program must have 5 parameter: redis_host,redisPort,redis_password, sim_id,log_level" | print *, "Simulator Program must have 6 parameter: redis_host,redisPort,redis_password, sim_id,log_level" | ||||
stop | stop | ||||
endif | endif | ||||
call get_command_argument(1, redis_host) | call get_command_argument(1, redis_host) | ||||
@@ -36,7 +36,9 @@ program SimulationCore2 | |||||
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=status) log_level | read(temp,*,iostat=status) log_level | ||||
call get_command_argument(6, temp) | |||||
read(temp,*,iostat=status) stepTime | |||||
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,stepTime) | ||||
end program SimulationCore2 | end program SimulationCore2 | ||||
@@ -67,7 +67,6 @@ module Simulator | |||||
implicit none | implicit none | ||||
type(json_core):: jsoncore | type(json_core):: jsoncore | ||||
integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep | integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep | ||||
real :: stepTime !time for each step | |||||
character(len=:),allocatable::redisInput,redisOutput | character(len=:),allocatable::redisInput,redisOutput | ||||
enum, bind(c) | enum, bind(c) | ||||
enumerator :: PLAY = 1 | enumerator :: PLAY = 1 | ||||
@@ -86,9 +85,9 @@ module Simulator | |||||
RETURN | RETURN | ||||
END FUNCTION | 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,stepTime) | ||||
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,stepTime | ||||
integer(8),dimension(12)::t,t_modules | integer(8),dimension(12)::t,t_modules | ||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||||
@@ -198,8 +197,8 @@ module Simulator | |||||
! t0 = time_ms() | ! t0 = time_ms() | ||||
call write_variables() | call write_variables() | ||||
t3 = time_ms() | t3 = time_ms() | ||||
if(t3-t0 < 100) then | if(t3-t0 < stepTime) then | ||||
call sleepqq(t3-t0) | call sleepqq(stepTime-t3+t0) | ||||
else | else | ||||
print *,"Simulation step can not be complete in 100 ms. step time=",t3-t0 | print *,"Simulation step can not be complete in 100 ms. step time=",t3-t0 | ||||
endif | endif | ||||
@@ -328,7 +327,7 @@ module Simulator | |||||
! open(1,file="redisContent.json",status="REPLACE") | ! open(1,file="redisContent.json",status="REPLACE") | ||||
! write(1,"(A)") redisContent | ! write(1,"(A)") redisContent | ||||
! close(1) | ! close(1) | ||||
call jsoncore%initialize() | call jsoncore%initialize() | ||||
call jsonfile%initialize(jsoncore) | call jsonfile%initialize(jsoncore) | ||||
call jsonfile%deserialize(redisOutput) | call jsonfile%deserialize(redisOutput) | ||||
call jsonfile%json_file_get_root(jsonroot) | call jsonfile%json_file_get_root(jsonroot) | ||||
@@ -68,7 +68,6 @@ module Simulator | |||||
implicit none | implicit none | ||||
type(json_core):: jsoncore | type(json_core):: jsoncore | ||||
integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep | integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep | ||||
real :: stepTime !time for each step | |||||
character(len=:),allocatable::redisInput,redisOutput | character(len=:),allocatable::redisInput,redisOutput | ||||
enum, bind(c) | enum, bind(c) | ||||
enumerator :: PLAY = 1 | enumerator :: PLAY = 1 | ||||
@@ -87,9 +86,9 @@ module Simulator | |||||
RETURN | RETURN | ||||
END FUNCTION | 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,stepTime) | ||||
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,stepTime | ||||
integer(8),dimension(12)::t,t_modules | integer(8),dimension(12)::t,t_modules | ||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||||
@@ -199,8 +198,8 @@ module Simulator | |||||
! t0 = time_ms() | ! t0 = time_ms() | ||||
call write_variables() | call write_variables() | ||||
t3 = time_ms() | t3 = time_ms() | ||||
if(t3-t0 < 100) then | if(t3-t0 < stepTime) then | ||||
call sleepqq(t3-t0) | call sleepqq(stepTime-t3+t0) | ||||
else | else | ||||
print *,"Simulation step can not be complete in 100 ms. step time=",t3-t0 | print *,"Simulation step can not be complete in 100 ms. step time=",t3-t0 | ||||
endif | endif | ||||
@@ -329,7 +328,7 @@ module Simulator | |||||
! open(1,file="redisContent.json",status="REPLACE") | ! open(1,file="redisContent.json",status="REPLACE") | ||||
! write(1,"(A)") redisContent | ! write(1,"(A)") redisContent | ||||
! close(1) | ! close(1) | ||||
call jsoncore%initialize() | call jsoncore%initialize() | ||||
call jsonfile%initialize(jsoncore) | call jsonfile%initialize(jsoncore) | ||||
call jsonfile%deserialize(redisOutput) | call jsonfile%deserialize(redisOutput) | ||||
call jsonfile%json_file_get_root(jsonroot) | call jsonfile%json_file_get_root(jsonroot) | ||||
@@ -7,5 +7,6 @@ | |||||
}, | }, | ||||
"logging":4, | "logging":4, | ||||
"process_name": "SimulationCore2", | "process_name": "SimulationCore2", | ||||
"work_dir" : "/mnt/c/Projects/VSIM/SimulationCore2" | "work_dir" : "/mnt/c/Projects/VSIM/SimulationCore2", | ||||
"step_time" : 1000 | |||||
} | } |
@@ -1,5 +1,5 @@ | |||||
{ | { | ||||
"step": 83, | "step": 502, | ||||
"Warnings": { | "Warnings": { | ||||
"PumpWithKellyDisconnected": false, | "PumpWithKellyDisconnected": false, | ||||
"PumpWithTopdriveDisconnected": false, | "PumpWithTopdriveDisconnected": false, | ||||
@@ -20,7 +20,7 @@ | |||||
"DrillPipeParted": false, | "DrillPipeParted": false, | ||||
"TripWithSlipsSet": false, | "TripWithSlipsSet": false, | ||||
"Blowout": false, | "Blowout": false, | ||||
"UndergroundBlowout": false, | "UndergroundBlowout": true, | ||||
"MaximumWellDepthExceeded": false, | "MaximumWellDepthExceeded": false, | ||||
"CrownCollision": false, | "CrownCollision": false, | ||||
"FloorCollision": false, | "FloorCollision": false, | ||||
@@ -99,7 +99,7 @@ | |||||
"RTTorque": 0.0E+0, | "RTTorque": 0.0E+0, | ||||
"RTRPM": 0.0E+0, | "RTRPM": 0.0E+0, | ||||
"WOP": 0.0E+0, | "WOP": 0.0E+0, | ||||
"ROP": "NaN", | "ROP": 0.0E+0, | ||||
"MudWeightIn": 0.0E+0, | "MudWeightIn": 0.0E+0, | ||||
"MudWeightOut": 0.0E+0, | "MudWeightOut": 0.0E+0, | ||||
"Buzzer1": false, | "Buzzer1": false, | ||||
@@ -142,7 +142,7 @@ | |||||
}, | }, | ||||
"Hook": { | "Hook": { | ||||
"HookHeight_S": 0.0E+0, | "HookHeight_S": 0.0E+0, | ||||
"HookHeight": "NaN" | "HookHeight": 0.57152001953125E+3 | ||||
}, | }, | ||||
"StandPipeManifold": { | "StandPipeManifold": { | ||||
"StandPipeGauge1": 0.0E+0, | "StandPipeGauge1": 0.0E+0, | ||||
@@ -154,14 +154,14 @@ | |||||
"HookLoad": 0.0E+0, | "HookLoad": 0.0E+0, | ||||
"WeightOnBit": 0.0E+0, | "WeightOnBit": 0.0E+0, | ||||
"RPM": 0.0E+0, | "RPM": 0.0E+0, | ||||
"ROP": "NaN", | "ROP": 0.0E+0, | ||||
"Torque": 0.0E+0, | "Torque": 0.0E+0, | ||||
"PumpPressure": 0.0E+0, | "PumpPressure": 0.0E+0, | ||||
"SPM1": 0.0E+0, | "SPM1": 0.0E+0, | ||||
"SPM2": 0.0E+0, | "SPM2": 0.0E+0, | ||||
"CasingPressure": 0.0E+0, | "CasingPressure": 0.0E+0, | ||||
"PercentFlow": 0.0E+0, | "PercentFlow": "NaN", | ||||
"PitGainLose": -0.32000000000000001E+0, | "PitGainLose": 0.0E+0, | ||||
"PitVolume": 0.0E+0, | "PitVolume": 0.0E+0, | ||||
"KillMudVolume": 0.0E+0, | "KillMudVolume": 0.0E+0, | ||||
"TripTankVolume": 0.0E+0, | "TripTankVolume": 0.0E+0, | ||||
@@ -19,6 +19,7 @@ if __name__=='__main__': | |||||
redis_port = config['redis']['port'] | redis_port = config['redis']['port'] | ||||
log_level = config['logging'] | log_level = config['logging'] | ||||
work_dir = config['work_dir'] | work_dir = config['work_dir'] | ||||
stepTime = config['step_time'] | |||||
process_name = config['process_name'] | process_name = config['process_name'] | ||||
r = redis.Redis(host=redis_address, port=redis_port, decode_responses=True,password=redis_password) | r = redis.Redis(host=redis_address, port=redis_port, decode_responses=True,password=redis_password) | ||||
@@ -34,38 +35,5 @@ if __name__=='__main__': | |||||
process_exists = True | process_exists = True | ||||
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),str(stepTime)], cwd=work_dir) | ||||
time.sleep(5) | time.sleep(5) | ||||
# Connect to Redis server | |||||
redis_host = 'localhost' # Replace with your Redis server's host | |||||
redis_port = 6379 # Replace with your Redis server's port | |||||
redis_client = redis.Redis(host=redis_host, port=redis_port) | |||||
if redis_client is None: | |||||
print(f"Can not connect to {redis_host}.\nExiting...") | |||||
exit(1) | |||||
# Main loop | |||||
while True: | |||||
# Retrieve array from Redis | |||||
simulations = redis_client.lrange('simulations', 0, -1) | |||||
# Check each entry in the array | |||||
for entry in simulations: | |||||
simulation_id = entry.decode() | |||||
# Check if 'SimulationCore2' process with specific parameter is running | |||||
process_name = 'SimulationCore2' | |||||
process_exists = False | |||||
for proc in psutil.process_iter(['pid', 'name', 'cmdline']): | |||||
if proc.info['name'] == process_name and len(proc.info['cmdline']) > 1 and proc.info['cmdline'][1] == simulation_id: | |||||
process_exists = True | |||||
break | |||||
if not process_exists: | |||||
# Run 'SimulationCore2' process with specific parameter | |||||
printf(f"Starting new simulator process for {simulation_id}") | |||||
subprocess.Popen(['./SimulationCore2', simulation_id], cwd='/path/to/SimulationCore2/directory') | |||||
# Wait for 1 second before checking again | |||||
time.sleep(1) |