Simulation Core
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

Simulator.f90 29 KiB

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