Simulation Core
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Simulator.f90 16 KiB

1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. module Simulator
  2. use RedisInterface
  3. use Bop
  4. use PumpsMain
  5. use RopMain
  6. use RotaryTableMain
  7. use DrawworksMain
  8. use FluidFlowMain
  9. use TorqueDragMain
  10. use MudSystemMain
  11. use PipeRams1Main
  12. use PipeRams2Main
  13. use KillLineMain
  14. use ChokeLineMain
  15. use BlindRamsMain
  16. use AnnularMain
  17. use TopDriveMain
  18. use CManifolds
  19. use GeoMain
  20. use ChokeControlMain
  21. use COperationScenariosMain
  22. ! For Json read and write
  23. use CStringConfiguration
  24. use CFormation
  25. use CReservoir
  26. use CShoe
  27. use CAccumulator
  28. use CBopStack
  29. use CHoisting
  30. use CPower
  31. use CPumpsVariables
  32. use CRigSize
  33. use CCasingLinerChoke
  34. use CPathGeneration
  35. use CWellSurveyData
  36. use MudPropertiesModule
  37. use CBitProblems
  38. use CBopProblems
  39. use CChokeProblems
  40. use CDrillStemProblems
  41. use CGaugesProblems
  42. use CHoistingProblems
  43. use CKickProblems
  44. use CLostProblems
  45. use CMudTreatmentProblems
  46. use COtherProblems
  47. use CPumpProblems
  48. use CRotaryProblems
  49. use OperationScenariosModule
  50. use PermissionsModule
  51. use UnitySignalsModule
  52. use CBopControlPanel
  53. use CChokeControlPanel
  54. use CChokeManifold
  55. use CDataDisplayConsole
  56. use CDrillingConsole
  57. use CHook
  58. use CStandPipeManifold
  59. use CTopDrivePanel
  60. use DrillingWatchModule
  61. use CTanks
  62. use :: json_module, rk => json_rk
  63. implicit none
  64. type(json_file) :: jsonfile
  65. type(json_value),pointer :: jsonvalue
  66. type(json_core) :: jsoncore
  67. logical :: is_found
  68. real T1,T2
  69. character(len=:),allocatable::redisContent
  70. contains
  71. subroutine Simulate
  72. integer :: t
  73. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  74. t=0
  75. ! call initConnection()
  76. ! print *,"redis exmaple program"
  77. ! call jsoncore%create_object(jsonvalue,'')
  78. ! call ConfigurationToJson(jsonvalue)
  79. ! call WarningsToJson(jsonvalue)
  80. ! call ProblemsToJson(jsonvalue)
  81. ! print *,"write starts"
  82. ! call jsoncore%serialize(jsonvalue,redisContent)
  83. ! ! s = "Test redis write!"
  84. ! call setData(redisContent)
  85. ! print *,"write ends len=",len(redisContent)
  86. ! call getData(s2)
  87. ! print *,"len(read)=",len(s2)
  88. ! print *, s2(1:10),' .... ', s2(len(s2)-10:len(s2))
  89. ! call deallocateData()
  90. ! ! print *,"S2 = ",s2
  91. ! deallocate(s2)
  92. call jsoncore%create_object(jsonvalue,'')
  93. call initConnection()
  94. call write_variables()
  95. call read_variables()
  96. call jsoncore%print(jsonvalue,'test.json')
  97. call jsoncore%destroy(jsonvalue)
  98. ! print *,"s2=",redisContent
  99. ! call deallocateData()
  100. ! print *,"redisContent Deallocated!"
  101. ! print *,"s2=",redisContent
  102. ! call init_modules()
  103. ! call cpu_time(T1)
  104. ! do while (t<0)
  105. ! !!read variable from shared file
  106. ! call read_variables()
  107. ! exit
  108. ! !! Tarmigh, Now merged with TorqueDrag (FluidFlow)
  109. ! ! call Rop_Step()
  110. ! !! Rafiee, nothing changed
  111. ! call BopStack_Step()
  112. ! !! Tarmigh, now is rewritten
  113. ! call Pump1_Step()
  114. ! !call Pump2_Step()
  115. ! !! Rafiee
  116. ! call ChokeControl_Step()
  117. ! !! Location ./Equipment/Rotarytable
  118. ! !! Variables:
  119. ! !! Does not have step function
  120. ! !! Call RTable_StartUp in the start
  121. ! !! Again has a loop in each step
  122. ! !! Tarmigh, now is rewritten
  123. ! call RotaryTable_Step()
  124. ! !! Location ./Equipment/Drawworks
  125. ! !! Variables:
  126. ! !! Does not have step function
  127. ! !! Call ..._StartUp in the start
  128. ! !! Again has a loop in each step
  129. ! !! Tarmigh, now is rewritten
  130. ! call Drawworks_Step()
  131. ! !! Empty nothing called
  132. ! !! Merged in FluidFlow
  133. ! ! call TorqueDrag_Step()
  134. ! !! Location: ./Equipment/MudSystem
  135. ! !! Variables: MudSystem_variables.f90 and MudSystem.f90
  136. ! !! Step function simply calls LineupAndPath in MudSystem.f90
  137. ! !! had not startUp
  138. ! !! Rafiee
  139. ! call MudSystem_Step()
  140. ! !! Location ./Equipment/BopStack
  141. ! !! Variables: VARIABLES,CBopStackVariables,CBopControlPanelVariables,CEquipmentsConstants
  142. ! !! Step function added, only call PIPE_RAMS1 and 2 function
  143. ! !! BOP_StartUp commented
  144. ! !! Rafiee
  145. ! call PipeRams1_Step()
  146. ! call PipeRams2_Step()
  147. ! !! Location ./Equipment/BopStack
  148. ! !! Variables: VARIABLES,CBopStackVariables,CBopControlPanelVariables,CEquipmentsConstants,CAccumulatorVariables,CSimulationVariables
  149. ! !! Step function added, only call PIPE_RAMS1 and PIPE_RAMS2 function
  150. ! !! BOP_StartUp commented
  151. ! !! Rafiee
  152. ! call KillLine_Step()
  153. ! !! Probably like other bopstack equipments
  154. ! !! Rafiee
  155. ! call ChokeLine_Step()
  156. ! call BlindRams_Step()
  157. ! call Annular_Step()
  158. ! !!Tarmigh. Step must rewrittem
  159. ! call TopDrive_Step()
  160. ! !!Empty
  161. ! ! call Geo_Step()
  162. ! !!Ahmadi
  163. ! call PathFinding_Step()
  164. ! !! Sheikh
  165. ! call FluidFlow_Step()
  166. ! !! Ahmadi
  167. ! call OperationScenarios_Step()
  168. ! !! Write variables to shared files
  169. ! call write_variables()
  170. ! print *,"t=",t
  171. ! t = t + 1
  172. ! end do
  173. ! call jsoncore%destroy(jsonvalue)
  174. ! call cpu_time(T2)
  175. ! print *,"Total Execution Time =",t2-t1
  176. end subroutine Simulate
  177. subroutine write_variables()
  178. use CAccumulator
  179. use json_module
  180. implicit none
  181. ! character(len=:),allocatable::s
  182. call ConfigurationToJson(jsonvalue)
  183. call WarningsToJson(jsonvalue)
  184. call ProblemsToJson(jsonvalue)
  185. call EquipmentsToJson(jsonvalue)
  186. print *,"write starts"
  187. call jsoncore%serialize(jsonvalue,redisContent)
  188. ! s = "Test redis write!"
  189. call setData(redisContent)
  190. print *,"write ends"
  191. end subroutine
  192. subroutine read_variables
  193. call getData(redisContent)
  194. call jsoncore%deserialize(jsonvalue,redisContent)
  195. ! print *,"Read from Redix:",redisContent
  196. ! ! Load the file.
  197. ! call jsonfile%load_file('config.json'); if (jsonfile%failed()) stop
  198. ! print *,"read complete"
  199. ! call jsonfile%get('t0', a1, is_found); if (.not. is_found) return
  200. ! call jsonfile%get('dt', a2, is_found); if (.not. is_found) return
  201. ! call jsonfile%get('tf', a3, is_found); if (.not. is_found) return
  202. ! call jsonfile%get('mu', a4, is_found); if (.not. is_found) return
  203. ! call jsonfile%get('x0', x0, is_found); if (.not. is_found) return
  204. ! if (is_found) then
  205. ! print *, a1,a2,a3,a4
  206. ! print *, x0
  207. ! end if
  208. ! call jsonfile%destroy()
  209. end subroutine
  210. subroutine init_modules
  211. !Tarmigh
  212. call Pump1_Init()
  213. !call Pump2_Step()
  214. call RotaryTable_Init()
  215. call Drawworks_Init()
  216. call TopDrive_Init()
  217. !Nothing in init (and step)
  218. ! call Rop_Init()
  219. ! call TorqueDrag_Init()
  220. ! call Geo_Step()
  221. !! Rafiee
  222. call BopStack_Init()
  223. call ChokeControl_Init()
  224. call MudSystem_Init()
  225. !Again calls Bop_Startup
  226. ! call PipeRams1_Init()
  227. ! call PipeRams2_Step()
  228. ! call KillLine_Step()
  229. ! call ChokeLine_Step()
  230. ! call BlindRams_Step()
  231. ! call Annular_Step()
  232. !! Sheikh
  233. call FluidFlow_Init()
  234. !! Ahmadi
  235. call PathFinding_Init()
  236. ! Calls OSInitialization and that sub only subscribes some notif
  237. ! call OperationScenarios_Init()
  238. end subroutine init_modules
  239. subroutine EquipmentsToJson(parent)
  240. type(json_value),pointer :: parent
  241. type(json_core) :: json
  242. type(json_value),pointer :: p
  243. ! 1. create new node
  244. call json%create_object(p,'Equipments')
  245. ! 2. add member of data type to new node
  246. call BopControlPanelToJson(p)
  247. call ChokeControlPanelToJson(p)
  248. call ChokeManifoldToJson(p)
  249. call DataDisplayConsoleToJson(p)
  250. call DrillingConsoleToJson(p)
  251. call HookToJson(p)
  252. call StandPipeManifoldToJson(p)
  253. call TopDrivePanelToJson(p)
  254. call DrillingWatchToJson(p)
  255. call TankToJson(p)
  256. ! 3. add new node to parent
  257. call json%add(parent,p)
  258. end subroutine
  259. subroutine ConfigurationToJson(parent)
  260. type(json_value),pointer :: parent
  261. type(json_core) :: json
  262. type(json_value),pointer :: p
  263. ! 1. create new node
  264. call json%create_object(p,'Configuration')
  265. ! 2. add member of data type to new node
  266. call StringConfigurationToJson(p)
  267. call FormationToJson(p)
  268. call ReservoirToJson(p)
  269. call ShoeToJson(p)
  270. call AccumulatorToJson(p)
  271. call BopStackToJson(p)
  272. call HoistingToJson(p)
  273. call PowerToJson(p)
  274. call PumpsToJson(p)
  275. call RigSizeToJson(p)
  276. call CasingLinerChokeToJson(p)
  277. call PathGenerationToJson(p)
  278. ! call WellSurveyDataToJson(p)
  279. call MudPropertiesToJson(p)
  280. ! 3. add new node to parent
  281. call json%add(parent,p)
  282. end subroutine
  283. subroutine WarningsToJson(parent)
  284. type(json_value),pointer :: parent
  285. type(json_core) :: json
  286. type(json_value),pointer :: p
  287. ! 1. create new node
  288. call json%create_object(p,'Warnings')
  289. ! 2. add member of data type to new node
  290. call json%add(p,"PumpWithKellyDisconnected",data%Warnings%PumpWithKellyDisconnected)
  291. call json%add(p,"PumpWithTopdriveDisconnected",data%Warnings%PumpWithTopdriveDisconnected)
  292. call json%add(p,"Pump1PopOffValveBlown",data%Warnings%Pump1PopOffValveBlown)
  293. call json%add(p,"Pump1Failure",data%Warnings%Pump1Failure)
  294. call json%add(p,"Pump2PopOffValveBlown",data%Warnings%Pump2PopOffValveBlown)
  295. call json%add(p,"Pump2Failure",data%Warnings%Pump2Failure)
  296. call json%add(p,"Pump3PopOffValveBlown",data%Warnings%Pump3PopOffValveBlown)
  297. call json%add(p,"Pump3Failure",data%Warnings%Pump3Failure)
  298. call json%add(p,"DrawworksGearsAbuse",data%Warnings%DrawworksGearsAbuse)
  299. call json%add(p,"RotaryGearsAbuse",data%Warnings%RotaryGearsAbuse)
  300. call json%add(p,"HoistLineBreak",data%Warnings%HoistLineBreak)
  301. call json%add(p,"PartedDrillString",data%Warnings%PartedDrillString)
  302. call json%add(p,"ActiveTankOverflow",data%Warnings%ActiveTankOverflow)
  303. call json%add(p,"ActiveTankUnderVolume",data%Warnings%ActiveTankUnderVolume)
  304. call json%add(p,"TripTankOverflow",data%Warnings%TripTankOverflow)
  305. call json%add(p,"DrillPipeTwistOff",data%Warnings%DrillPipeTwistOff)
  306. call json%add(p,"DrillPipeParted",data%Warnings%DrillPipeParted)
  307. call json%add(p,"TripWithSlipsSet",data%Warnings%TripWithSlipsSet)
  308. call json%add(p,"Blowout",data%Warnings%Blowout)
  309. call json%add(p,"UndergroundBlowout",data%Warnings%UndergroundBlowout)
  310. call json%add(p,"MaximumWellDepthExceeded",data%Warnings%MaximumWellDepthExceeded)
  311. call json%add(p,"CrownCollision",data%Warnings%CrownCollision)
  312. call json%add(p,"FloorCollision",data%Warnings%FloorCollision)
  313. call json%add(p,"TopdriveRotaryTableConfilict",data%Warnings%TopdriveRotaryTableConfilict)
  314. ! 3. add new node to parent
  315. call json%add(parent,p)
  316. end subroutine
  317. subroutine ProblemsToJson(parent)
  318. type(json_value),pointer :: parent
  319. type(json_core) :: json
  320. type(json_value),pointer :: p
  321. ! 1. create new node
  322. call json%create_object(p,'Problems')
  323. ! 2. add member of data type to new node
  324. call BitProblemsToJson(p)
  325. call BopProblemsToJson(p)
  326. call ChokeProblemsToJson(p)
  327. call DrillStemProblemsToJson(p)
  328. call GaugesProblemsToJson(p)
  329. call HoistingProblemsToJson(p)
  330. call KickProblemsToJson(p)
  331. call LostProblemsToJson(p)
  332. call MudTreatmentProblemsToJson(p)
  333. call OtherProblemsToJson(p)
  334. call PumpProblemsToJson(p)
  335. call RotaryProblemsToJson(p)
  336. ! 3. add new node to parent
  337. call json%add(parent,p)
  338. end subroutine
  339. subroutine StateToJson(parent)
  340. type(json_value),pointer :: parent
  341. type(json_core) :: json
  342. type(json_value),pointer :: p
  343. ! 1. create new node
  344. call json%create_object(p,'State')
  345. ! call OperationScenarioToJson(p)
  346. call notificationsToJson(p)
  347. ! call permissionsToJson(p)
  348. ! call unitySignalsToJson(p)
  349. ! call StudentStationToJson(p)
  350. ! call BopStackInputToJson(p)
  351. ! call BopStackAccToJson(p)
  352. ! call RamLineToJson(p)
  353. ! call AnnularComputationalToJson(p)
  354. ! call AnnularToJson(p)
  355. ! call PipeRam1ToJson(p)
  356. ! call ShearRamToJson(p)
  357. ! call PipeRam2ToJson(p)
  358. ! call ChokeLineToJson(p)
  359. ! call KillLineToJson(p)
  360. ! call PumpsToJson(p)
  361. ! call RAMToJson(p)
  362. ! call RAMSToJson(p)
  363. ! call ChokeToJson(p)
  364. ! call AirDrivenPumpToJson(p)
  365. ! call AirPumpLineToJson(p)
  366. ! call CHOOKEToJson(p)
  367. ! call DrawworksToJson(p)
  368. ! call MudSystemToJson(p)
  369. ! call MUDToJson(p)
  370. ! call MPumpsToJson(p)
  371. ! call PUMPToJson(p)
  372. ! call RTableToJson(p)
  373. ! call TDSToJson(p)
  374. ! call GasType(3)ToJson(p)
  375. ! call PressureDisplayToJson(p)
  376. ! call FricPressDropToJson(p)
  377. ! call ROP_SpecToJson(p)
  378. ! call ROP_BitToJson(p)
  379. ! call TDGeoToJson(p)
  380. ! call F_String(:)ToJson(p)
  381. ! call F_CountsToJson(p)
  382. ! call F_Interval(:)ToJson(p)
  383. ! call OD_Annulus(4)ToJson(p)
  384. ! call TD_DrillStemToJson(p)
  385. ! call TD_DrillStemsToJson(p)
  386. ! call TD_StringToJson(p)
  387. ! call TD_CountToJson(p)
  388. ! call G_StringElementToJson(p)
  389. ! call TD_VolToJson(p)
  390. ! call TD_GeneralToJson(p)
  391. ! call TD_BOPToJson(p)
  392. ! call TD_BOPElement(4)ToJson(p)
  393. ! call TD_StConnToJson(p)
  394. ! call TD_LoadToJson(p)
  395. ! call TD_WellElToJson(p)
  396. ! call TD_CasingToJson(p)
  397. ! call TD_LinerToJson(p)
  398. ! call TD_OpenHoleToJson(p)
  399. ! call TD_ROPHoleToJson(p)
  400. ! call TD_WellGeneralToJson(p)
  401. ! call TD_WellGeo(:)ToJson(p)
  402. ! 2. add member of data type to new node
  403. ! 3. add new node to parent
  404. call json%add(parent,p)
  405. end subroutine
  406. !use this as a template
  407. subroutine notificationsToJson(parent)
  408. type(json_value),pointer :: parent
  409. type(json_core) :: json
  410. type(json_value),pointer :: p
  411. ! 1. create new node
  412. call json%create_object(p,'Notifications')
  413. ! 2. add member of data type to new node
  414. ! 3. add new node to parent
  415. call json%add(parent,p)
  416. end subroutine
  417. end module Simulator