Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Simulator.f90 28 KiB

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