Browse Source

First Demo

master
mahmood19227 1 year ago
parent
commit
17745d3016
10 changed files with 35 additions and 64 deletions
  1. +1
    -1
      .vscode/launch.json
  2. BIN
     
  3. +6
    -4
      SimulationCore2.f90
  4. +6
    -4
      SimulationCore2.i90
  5. +5
    -6
      Simulator.f90
  6. +5
    -6
      Simulator.i90
  7. +2
    -1
      config-remote.json
  8. +7
    -7
      data_out.json
  9. +1
    -1
      redisContent.json
  10. +2
    -34
      simulatorManager.py

+ 1
- 1
.vscode/launch.json View File

@@ -30,7 +30,7 @@
"type": "cppdbg",
"request": "launch",
"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,
"cwd": "${workspaceRoot}",
"externalConsole": false,


BIN
View File


+ 6
- 4
SimulationCore2.f90 View File

@@ -18,14 +18,14 @@ program SimulationCore2
!use testRedisModule
implicit none
character(len=100) :: redis_host,redis_password, sim_id, temp
integer :: redis_port, log_level, status
integer :: redis_port, log_level, status,stepTime
! 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"
if(command_argument_count()/=6) then
print *, "Simulator Program must have 6 parameter: redis_host,redisPort,redis_password, sim_id,log_level"
stop
endif
call get_command_argument(1, redis_host)
@@ -35,7 +35,9 @@ program SimulationCore2
call get_command_argument(4, sim_id)
call get_command_argument(5, temp)
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


+ 6
- 4
SimulationCore2.i90 View File

@@ -19,14 +19,14 @@ program SimulationCore2
!use testRedisModule
implicit none
character(len=100) :: redis_host,redis_password, sim_id, temp
integer :: redis_port, log_level, status
integer :: redis_port, log_level, status,stepTime
! 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"
if(command_argument_count()/=6) then
print *, "Simulator Program must have 6 parameter: redis_host,redisPort,redis_password, sim_id,log_level"
stop
endif
call get_command_argument(1, redis_host)
@@ -36,7 +36,9 @@ program SimulationCore2
call get_command_argument(4, sim_id)
call get_command_argument(5, temp)
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


+ 5
- 6
Simulator.f90 View File

@@ -67,7 +67,6 @@ module Simulator
implicit none
type(json_core):: jsoncore
integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep
real :: stepTime !time for each step
character(len=:),allocatable::redisInput,redisOutput
enum, bind(c)
enumerator :: PLAY = 1
@@ -86,9 +85,9 @@ module Simulator
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,stepTime)
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -198,8 +197,8 @@ module Simulator
! t0 = time_ms()
call write_variables()
t3 = time_ms()
if(t3-t0 < 100) then
call sleepqq(t3-t0)
if(t3-t0 < stepTime) then
call sleepqq(stepTime-t3+t0)
else
print *,"Simulation step can not be complete in 100 ms. step time=",t3-t0
endif
@@ -328,7 +327,7 @@ module Simulator
! open(1,file="redisContent.json",status="REPLACE")
! write(1,"(A)") redisContent
! close(1)
call jsoncore%initialize()
call jsoncore%initialize()
call jsonfile%initialize(jsoncore)
call jsonfile%deserialize(redisOutput)
call jsonfile%json_file_get_root(jsonroot)


+ 5
- 6
Simulator.i90 View File

@@ -68,7 +68,6 @@ module Simulator
implicit none
type(json_core):: jsoncore
integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep
real :: stepTime !time for each step
character(len=:),allocatable::redisInput,redisOutput
enum, bind(c)
enumerator :: PLAY = 1
@@ -87,9 +86,9 @@ module Simulator
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,stepTime)
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@@ -199,8 +198,8 @@ module Simulator
! t0 = time_ms()
call write_variables()
t3 = time_ms()
if(t3-t0 < 100) then
call sleepqq(t3-t0)
if(t3-t0 < stepTime) then
call sleepqq(stepTime-t3+t0)
else
print *,"Simulation step can not be complete in 100 ms. step time=",t3-t0
endif
@@ -329,7 +328,7 @@ module Simulator
! open(1,file="redisContent.json",status="REPLACE")
! write(1,"(A)") redisContent
! close(1)
call jsoncore%initialize()
call jsoncore%initialize()
call jsonfile%initialize(jsoncore)
call jsonfile%deserialize(redisOutput)
call jsonfile%json_file_get_root(jsonroot)


+ 2
- 1
config-remote.json View File

@@ -7,5 +7,6 @@
},
"logging":4,
"process_name": "SimulationCore2",
"work_dir" : "/mnt/c/Projects/VSIM/SimulationCore2"
"work_dir" : "/mnt/c/Projects/VSIM/SimulationCore2",
"step_time" : 1000
}

+ 7
- 7
data_out.json View File

@@ -1,5 +1,5 @@
{
"step": 83,
"step": 502,
"Warnings": {
"PumpWithKellyDisconnected": false,
"PumpWithTopdriveDisconnected": false,
@@ -20,7 +20,7 @@
"DrillPipeParted": false,
"TripWithSlipsSet": false,
"Blowout": false,
"UndergroundBlowout": false,
"UndergroundBlowout": true,
"MaximumWellDepthExceeded": false,
"CrownCollision": false,
"FloorCollision": false,
@@ -99,7 +99,7 @@
"RTTorque": 0.0E+0,
"RTRPM": 0.0E+0,
"WOP": 0.0E+0,
"ROP": "NaN",
"ROP": 0.0E+0,
"MudWeightIn": 0.0E+0,
"MudWeightOut": 0.0E+0,
"Buzzer1": false,
@@ -142,7 +142,7 @@
},
"Hook": {
"HookHeight_S": 0.0E+0,
"HookHeight": "NaN"
"HookHeight": 0.57152001953125E+3
},
"StandPipeManifold": {
"StandPipeGauge1": 0.0E+0,
@@ -154,14 +154,14 @@
"HookLoad": 0.0E+0,
"WeightOnBit": 0.0E+0,
"RPM": 0.0E+0,
"ROP": "NaN",
"ROP": 0.0E+0,
"Torque": 0.0E+0,
"PumpPressure": 0.0E+0,
"SPM1": 0.0E+0,
"SPM2": 0.0E+0,
"CasingPressure": 0.0E+0,
"PercentFlow": 0.0E+0,
"PitGainLose": -0.32000000000000001E+0,
"PercentFlow": "NaN",
"PitGainLose": 0.0E+0,
"PitVolume": 0.0E+0,
"KillMudVolume": 0.0E+0,
"TripTankVolume": 0.0E+0,


+ 1
- 1
redisContent.json
File diff suppressed because it is too large
View File


+ 2
- 34
simulatorManager.py View File

@@ -19,6 +19,7 @@ if __name__=='__main__':
redis_port = config['redis']['port']
log_level = config['logging']
work_dir = config['work_dir']
stepTime = config['step_time']
process_name = config['process_name']

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
break
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)

# 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)

Loading…
Cancel
Save