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

448 lines
14 KiB

  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. call jsoncore%serialize(jsonvalue,redisContent)
  175. ! s = "Test redis write!"
  176. call setData(redisContent)
  177. print *,"write ends"
  178. end subroutine
  179. subroutine read_variables
  180. call getData(redisContent)
  181. call jsoncore%deserialize(jsonvalue,redisContent)
  182. ! print *,"Read from Redix:",redisContent
  183. ! ! Load the file.
  184. ! call jsonfile%load_file('config.json'); if (jsonfile%failed()) stop
  185. ! print *,"read complete"
  186. ! call jsonfile%get('t0', a1, is_found); if (.not. is_found) return
  187. ! call jsonfile%get('dt', a2, is_found); if (.not. is_found) return
  188. ! call jsonfile%get('tf', a3, is_found); if (.not. is_found) return
  189. ! call jsonfile%get('mu', a4, is_found); if (.not. is_found) return
  190. ! call jsonfile%get('x0', x0, is_found); if (.not. is_found) return
  191. ! if (is_found) then
  192. ! print *, a1,a2,a3,a4
  193. ! print *, x0
  194. ! end if
  195. ! call jsonfile%destroy()
  196. end subroutine
  197. subroutine init_modules
  198. !Tarmigh
  199. call Pump1_Init()
  200. !call Pump2_Step()
  201. call RotaryTable_Init()
  202. call Drawworks_Init()
  203. call TopDrive_Init()
  204. !Nothing in init (and step)
  205. ! call Rop_Init()
  206. ! call TorqueDrag_Init()
  207. ! call Geo_Step()
  208. !! Rafiee
  209. call BopStack_Init()
  210. call ChokeControl_Init()
  211. call MudSystem_Init()
  212. !Again calls Bop_Startup
  213. ! call PipeRams1_Init()
  214. ! call PipeRams2_Step()
  215. ! call KillLine_Step()
  216. ! call ChokeLine_Step()
  217. ! call BlindRams_Step()
  218. ! call Annular_Step()
  219. !! Sheikh
  220. call FluidFlow_Init()
  221. !! Ahmadi
  222. call PathFinding_Init()
  223. ! Calls OSInitialization and that sub only subscribes some notif
  224. ! call OperationScenarios_Init()
  225. end subroutine init_modules
  226. subroutine ConfigurationToJson(parent)
  227. type(json_value),pointer :: parent
  228. type(json_core) :: json
  229. type(json_value),pointer :: p
  230. ! 1. create new node
  231. call json%create_object(p,'Configuration')
  232. ! 2. add member of data type to new node
  233. call StringConfigurationToJson(p)
  234. call FormationToJson(p)
  235. call ReservoirToJson(p)
  236. call ShoeToJson(p)
  237. call AccumulatorToJson(p)
  238. call BopStackToJson(p)
  239. call HoistingToJson(p)
  240. call PowerToJson(p)
  241. call PumpsToJson(p)
  242. call RigSizeToJson(p)
  243. call CasingLinerChokeToJson(p)
  244. call PathGenerationToJson(p)
  245. ! call WellSurveyDataToJson(p)
  246. call MudPropertiesToJson(p)
  247. ! 3. add new node to parent
  248. call json%add(parent,p)
  249. end subroutine
  250. subroutine WarningsToJson(parent)
  251. type(json_value),pointer :: parent
  252. type(json_core) :: json
  253. type(json_value),pointer :: p
  254. ! 1. create new node
  255. call json%create_object(p,'Warnings')
  256. ! 2. add member of data type to new node
  257. call json%add(p,"PumpWithKellyDisconnected",data%Warnings%PumpWithKellyDisconnected)
  258. call json%add(p,"PumpWithTopdriveDisconnected",data%Warnings%PumpWithTopdriveDisconnected)
  259. call json%add(p,"Pump1PopOffValveBlown",data%Warnings%Pump1PopOffValveBlown)
  260. call json%add(p,"Pump1Failure",data%Warnings%Pump1Failure)
  261. call json%add(p,"Pump2PopOffValveBlown",data%Warnings%Pump2PopOffValveBlown)
  262. call json%add(p,"Pump2Failure",data%Warnings%Pump2Failure)
  263. call json%add(p,"Pump3PopOffValveBlown",data%Warnings%Pump3PopOffValveBlown)
  264. call json%add(p,"Pump3Failure",data%Warnings%Pump3Failure)
  265. call json%add(p,"DrawworksGearsAbuse",data%Warnings%DrawworksGearsAbuse)
  266. call json%add(p,"RotaryGearsAbuse",data%Warnings%RotaryGearsAbuse)
  267. call json%add(p,"HoistLineBreak",data%Warnings%HoistLineBreak)
  268. call json%add(p,"PartedDrillString",data%Warnings%PartedDrillString)
  269. call json%add(p,"ActiveTankOverflow",data%Warnings%ActiveTankOverflow)
  270. call json%add(p,"ActiveTankUnderVolume",data%Warnings%ActiveTankUnderVolume)
  271. call json%add(p,"TripTankOverflow",data%Warnings%TripTankOverflow)
  272. call json%add(p,"DrillPipeTwistOff",data%Warnings%DrillPipeTwistOff)
  273. call json%add(p,"DrillPipeParted",data%Warnings%DrillPipeParted)
  274. call json%add(p,"TripWithSlipsSet",data%Warnings%TripWithSlipsSet)
  275. call json%add(p,"Blowout",data%Warnings%Blowout)
  276. call json%add(p,"UndergroundBlowout",data%Warnings%UndergroundBlowout)
  277. call json%add(p,"MaximumWellDepthExceeded",data%Warnings%MaximumWellDepthExceeded)
  278. call json%add(p,"CrownCollision",data%Warnings%CrownCollision)
  279. call json%add(p,"FloorCollision",data%Warnings%FloorCollision)
  280. call json%add(p,"TopdriveRotaryTableConfilict",data%Warnings%TopdriveRotaryTableConfilict)
  281. ! 3. add new node to parent
  282. call json%add(parent,p)
  283. end subroutine
  284. subroutine ProblemsToJson(parent)
  285. type(json_value),pointer :: parent
  286. type(json_core) :: json
  287. type(json_value),pointer :: p
  288. ! 1. create new node
  289. call json%create_object(p,'Problems')
  290. ! 2. add member of data type to new node
  291. call BitProblemsToJson(p)
  292. call BopProblemsToJson(p)
  293. call ChokeProblemsToJson(p)
  294. call DrillStemProblemsToJson(p)
  295. call GaugesProblemsToJson(p)
  296. call HoistingProblemsToJson(p)
  297. call KickProblemsToJson(p)
  298. call LostProblemsToJson(p)
  299. call MudTreatmentProblemsToJson(p)
  300. call OtherProblemsToJson(p)
  301. call PumpProblemsToJson(p)
  302. call RotaryProblemsToJson(p)
  303. ! 3. add new node to parent
  304. call json%add(parent,p)
  305. end subroutine
  306. subroutine StateToJson(parent)
  307. type(json_value),pointer :: parent
  308. type(json_core) :: json
  309. type(json_value),pointer :: p
  310. ! 1. create new node
  311. call json%create_object(p,'State')
  312. ! call OperationScenarioToJson(p)
  313. call notificationsToJson(p)
  314. ! call permissionsToJson(p)
  315. ! call unitySignalsToJson(p)
  316. ! call StudentStationToJson(p)
  317. ! call BopStackInputToJson(p)
  318. ! call BopStackAccToJson(p)
  319. ! call RamLineToJson(p)
  320. ! call AnnularComputationalToJson(p)
  321. ! call AnnularToJson(p)
  322. ! call PipeRam1ToJson(p)
  323. ! call ShearRamToJson(p)
  324. ! call PipeRam2ToJson(p)
  325. ! call ChokeLineToJson(p)
  326. ! call KillLineToJson(p)
  327. ! call PumpsToJson(p)
  328. ! call RAMToJson(p)
  329. ! call RAMSToJson(p)
  330. ! call ChokeToJson(p)
  331. ! call AirDrivenPumpToJson(p)
  332. ! call AirPumpLineToJson(p)
  333. ! call CHOOKEToJson(p)
  334. ! call DrawworksToJson(p)
  335. ! call MudSystemToJson(p)
  336. ! call MUDToJson(p)
  337. ! call MPumpsToJson(p)
  338. ! call PUMPToJson(p)
  339. ! call RTableToJson(p)
  340. ! call TDSToJson(p)
  341. ! call GasType(3)ToJson(p)
  342. ! call PressureDisplayToJson(p)
  343. ! call FricPressDropToJson(p)
  344. ! call ROP_SpecToJson(p)
  345. ! call ROP_BitToJson(p)
  346. ! call TDGeoToJson(p)
  347. ! call F_String(:)ToJson(p)
  348. ! call F_CountsToJson(p)
  349. ! call F_Interval(:)ToJson(p)
  350. ! call OD_Annulus(4)ToJson(p)
  351. ! call TD_DrillStemToJson(p)
  352. ! call TD_DrillStemsToJson(p)
  353. ! call TD_StringToJson(p)
  354. ! call TD_CountToJson(p)
  355. ! call G_StringElementToJson(p)
  356. ! call TD_VolToJson(p)
  357. ! call TD_GeneralToJson(p)
  358. ! call TD_BOPToJson(p)
  359. ! call TD_BOPElement(4)ToJson(p)
  360. ! call TD_StConnToJson(p)
  361. ! call TD_LoadToJson(p)
  362. ! call TD_WellElToJson(p)
  363. ! call TD_CasingToJson(p)
  364. ! call TD_LinerToJson(p)
  365. ! call TD_OpenHoleToJson(p)
  366. ! call TD_ROPHoleToJson(p)
  367. ! call TD_WellGeneralToJson(p)
  368. ! call TD_WellGeo(:)ToJson(p)
  369. ! 2. add member of data type to new node
  370. ! 3. add new node to parent
  371. call json%add(parent,p)
  372. end subroutine
  373. !use this as a template
  374. subroutine notificationsToJson(parent)
  375. type(json_value),pointer :: parent
  376. type(json_core) :: json
  377. type(json_value),pointer :: p
  378. ! 1. create new node
  379. call json%create_object(p,'Notifications')
  380. ! 2. add member of data type to new node
  381. ! 3. add new node to parent
  382. call json%add(parent,p)
  383. end subroutine
  384. end module Simulator