Simulation Core
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Simulator.f90 15 KiB

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