Simulation Core
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Simulator.f90 32 KiB

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