Simulation Core
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

825 linhas
29 KiB

  1. module Simulator
  2. use IFPORT
  3. use RedisInterface
  4. use Bop
  5. use PumpsMain
  6. use RopMain
  7. use RotaryTableMain
  8. use DrawworksMain
  9. use FluidFlowMain
  10. use TorqueDragMain
  11. use MudSystemMain
  12. use PipeRams1Main
  13. use PipeRams2Main
  14. use KillLineMain
  15. use ChokeLineMain
  16. use BlindRamsMain
  17. use AnnularMain
  18. use TopDriveMain
  19. use CManifolds
  20. use GeoMain
  21. use ChokeControlMain
  22. use COperationScenariosMain
  23. ! For Json read and write
  24. use CStringConfiguration
  25. use CFormation
  26. use CReservoir
  27. use CShoe
  28. use CAccumulator
  29. use CBopStack
  30. use CHoisting
  31. use CPower
  32. use CPumpsVariables
  33. use CRigSize
  34. use CCasingLinerChoke
  35. use CPathGeneration
  36. use CWellSurveyData
  37. use MudPropertiesModule
  38. use CBitProblems
  39. use CBopProblems
  40. use CChokeProblems
  41. use CDrillStemProblems
  42. use CGaugesProblems
  43. use CHoistingProblems
  44. use CKickProblems
  45. use CLostProblems
  46. use CMudTreatmentProblems
  47. use COtherProblems
  48. use CPumpProblems
  49. use CRotaryProblems
  50. use OperationScenariosModule
  51. use PermissionsModule
  52. use UnitySignalsModule
  53. use CBopControlPanel
  54. use CChokeControlPanel
  55. use CChokeManifold
  56. use CDataDisplayConsole
  57. use CDrillingConsole
  58. use CHook
  59. use CStandPipeManifold
  60. use CTopDrivePanel
  61. use DrillingWatchModule
  62. use CTanks
  63. use UnityModule
  64. implicit none
  65. type(json_core):: jsoncore
  66. integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep
  67. logical::Kelly_ConnectionNothing_in_progress=.false.
  68. character(len=:),allocatable::redisInput
  69. character(len=:),allocatable::redisOutput,operationScenarioEvent
  70. character(len=100)::simulationId
  71. enum, bind(c)
  72. enumerator :: PLAY = 1
  73. enumerator :: PAUSE = 2
  74. enumerator :: STOP = 3
  75. enumerator :: PLAY_TO_DETERMINED_TIME = 4
  76. end enum
  77. contains
  78. FUNCTION time_ms()
  79. INTEGER(8) :: time_ms
  80. integer,dimension(8)::timearray
  81. call date_and_time(values=timearray)
  82. time_ms = timearray(8)+timearray(7)*1000 + timearray(6)*60000 + timearray(5)*60000*600000 +timearray(4)*24*60000*60000
  83. RETURN
  84. END FUNCTION
  85. subroutine Simulate(redis_host,redis_port,redis_password, sim_id,stepTime,print_freq)
  86. character(len=*) :: redis_host,redis_password, sim_id
  87. integer::t0,t1,t2,t3,t_read=0,t_write=0,t_exec=0,i,status,redis_port,stepTime,print_freq
  88. integer(8),dimension(12)::t,t_modules
  89. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  90. simulationId = sim_id
  91. do i=1,size(t_modules)
  92. t_modules(i)=0
  93. end do
  94. ! call initSimulation(configFilename)
  95. call initConnection(redis_host,redis_port,redis_password, sim_id,status)
  96. if (status<0) then
  97. print *,"Can not init connection to redis."
  98. stop
  99. endif
  100. call read_configuration()
  101. ! call read_variables()
  102. print *,"connection initialized"
  103. call init_modules()
  104. print *,"modules initialized"
  105. ! call cpu_time(T1)
  106. simulationStep = 1
  107. !$omp parallel sections
  108. !$omp section
  109. call listenToChannel()
  110. !$omp section
  111. ! call sleepqq(100000)
  112. do while (.true.)
  113. if(mod(simulationStep,print_freq)==0) then
  114. print_log=.true.
  115. ! call publishMessageToChannel("Hello from FORTRAN!")
  116. else
  117. print_log=.false.
  118. endif
  119. t0 = time_ms()
  120. if(print_log) print *,"simulationStep = ",simulationStep
  121. call read_variables()
  122. if(simulationStatus==PLAY_TO_DETERMINED_TIME .and. simulationStep>simulationEnd) exit
  123. if(simulationStatus==STOP) exit
  124. if(simulationStatus==PAUSE) then
  125. if(print_log) print *, "Paused"
  126. call sleepqq(stepTime)
  127. go to 211
  128. endif
  129. t1 = time_ms()
  130. t_read = t_read+t1-t0
  131. call logg(4,"read completed")
  132. !! Rafiee, nothing changed
  133. call BopStack_Step()
  134. t(1) = time_ms()
  135. t_modules(1) = t_modules(1)+t(1)-t1
  136. !! Tarmigh, now is rewritten
  137. call Pumps_MainSolver()
  138. t(2) = time_ms()
  139. t_modules(2) = t_modules(2)+t(2)-t(1)
  140. !call Pump2_Step()
  141. !! Rafiee
  142. call ChokeControl_Step()
  143. t(3) = time_ms()
  144. t_modules(3) = t_modules(3)+t(3)-t(2)
  145. !! Tarmigh, now is rewritten
  146. call RotaryTable_Step()
  147. t(4) = time_ms()
  148. t_modules(4) = t_modules(4)+t(4)-t(3)
  149. !! Tarmigh, now is rewritten
  150. call Drawworks_Step()
  151. t(5) = time_ms()
  152. t_modules(5) = t_modules(5)+t(5)-t(4)
  153. !! Rafiee
  154. call MudSystem_Step()
  155. !! Rafiee
  156. call PipeRams1_Step()
  157. call PipeRams2_Step()
  158. !! Rafiee
  159. call KillLine_Step()
  160. t(6) = time_ms()
  161. t_modules(6) = t_modules(6)+t(6)-t(5)
  162. !! Rafiee
  163. call ChokeLine_Step()
  164. t(7) = time_ms()
  165. t_modules(7) = t_modules(7)+t(7)-t(6)
  166. call BlindRams_Step()
  167. t(8) = time_ms()
  168. t_modules(8) = t_modules(8)+t(8)-t(7)
  169. call Annular_Step()
  170. t(9) = time_ms()
  171. t_modules(9) = t_modules(9)+t(9)-t(8)
  172. !!Tarmigh. Step must rewrittem
  173. call TopDrive_Step()
  174. t(10) = time_ms()
  175. t_modules(10) = t_modules(10)+t(10)-t(9)
  176. ! call Geo_Step()
  177. !!Ahmadi
  178. call PathFinding_Step()
  179. t(11) = time_ms()
  180. t_modules(11) = t_modules(11)+t(11)-t(10)
  181. !! Ahmadi
  182. call OperationScenarios_Step()
  183. !! Sheikh
  184. call FluidFlow_Step()
  185. !! Write variables to shared files
  186. t2 = time_ms()
  187. ! stepTime = t2-t1
  188. t_modules(12) = t_modules(12)+t2-t(11)
  189. t_exec = t_exec+t2-t1
  190. ! call date_and_time(values=timearray)
  191. ! t0 = time_ms()
  192. call write_variables()
  193. t3 = time_ms()
  194. if(t3-t0 < stepTime) then
  195. call sleepqq(stepTime-t3+t0)
  196. else
  197. print *,"Simulation step can not be complete in 100 ms. step time=",t3-t0
  198. endif
  199. t_write = t_write+t3-t2
  200. ! print *,"write completed"
  201. ! print *,"t=",t
  202. simulationStep = simulationStep + 1
  203. 211 end do
  204. !$omp end parallel sections
  205. ! call write_variables()
  206. ! call json%print(jsonroot,'test.json')
  207. ! call json%destroy(jsonroot)
  208. do i=1,size(t)
  209. print *,"t_modules(",i,")=",t_modules(i)
  210. end do
  211. print *,"Number of steps =",simulationStep-1
  212. print *,"Read Time (from redis) =",t_read
  213. print *,"Write Time (to redis)=",t_write
  214. print *,"Simulation Time =",t_exec
  215. print *,"Total Time =",t_read+t_write+t_exec
  216. end subroutine Simulate
  217. subroutine write_variables()
  218. ! use CAccumulator
  219. use json_module
  220. implicit none
  221. type(json_value),pointer :: jsonroot
  222. ! character(len=:),allocatable::redisInput
  223. character(len=10)::str
  224. call jsoncore%initialize()
  225. call jsoncore%create_object(jsonroot,'')
  226. ! print *,"status=",simulationStatus
  227. ! call json%add(jsonroot,'status',simulationStatus)
  228. ! call json%add(jsonroot,'speed',simulationSpeed)
  229. ! call json%add(jsonroot,'endstep',simulationEnd)
  230. call jsoncore%add(jsonroot,'step',simulationStep)
  231. ! call ConfigurationToJson(jsonroot)
  232. call WarningsToJson(jsonroot)
  233. ! call ProblemsToJson(jsonroot)
  234. call EquipmentsToJson(jsonroot)
  235. call jsoncore%print_to_string(jsonroot,redisInput)
  236. if(log_level>4) then
  237. write(str, '(I0)') len(redisInput)
  238. print *,"Writing to redis:"//trim(str)
  239. endif
  240. call setData(redisInput)
  241. ! nullify(redisContent)
  242. ! deallocate(redisContent)
  243. ! call json%destroy(pval)
  244. call jsoncore%destroy(jsonroot)
  245. ! print *,"write ends"
  246. end subroutine
  247. subroutine read_configuration()
  248. type(json_value),pointer :: jsonroot,pval
  249. type(json_file) :: jsonfile
  250. type(json_core)::json
  251. integer::len
  252. ! character(len=:),allocatable::redisOutput
  253. ! call getData3(simulationId,redisOutput)
  254. call getData(redisOutput,len)
  255. ! print *,len(redisOutput)," bytes read from redis"
  256. open(1,file="redisContent.json",status="REPLACE")
  257. write(1,"(A)") redisOutput
  258. close(1)
  259. call jsonfile%initialize()
  260. call jsonfile%get_core(json)
  261. call jsonfile%deserialize(redisOutput(1:len))
  262. call jsonfile%json_file_get_root(jsonroot)
  263. ! call json%info(jsonvalue, n_children=n_children)
  264. ! print *,"n_children =",n_children
  265. call json%get(jsonroot,'status',pval)
  266. call json%get(pval,simulationStatus)
  267. call json%get(jsonroot,'speed',pval)
  268. call json%get(pval,simulationSpeed)
  269. if(simulationSpeed==0) simulationSpeed = 1
  270. msPerStep = 100/simulationSpeed
  271. call json%get(jsonroot,'endstep',pval)
  272. call json%get(pval,simulationEnd)
  273. call ConfigurationFromJson(jsonfile)
  274. call jsonfile%destroy()
  275. end subroutine
  276. subroutine read_variables()
  277. type(json_value),pointer :: jsonroot,pval
  278. type(json_file) :: jsonfile
  279. type(json_core)::json
  280. integer::stat,leng
  281. logical::found
  282. call getData(redisOutput,leng)
  283. open(1,file="redisContent.json",status="REPLACE")
  284. write(1,"(A)") redisOutput
  285. close(1)
  286. call jsonfile%initialize()
  287. call jsonfile%get_core(json)
  288. ! print *,"len_trim(redidOutput)=",len_trim(redisOutput)
  289. call jsonfile%deserialize(redisOutput(1:leng))
  290. call jsonfile%json_file_get_root(jsonroot)
  291. ! call json%info(jsonvalue, n_children=n_children)
  292. ! print *,"n_children =",n_children
  293. call json%get(jsonroot,'status',pval)
  294. call json%get(pval,stat)
  295. if (stat==0) then
  296. return
  297. endif
  298. simulationStatus = stat
  299. ! call jsonfile%get('OperationScenarioEvent',operationScenarioEvent,found)
  300. ! if ( .not. found .and. print_log) print *,"Not found: operationScenarioEvent"
  301. call json%get(jsonroot,'speed',pval)
  302. call json%get(pval,simulationSpeed)
  303. if(simulationSpeed==0) simulationSpeed = 1
  304. msPerStep = 100/simulationSpeed
  305. call json%get(jsonroot,'endstep',pval)
  306. call json%get(pval,simulationEnd)
  307. ! call ProblemsFromJson(jsonfile)
  308. call EquipmentsFromJson(jsonfile)
  309. call UnitySignalsFromJson(jsonfile)
  310. call jsonfile%destroy()
  311. end subroutine
  312. subroutine init_modules
  313. print *,"initializing modules"
  314. !Tarmigh
  315. call Pumps_StartUp()
  316. print *,"pump1 initialized"
  317. !call Pump2_Init()
  318. call RotaryTable_Init()
  319. print *,"RT initialized"
  320. call Drawworks_Init()
  321. call TopDrive_Init()
  322. print *,"TD initialized"
  323. !Nothing in init (and step)
  324. ! call Rop_Init()
  325. ! call TorqueDrag_Init()
  326. ! call Geo_Step()
  327. !! Rafiee
  328. call BopStack_Init()
  329. call ChokeControl_Init()
  330. call MudSystem_Init()
  331. ! call PipeRams1_Init()
  332. ! call PipeRams2_Step()
  333. ! call KillLine_Step()
  334. ! call ChokeLine_Step()
  335. ! call BlindRams_Step()
  336. ! call Annular_Step()
  337. !! Sheikh
  338. call FluidFlow_Init()
  339. !! Ahmadi
  340. call PathFinding_Init()
  341. print *,"Modules are initialized"
  342. ! Calls OSInitialization and that sub only subscribes some notif
  343. ! call OperationScenarios_Init()
  344. end subroutine init_modules
  345. subroutine EquipmentsFromJson(jsonfile)
  346. type(json_value),pointer :: parent
  347. type(json_value),pointer :: p
  348. type(json_file)::jsonfile
  349. integer::n_children
  350. logical::is_found
  351. ! 1. get related root
  352. ! call jsonfile%json_file_get_root(parent)
  353. ! call jsoncore%get(parent,"Equipments",p)
  354. call jsonfile%get("Equipments",p,is_found)
  355. ! call jsoncore%info(p, n_children=n_children)
  356. ! print *,"number of Equipments =",n_children
  357. ! 2. add member of data type to new node
  358. call BopControlPanelFromJson(p)
  359. call ChokeControlPanelFromJson(jsonfile)
  360. call ChokeManifoldFromJson(p)
  361. call DataDisplayConsoleFromJson(p)
  362. call DrillingConsoleFromJson(jsonfile)
  363. ! call HookFromJson(p)
  364. call StandPipeManifoldFromJson(p)
  365. call TopDrivePanelFromJson(p)
  366. ! call DrillingWatchFromJson(p)
  367. call TankFromJson(p)
  368. call UnityInputsFromJson(jsonfile)
  369. end subroutine
  370. subroutine EquipmentsToJson(parent)
  371. type(json_value),pointer :: parent
  372. type(json_value),pointer :: p
  373. ! 1. create new node
  374. call jsoncore%create_object(p,'Equipments')
  375. ! 2. add member of data type to new node
  376. call BopControlPanelToJson(p)
  377. call ChokeControlPanelToJson(p)
  378. call ChokeManifoldToJson(p)
  379. call DataDisplayConsoleToJson(p)
  380. call DrillingConsoleToJson(p)
  381. call HookToJson(p)
  382. call StandPipeManifoldToJson(p)
  383. call TopDrivePanelToJson(p)
  384. call DrillingWatchToJson(p)
  385. ! call TankToJson(p)
  386. ! 3. add new node to parent
  387. call jsoncore%add(parent,p)
  388. end subroutine
  389. ! subroutine ConfigurationToJson(parent)
  390. ! type(json_value),pointer :: parent
  391. ! type(json_value),pointer :: p
  392. ! ! 1. create new node
  393. ! call jsoncore%create_object(p,'Configuration')
  394. ! ! 2. add member of data type to new node
  395. ! call StringConfigurationToJson(p)
  396. ! call FormationToJson(p)
  397. ! call ReservoirToJson(p)
  398. ! call ShoeToJson(p)
  399. ! call AccumulatorToJson(p)
  400. ! call BopStackToJson(p)
  401. ! call HoistingToJson(p)
  402. ! call PowerToJson(p)
  403. ! call PumpsToJson(p)
  404. ! call RigSizeToJson(p)
  405. ! call CasingLinerChokeToJson(p)
  406. ! call PathGenerationToJson(p)
  407. ! ! call WellSurveyDataToJson(p)
  408. ! call MudPropertiesToJson(p)
  409. ! call UnityOutputsToJson(p)
  410. ! ! 3. add new node to parent
  411. ! call jsoncore%add(parent,p)
  412. ! end subroutine
  413. subroutine WarningsToJson(parent)
  414. type(json_value),pointer :: parent
  415. type(json_value),pointer :: p
  416. ! 1. create new node
  417. call jsoncore%create_object(p,'Warnings')
  418. ! 2. add member of data type to new node
  419. call jsoncore%add(p,"PumpWithKellyDisconnected",data%Warnings%PumpWithKellyDisconnected)
  420. call jsoncore%add(p,"PumpWithTopdriveDisconnected",data%Warnings%PumpWithTopdriveDisconnected)
  421. call jsoncore%add(p,"Pump1PopOffValveBlown",data%Warnings%Pump1PopOffValveBlown)
  422. call jsoncore%add(p,"Pump1Failure",data%Warnings%Pump1Failure)
  423. call jsoncore%add(p,"Pump2PopOffValveBlown",data%Warnings%Pump2PopOffValveBlown)
  424. call jsoncore%add(p,"Pump2Failure",data%Warnings%Pump2Failure)
  425. call jsoncore%add(p,"Pump3PopOffValveBlown",data%Warnings%Pump3PopOffValveBlown)
  426. call jsoncore%add(p,"Pump3Failure",data%Warnings%Pump3Failure)
  427. call jsoncore%add(p,"DrawworksGearsAbuse",data%Warnings%DrawworksGearsAbuse)
  428. call jsoncore%add(p,"RotaryGearsAbuse",data%Warnings%RotaryGearsAbuse)
  429. call jsoncore%add(p,"HoistLineBreak",data%Warnings%HoistLineBreak)
  430. call jsoncore%add(p,"PartedDrillString",data%Warnings%PartedDrillString)
  431. call jsoncore%add(p,"ActiveTankOverflow",data%Warnings%ActiveTankOverflow)
  432. call jsoncore%add(p,"ActiveTankUnderVolume",data%Warnings%ActiveTankUnderVolume)
  433. call jsoncore%add(p,"TripTankOverflow",data%Warnings%TripTankOverflow)
  434. call jsoncore%add(p,"DrillPipeTwistOff",data%Warnings%DrillPipeTwistOff)
  435. call jsoncore%add(p,"DrillPipeParted",data%Warnings%DrillPipeParted)
  436. call jsoncore%add(p,"TripWithSlipsSet",data%Warnings%TripWithSlipsSet)
  437. call jsoncore%add(p,"Blowout",data%Warnings%Blowout)
  438. call jsoncore%add(p,"UndergroundBlowout",data%Warnings%UndergroundBlowout)
  439. call jsoncore%add(p,"MaximumWellDepthExceeded",data%Warnings%MaximumWellDepthExceeded)
  440. call jsoncore%add(p,"CrownCollision",data%Warnings%CrownCollision)
  441. call jsoncore%add(p,"FloorCollision",data%Warnings%FloorCollision)
  442. call jsoncore%add(p,"TopdriveRotaryTableConfilict",data%Warnings%TopdriveRotaryTableConfilict)
  443. ! 3. add new node to parent
  444. call jsoncore%add(parent,p)
  445. end subroutine
  446. subroutine ProblemsToJson(parent)
  447. type(json_value),pointer :: parent
  448. type(json_value),pointer :: p
  449. ! 1. create new node
  450. call jsoncore%create_object(p,'Problems')
  451. ! 2. add member of data type to new node
  452. call BitProblemsToJson(p)
  453. call BopProblemsToJson(p)
  454. call ChokeProblemsToJson(p)
  455. call DrillStemProblemsToJson(p)
  456. call GaugesProblemsToJson(p)
  457. call HoistingProblemsToJson(p)
  458. call KickProblemsToJson(p)
  459. call LostProblemsToJson(p)
  460. call MudTreatmentProblemsToJson(p)
  461. call OtherProblemsToJson(p)
  462. call PumpProblemsToJson(p)
  463. call RotaryProblemsToJson(p)
  464. ! 3. add new node to parent
  465. call jsoncore%add(parent,p)
  466. end subroutine
  467. subroutine StateToJson(parent)
  468. type(json_value),pointer :: parent
  469. type(json_value),pointer :: p
  470. ! 1. create new node
  471. call jsoncore%create_object(p,'State')
  472. ! call OperationScenarioToJson(p)
  473. call notificationsToJson(p)
  474. ! call permissionsToJson(p)
  475. ! call unitySignalsToJson(p)
  476. ! call StudentStationToJson(p)
  477. ! call BopStackInputToJson(p)
  478. ! call BopStackAccToJson(p)
  479. ! call RamLineToJson(p)
  480. ! call AnnularComputationalToJson(p)
  481. ! call AnnularToJson(p)
  482. ! call PipeRam1ToJson(p)
  483. ! call ShearRamToJson(p)
  484. ! call PipeRam2ToJson(p)
  485. ! call ChokeLineToJson(p)
  486. ! call KillLineToJson(p)
  487. ! call PumpsToJson(p)
  488. ! call RAMToJson(p)
  489. ! call RAMSToJson(p)
  490. ! call ChokeToJson(p)
  491. ! call AirDrivenPumpToJson(p)
  492. ! call AirPumpLineToJson(p)
  493. ! call CHOOKEToJson(p)
  494. ! call DrawworksToJson(p)
  495. ! call MudSystemToJson(p)
  496. ! call MUDToJson(p)
  497. ! call MPumpsToJson(p)
  498. ! call PUMPToJson(p)
  499. ! call RTableToJson(p)
  500. ! call TDSToJson(p)
  501. ! call GasType(3)ToJson(p)
  502. ! call PressureDisplayToJson(p)
  503. ! call FricPressDropToJson(p)
  504. ! call ROP_SpecToJson(p)
  505. ! call ROP_BitToJson(p)
  506. ! call TDGeoToJson(p)
  507. ! call F_String(:)ToJson(p)
  508. ! call F_CountsToJson(p)
  509. ! call F_Interval(:)ToJson(p)
  510. ! call OD_Annulus(4)ToJson(p)
  511. ! call TD_DrillStemToJson(p)
  512. ! call TD_DrillStemsToJson(p)
  513. ! call TD_StringToJson(p)
  514. ! call TD_CountToJson(p)
  515. ! call G_StringElementToJson(p)
  516. ! call TD_VolToJson(p)
  517. ! call TD_GeneralToJson(p)
  518. ! call TD_BOPToJson(p)
  519. ! call TD_BOPElement(4)ToJson(p)
  520. ! call TD_StConnToJson(p)
  521. ! call TD_LoadToJson(p)
  522. ! call TD_WellElToJson(p)
  523. ! call TD_CasingToJson(p)
  524. ! call TD_LinerToJson(p)
  525. ! call TD_OpenHoleToJson(p)
  526. ! call TD_ROPHoleToJson(p)
  527. ! call TD_WellGeneralToJson(p)
  528. ! call TD_WellGeo(:)ToJson(p)
  529. ! 2. add member of data type to new node
  530. ! 3. add new node to parent
  531. call jsoncore%add(parent,p)
  532. end subroutine
  533. !use this as a template
  534. subroutine notificationsToJson(parent)
  535. type(json_value),pointer :: parent
  536. type(json_value),pointer :: p
  537. ! 1. create new node
  538. call jsoncore%create_object(p,'Notifications')
  539. ! 2. add member of data type to new node
  540. ! 3. add new node to parent
  541. call jsoncore%add(parent,p)
  542. end subroutine
  543. subroutine ConfigurationFromJson(jsonfile)
  544. type(json_file)::jsonfile
  545. type(json_value),pointer :: parent
  546. type(json_value),pointer :: p
  547. ! 1. get related root
  548. call jsonfile%json_file_get_root(parent)
  549. call jsoncore%get(parent,"Configuration",p)
  550. call StringConfigurationFromJson(p)
  551. call FormationFromJson(p)
  552. call ReservoirFromJson(p)
  553. call ShoeFromJson(p)
  554. call AccumulatorFromJson(p)
  555. call BopStackFromJson(p)
  556. call HoistingFromJson(p)
  557. call PowerFromJson(p)
  558. call PumpsFromJson(p)
  559. call RigSizeFromJson(p)
  560. call CasingLinerChokeFromJson(p)
  561. call PathGenerationFromJson(p)
  562. call MudPropertiesFromJson(p)
  563. ! 3. add new node to parent
  564. ! nullify(parent)
  565. end subroutine
  566. subroutine WarningsFromJson(parent)
  567. type(json_value),pointer :: parent
  568. type(json_value),pointer :: p
  569. type(json_value),pointer :: pval
  570. ! 1. get node
  571. call jsoncore%get(parent,'Warnings',p)
  572. ! ! 2. add member of data type to new node
  573. call jsoncore%get(p,'PumpWithKellyDisconnected',pval)
  574. call jsoncore%get(pval,data%Warnings%PumpWithKellyDisconnected)
  575. call jsoncore%get(p,'PumpWithTopdriveDisconnected',pval)
  576. call jsoncore%get(pval,data%Warnings%PumpWithTopdriveDisconnected)
  577. call jsoncore%get(p,'Pump1PopOffValveBlown',pval)
  578. call jsoncore%get(pval,data%Warnings%Pump1PopOffValveBlown)
  579. call jsoncore%get(p,'Pump1Failure',pval)
  580. call jsoncore%get(pval,data%Warnings%Pump1Failure)
  581. call jsoncore%get(p,'Pump2PopOffValveBlown',pval)
  582. call jsoncore%get(pval,data%Warnings%Pump2PopOffValveBlown)
  583. call jsoncore%get(p,'Pump2Failure',pval)
  584. call jsoncore%get(pval,data%Warnings%Pump2Failure)
  585. call jsoncore%get(p,'Pump3PopOffValveBlown',pval)
  586. call jsoncore%get(pval,data%Warnings%Pump3PopOffValveBlown)
  587. call jsoncore%get(p,'Pump3Failure',pval)
  588. call jsoncore%get(pval,data%Warnings%Pump3Failure)
  589. call jsoncore%get(p,'DrawworksGearsAbuse',pval)
  590. call jsoncore%get(pval,data%Warnings%DrawworksGearsAbuse)
  591. call jsoncore%get(p,'RotaryGearsAbuse',pval)
  592. call jsoncore%get(pval,data%Warnings%RotaryGearsAbuse)
  593. call jsoncore%get(p,'HoistLineBreak',pval)
  594. call jsoncore%get(pval,data%Warnings%HoistLineBreak)
  595. call jsoncore%get(p,'PartedDrillString',pval)
  596. call jsoncore%get(pval,data%Warnings%PartedDrillString)
  597. call jsoncore%get(p,'ActiveTankOverflow',pval)
  598. call jsoncore%get(pval,data%Warnings%ActiveTankOverflow)
  599. call jsoncore%get(p,'ActiveTankUnderVolume',pval)
  600. call jsoncore%get(pval,data%Warnings%ActiveTankUnderVolume)
  601. call jsoncore%get(p,'TripTankOverflow',pval)
  602. call jsoncore%get(pval,data%Warnings%TripTankOverflow)
  603. call jsoncore%get(p,'DrillPipeTwistOff',pval)
  604. call jsoncore%get(pval,data%Warnings%DrillPipeTwistOff)
  605. call jsoncore%get(p,'DrillPipeParted',pval)
  606. call jsoncore%get(pval,data%Warnings%DrillPipeParted)
  607. call jsoncore%get(p,'TripWithSlipsSet',pval)
  608. call jsoncore%get(pval,data%Warnings%TripWithSlipsSet)
  609. call jsoncore%get(p,'Blowout',pval)
  610. call jsoncore%get(pval,data%Warnings%Blowout)
  611. call jsoncore%get(p,'UndergroundBlowout',pval)
  612. call jsoncore%get(pval,data%Warnings%UndergroundBlowout)
  613. call jsoncore%get(p,'MaximumWellDepthExceeded',pval)
  614. call jsoncore%get(pval,data%Warnings%MaximumWellDepthExceeded)
  615. call jsoncore%get(p,'CrownCollision',pval)
  616. call jsoncore%get(pval,data%Warnings%CrownCollision)
  617. call jsoncore%get(p,'FloorCollision',pval)
  618. call jsoncore%get(pval,data%Warnings%FloorCollision)
  619. call jsoncore%get(p,'TopdriveRotaryTableConfilict',pval)
  620. call jsoncore%get(pval,data%Warnings%TopdriveRotaryTableConfilict)
  621. end subroutine
  622. subroutine ProblemsFromJson(jsonfile)
  623. type(json_value),pointer :: parent
  624. type(json_value),pointer :: p
  625. type(json_file)::jsonfile
  626. call jsonfile%json_file_get_root(parent)
  627. call jsoncore%get(parent,'Warnings',p)
  628. call BitProblemsToJson(p)
  629. call BopProblemsFromJson(p)
  630. call ChokeProblemsFromJson(p)
  631. call DrillStemProblemsFromJson(p)
  632. call GaugesProblemsFromJson(p)
  633. call HoistingProblemsFromJson(p)
  634. call KickProblemsFromJson(p)
  635. call LostProblemsFromJson(p)
  636. call MudTreatmentProblemsFromJson(p)
  637. call OtherProblemsFromJson(p)
  638. call PumpProblemsFromJson(p)
  639. call RotaryProblemsFromJson(p)
  640. end subroutine
  641. subroutine StateFromJson(parent)
  642. type(json_value),pointer :: parent
  643. type(json_value),pointer :: p
  644. ! 1. create new node
  645. ! call json%create_object(p,'State')
  646. ! ! call OperationScenarioFromJson(p)
  647. ! call notificationsFromJson(p)
  648. ! call permissionsFromJson(p)
  649. ! call unitySignalsFromJson(p)
  650. ! call StudentStationFromJson(p)
  651. ! call BopStackInputFromJson(p)
  652. ! call BopStackAccFromJson(p)
  653. ! call RamLineFromJson(p)
  654. ! call AnnularComputationalFromJson(p)
  655. ! call AnnularFromJson(p)
  656. ! call PipeRam1FromJson(p)
  657. ! call ShearRamFromJson(p)
  658. ! call PipeRam2FromJson(p)
  659. ! call ChokeLineFromJson(p)
  660. ! call KillLineFromJson(p)
  661. ! call PumpsFromJson(p)
  662. ! call RAMFromJson(p)
  663. ! call RAMSFromJson(p)
  664. ! call ChokeFromJson(p)
  665. ! call AirDrivenPumpFromJson(p)
  666. ! call AirPumpLineFromJson(p)
  667. ! call CHOOKEFromJson(p)
  668. ! call DrawworksFromJson(p)
  669. ! call MudSystemFromJson(p)
  670. ! call MUDFromJson(p)
  671. ! call MPumpsFromJson(p)
  672. ! call PUMPFromJson(p)
  673. ! call RTableFromJson(p)
  674. ! call TDSFromJson(p)
  675. ! call GasType(3)FromJson(p)
  676. ! call PressureDisplayFromJson(p)
  677. ! call FricPressDropFromJson(p)
  678. ! call ROP_SpecFromJson(p)
  679. ! call ROP_BitFromJson(p)
  680. ! call TDGeoFromJson(p)
  681. ! call F_String(:)FromJson(p)
  682. ! call F_CountsFromJson(p)
  683. ! call F_Interval(:)FromJson(p)
  684. ! call OD_Annulus(4)FromJson(p)
  685. ! call TD_DrillStemFromJson(p)
  686. ! call TD_DrillStemsFromJson(p)
  687. ! call TD_StringFromJson(p)
  688. ! call TD_CountFromJson(p)
  689. ! call G_StringElementFromJson(p)
  690. ! call TD_VolFromJson(p)
  691. ! call TD_GeneralFromJson(p)
  692. ! call TD_BOPFromJson(p)
  693. ! call TD_BOPElement(4)FromJson(p)
  694. ! call TD_StConnFromJson(p)
  695. ! call TD_LoadFromJson(p)
  696. ! call TD_WellElFromJson(p)
  697. ! call TD_CasingFromJson(p)
  698. ! call TD_LinerFromJson(p)
  699. ! call TD_OpenHoleFromJson(p)
  700. ! call TD_ROPHoleFromJson(p)
  701. ! call TD_WellGeneralFromJson(p)
  702. ! call TD_WellGeo(:)FromJson(p)
  703. ! 2. add member of data type to new node
  704. ! 3. add new node to parent
  705. ! call jsoncore%add(parent,p)
  706. end subroutine
  707. !use this as a template
  708. subroutine notificationsFromJson(parent)
  709. type(json_value),pointer :: parent
  710. !
  711. ! type(json_value),pointer :: p
  712. ! 1. create new node
  713. ! call json%create_object(p,'Notifications')
  714. ! ! 2. add member of data type to new node
  715. ! ! 3. add new node to parent
  716. ! call json%add(parent,p)
  717. end subroutine
  718. ! subroutine fireOperationScenarioEvent()
  719. ! print *,"fireOperationScenarioEvent starts"
  720. ! if(operationScenarioEvent=='Kelly_ConnectionNothing'.and. .not. Kelly_ConnectionNothing_in_progress) then
  721. ! Kelly_ConnectionNothing_in_progress = .true.
  722. ! print *, "Starting Kelly_ConnectionNothing"
  723. ! call Kelly_ConnectionNothing()
  724. ! print *, "Kelly_ConnectionNothing ends."
  725. ! Kelly_ConnectionNothing_in_progress = .false.
  726. ! endif
  727. ! end subroutine
  728. end module Simulator