Simulation Core
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1 рік тому
1 рік тому
1 рік тому
1 рік тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. module CSimulation
  2. ! use CSimulationVariables
  3. use CSimulationThreads
  4. use ifcore
  5. use ifmt
  6. implicit none
  7. public
  8. contains
  9. subroutine InitThreads
  10. implicit none
  11. #ifdef EnableSimulation
  12. !BopStack
  13. BopStackThreadHandle = CreateThread( &
  14. ThreadSecurity, &
  15. ThreadStackSize, &
  16. BopStackThread, &
  17. loc(BopStackThreadParam), &
  18. CREATE_SUSPENDED, &
  19. BopStackThreadId )
  20. !Pumps
  21. Pump1ThreadHandle = CreateThread( &
  22. ThreadSecurity, &
  23. ThreadStackSize, &
  24. Pump1Thread, &
  25. loc(Pump1ThreadParam), &
  26. CREATE_SUSPENDED, &
  27. Pump1ThreadId )
  28. Pump2ThreadHandle = CreateThread( &
  29. ThreadSecurity, &
  30. ThreadStackSize, &
  31. Pump2Thread, &
  32. loc(Pump2ThreadParam), &
  33. CREATE_SUSPENDED, &
  34. Pump2ThreadId )
  35. Pump3ThreadHandle = CreateThread( &
  36. ThreadSecurity, &
  37. ThreadStackSize, &
  38. Pump3Thread, &
  39. loc(Pump3ThreadParam), &
  40. CREATE_SUSPENDED, &
  41. Pump3ThreadId )
  42. !ChokeControl
  43. ChokeControlThreadHandle = CreateThread( &
  44. ThreadSecurity, &
  45. ThreadStackSize, &
  46. ChokeControlThread, &
  47. loc(ChokeControlThreadParam), &
  48. CREATE_SUSPENDED, &
  49. ChokeControlThreadId )
  50. !ROP
  51. RopThreadHandle = CreateThread( &
  52. ThreadSecurity, &
  53. ThreadStackSize, &
  54. RopThread, &
  55. loc(RopThreadParam), &
  56. CREATE_SUSPENDED, &
  57. RopThreadId )
  58. !Geo
  59. GeoThreadHandle = CreateThread( &
  60. ThreadSecurity, &
  61. ThreadStackSize, &
  62. GeoThread, &
  63. loc(GeoThreadParam), &
  64. CREATE_SUSPENDED, &
  65. GeoThreadId )
  66. !RotaryTable
  67. RotaryTableThreadHandle = CreateThread( &
  68. ThreadSecurity, &
  69. ThreadStackSize, &
  70. RotaryTableThread, &
  71. loc(RotaryTableThreadParam), &
  72. CREATE_SUSPENDED, &
  73. RotaryTableThreadId )
  74. !Drawworks
  75. DrawworksThreadHandle = CreateThread( &
  76. ThreadSecurity, &
  77. ThreadStackSize, &
  78. DrawworksThread, &
  79. loc(DrawworksThreadParam), &
  80. CREATE_SUSPENDED, &
  81. DrawworksThreadId )
  82. !FluidFlow
  83. FluidFlowThreadHandle = CreateThread( &
  84. ThreadSecurity, &
  85. ThreadStackSize, &
  86. FluidFlowThread, &
  87. loc(FluidFlowThreadParam), &
  88. CREATE_SUSPENDED, &
  89. FluidFlowThreadId )
  90. !TorqueDrag
  91. TorqueDragThreadHandle = CreateThread( &
  92. ThreadSecurity, &
  93. ThreadStackSize, &
  94. TorqueDragThread, &
  95. loc(TorqueDragThreadParam), &
  96. CREATE_SUSPENDED, &
  97. TorqueDragThreadId )
  98. !TopDrive
  99. TopDriveThreadHandle = CreateThread( &
  100. ThreadSecurity, &
  101. ThreadStackSize, &
  102. TopDriveThread, &
  103. loc(TopDriveThreadParam), &
  104. CREATE_SUSPENDED, &
  105. TopDriveThreadId )
  106. !MudSystem
  107. MudSystemThreadHandle = CreateThread( &
  108. ThreadSecurity, &
  109. ThreadStackSize, &
  110. MudSystemThread, &
  111. loc(MudSystemThreadParam), &
  112. CREATE_SUSPENDED, &
  113. MudSystemThreadId )
  114. !PipeRams1
  115. PipeRams1ThreadHandle = CreateThread( &
  116. ThreadSecurity, &
  117. ThreadStackSize, &
  118. PipeRams1Thread, &
  119. loc(PipeRams1ThreadParam), &
  120. CREATE_SUSPENDED, &
  121. PipeRams1ThreadId )
  122. !PipeRams2
  123. PipeRams2ThreadHandle = CreateThread( &
  124. ThreadSecurity, &
  125. ThreadStackSize, &
  126. PipeRams2Thread, &
  127. loc(PipeRams2ThreadParam), &
  128. CREATE_SUSPENDED, &
  129. PipeRams2ThreadId )
  130. !KillLine
  131. KillLineThreadHandle = CreateThread( &
  132. ThreadSecurity, &
  133. ThreadStackSize, &
  134. KillLineThread, &
  135. loc(KillLineThreadParam), &
  136. CREATE_SUSPENDED, &
  137. KillLineThreadId )
  138. !ChokeLine
  139. ChokeLineThreadHandle = CreateThread( &
  140. ThreadSecurity, &
  141. ThreadStackSize, &
  142. ChokeLineThread, &
  143. loc(ChokeLineThreadParam), &
  144. CREATE_SUSPENDED, &
  145. ChokeLineThreadId )
  146. !BlindRams
  147. BlindRamsThreadHandle = CreateThread( &
  148. ThreadSecurity, &
  149. ThreadStackSize, &
  150. BlindRamsThread, &
  151. loc(BlindRamsThreadParam), &
  152. CREATE_SUSPENDED, &
  153. BlindRamsThreadId )
  154. !Annular
  155. AnnularThreadHandle = CreateThread( &
  156. ThreadSecurity, &
  157. ThreadStackSize, &
  158. AnnularThread, &
  159. loc(AnnularThreadParam), &
  160. CREATE_SUSPENDED, &
  161. AnnularThreadId )
  162. !OperationScenarios
  163. OperationScenariosThreadHandle = CreateThread( &
  164. ThreadSecurity, &
  165. ThreadStackSize, &
  166. OperationScenariosThread, &
  167. loc(OperationScenariosThreadParam), &
  168. CREATE_SUSPENDED, &
  169. OperationScenariosThreadId )
  170. !PathFinding
  171. PathFindingThreadHandle = CreateThread( &
  172. ThreadSecurity, &
  173. ThreadStackSize, &
  174. PathFindingThread, &
  175. loc(PathFindingThreadParam), &
  176. CREATE_SUSPENDED, &
  177. PathFindingThreadId )
  178. !Sample
  179. SampleThreadHandle = CreateThread( &
  180. ThreadSecurity, &
  181. ThreadStackSize, &
  182. SampleThread, &
  183. loc(SampleThreadParam), &
  184. CREATE_SUSPENDED, &
  185. SampleThreadId )
  186. #endif
  187. end subroutine InitThreads
  188. subroutine StopThreads
  189. implicit none
  190. #ifdef EnableSimulation
  191. !BopStack
  192. #ifdef HardStop
  193. ApiResult = TerminateThread(BopStackThreadHandle, 0)
  194. #else
  195. !ApiResult = WaitForSingleObject(BopStackThreadHandle, WaitForStopMs)
  196. #endif
  197. ApiResult = CloseHandle(BopStackThreadHandle)
  198. !Pump 1
  199. #ifdef HardStop
  200. ApiResult = TerminateThread(Pump1ThreadHandle, 0)
  201. #else
  202. !ApiResult = WaitForSingleObject(Pump1ThreadHandle, WaitForStopMs)
  203. #endif
  204. ApiResult = CloseHandle(Pump1ThreadHandle)
  205. !Pump 2
  206. #ifdef HardStop
  207. ApiResult = TerminateThread(Pump2ThreadHandle, 0)
  208. #else
  209. !ApiResult = WaitForSingleObject(Pump2ThreadHandle, WaitForStopMs)
  210. #endif
  211. ApiResult = CloseHandle(Pump2ThreadHandle)
  212. !Pump 3
  213. #ifdef HardStop
  214. ApiResult = TerminateThread(Pump3ThreadHandle, 0)
  215. #else
  216. !ApiResult = WaitForSingleObject(Pump3ThreadHandle, WaitForStopMs)
  217. #endif
  218. ApiResult = CloseHandle(Pump3ThreadHandle)
  219. !ChokeControl
  220. #ifdef HardStop
  221. ApiResult = TerminateThread(ChokeControlThreadHandle, 0)
  222. #else
  223. !ApiResult = WaitForSingleObject(ChokeControlThreadHandle, WaitForStopMs)
  224. #endif
  225. ApiResult = CloseHandle(ChokeControlThreadHandle)
  226. !ROP
  227. #ifdef HardStop
  228. ApiResult = TerminateThread(RopThreadHandle, 0)
  229. #else
  230. !ApiResult = WaitForSingleObject(RopThreadHandle, WaitForStopMs)
  231. #endif
  232. ApiResult = CloseHandle(RopThreadHandle)
  233. !Geo
  234. #ifdef HardStop
  235. ApiResult = TerminateThread(GeoThreadHandle, 0)
  236. #else
  237. !ApiResult = WaitForSingleObject(GeoThreadHandle, WaitForStopMs)
  238. #endif
  239. ApiResult = CloseHandle(GeoThreadHandle)
  240. !RotaryTable
  241. #ifdef HardStop
  242. ApiResult = TerminateThread(RotaryTableThreadHandle, 0)
  243. #else
  244. !ApiResult = WaitForSingleObject(RotaryTableThreadHandle, WaitForStopMs)
  245. #endif
  246. ApiResult = CloseHandle(RotaryTableThreadHandle)
  247. !Drawworks
  248. #ifdef HardStop
  249. ApiResult = TerminateThread(DrawworksThreadHandle, 0)
  250. #else
  251. !ApiResult = WaitForSingleObject(DrawworksThreadHandle, WaitForStopMs)
  252. #endif
  253. ApiResult = CloseHandle(DrawworksThreadHandle)
  254. !FluidFlow
  255. #ifdef HardStop
  256. ApiResult = TerminateThread(FluidFlowThreadHandle, 0)
  257. #else
  258. !ApiResult = WaitForSingleObject(FluidFlowThreadHandle, WaitForStopMs)
  259. #endif
  260. ApiResult = CloseHandle(FluidFlowThreadHandle)
  261. !TorqueDrag
  262. #ifdef HardStop
  263. ApiResult = TerminateThread(TorqueDragThreadHandle, 0)
  264. #else
  265. !ApiResult = WaitForSingleObject(TorqueDragThreadHandle, WaitForStopMs)
  266. #endif
  267. ApiResult = CloseHandle(TorqueDragThreadHandle)
  268. !TopDrive
  269. #ifdef HardStop
  270. ApiResult = TerminateThread(TopDriveThreadHandle, 0)
  271. #else
  272. !ApiResult = WaitForSingleObject(TopDriveThreadHandle, WaitForStopMs)
  273. #endif
  274. ApiResult = CloseHandle(TopDriveThreadHandle)
  275. !MudSystem
  276. #ifdef HardStop
  277. ApiResult = TerminateThread(MudSystemThreadHandle, 0)
  278. #else
  279. !ApiResult = WaitForSingleObject(MudSystemThreadHandle, WaitForStopMs)
  280. #endif
  281. ApiResult = CloseHandle(MudSystemThreadHandle)
  282. !PipeRams1
  283. #ifdef HardStop
  284. ApiResult = TerminateThread(PipeRams1ThreadHandle, 0)
  285. #else
  286. !ApiResult = WaitForSingleObject(PipeRams1ThreadHandle, WaitForStopMs)
  287. #endif
  288. ApiResult = CloseHandle(PipeRams1ThreadHandle)
  289. !PipeRams2
  290. #ifdef HardStop
  291. ApiResult = TerminateThread(PipeRams2ThreadHandle, 0)
  292. #else
  293. !ApiResult = WaitForSingleObject(PipeRams2ThreadHandle, WaitForStopMs)
  294. #endif
  295. ApiResult = CloseHandle(PipeRams2ThreadHandle)
  296. !KillLine
  297. #ifdef HardStop
  298. ApiResult = TerminateThread(KillLineThreadHandle, 0)
  299. #else
  300. !ApiResult = WaitForSingleObject(KillLineThreadHandle, WaitForStopMs)
  301. #endif
  302. ApiResult = CloseHandle(KillLineThreadHandle)
  303. !ChokeLine
  304. #ifdef HardStop
  305. ApiResult = TerminateThread(ChokeLineThreadHandle, 0)
  306. #else
  307. !ApiResult = WaitForSingleObject(ChokeLineThreadHandle, WaitForStopMs)
  308. #endif
  309. ApiResult = CloseHandle(ChokeLineThreadHandle)
  310. !BlindRams
  311. #ifdef HardStop
  312. ApiResult = TerminateThread(BlindRamsThreadHandle, 0)
  313. #else
  314. !ApiResult = WaitForSingleObject(BlindRamsThreadHandle, WaitForStopMs)
  315. #endif
  316. ApiResult = CloseHandle(BlindRamsThreadHandle)
  317. !Annular
  318. #ifdef HardStop
  319. ApiResult = TerminateThread(AnnularThreadHandle, 0)
  320. #else
  321. !ApiResult = WaitForSingleObject(AnnularThreadHandle, WaitForStopMs)
  322. #endif
  323. ApiResult = CloseHandle(AnnularThreadHandle)
  324. !OperationScenarios
  325. #ifdef HardStop
  326. ApiResult = TerminateThread(OperationScenariosThreadHandle, 0)
  327. #else
  328. !ApiResult = WaitForSingleObject(OperationScenariosThreadHandle, WaitForStopMs)
  329. #endif
  330. ApiResult = CloseHandle(OperationScenariosThreadHandle)
  331. !PathFinding
  332. #ifdef HardStop
  333. ApiResult = TerminateThread(PathFindingThreadHandle, 0)
  334. #else
  335. !ApiResult = WaitForSingleObject(PathFindingThreadHandle, WaitForStopMs)
  336. #endif
  337. ApiResult = CloseHandle(PathFindingThreadHandle)
  338. !Sample
  339. #ifdef HardStop
  340. ApiResult = TerminateThread(SampleThreadHandle, 0)
  341. #else
  342. !ApiResult = WaitForSingleObject(SampleThreadHandle, WaitForStopMs)
  343. #endif
  344. ApiResult = CloseHandle(SampleThreadHandle)
  345. #endif
  346. end subroutine StopThreads
  347. subroutine Initialization(portable)
  348. !DEC$ ATTRIBUTES DLLEXPORT::Initialization
  349. !DEC$ ATTRIBUTES ALIAS: 'Initialization' :: Initialization
  350. use BopStackMain
  351. use PumpsMain
  352. use ChokeControlMain
  353. use RopMain
  354. use RotaryTableMain
  355. use DrawworksMain
  356. use FluidFlowMain
  357. use TorqueDragMain
  358. use MudSystemMain
  359. use PipeRams1Main
  360. use PipeRams2Main
  361. use KillLineMain
  362. use ChokeLineMain
  363. use BlindRamsMain
  364. use AnnularMain
  365. use TopDriveMain
  366. use GeoMain
  367. use COperationScenariosMain
  368. use CManifolds
  369. implicit none
  370. logical, intent(in) :: portable
  371. IsPortable = portable
  372. if(portable) then
  373. IsPortableInt = 1
  374. !print*, 'IsPortableInt=', IsPortableInt
  375. else
  376. IsPortableInt = 0
  377. !print*, 'IsPortableInt=', IsPortableInt
  378. endif
  379. call BopStack_Setup()
  380. call Pump1_Setup()
  381. call Pump2_Setup()
  382. call Pump3_Setup()
  383. call ChokeControl_Setup()
  384. call Rop_Setup()
  385. call RotaryTable_Setup()
  386. call Drawworks_Setup()
  387. call FluidFlow_Setup()
  388. call TorqueDrag_Setup()
  389. call MudSystem_Setup()
  390. call PipeRams1_Setup()
  391. call PipeRams2_Setup()
  392. call KillLine_Setup()
  393. call ChokeLine_Setup()
  394. call BlindRams_Setup()
  395. call Annular_Setup()
  396. call TopDrive_Setup()
  397. call Geo_Setup()
  398. call OperationScenarios_Setup()
  399. call PathFinding_Setup()
  400. call Sample_Setup()
  401. call OnSimulationInitialization%RunAll()
  402. call InitThreads()
  403. call OnBopStackPause%Add(BopStack_Thread)
  404. call OnPump1Pause%Add(Pump1_Thread)
  405. call OnPump2Pause%Add(Pump2_Thread)
  406. call OnPump3Pause%Add(Pump3_Thread)
  407. call OnChokeControlPause%Add(ChokeControl_Thread)
  408. call OnRopPause%Add(Rop_Thread)
  409. call OnRotaryTablePause%Add(RotaryTable_Thread)
  410. call OnDrawworksPause%Add(Drawworks_Thread)
  411. call OnFluidFlowPause%Add(FluidFlow_Thread)
  412. call OnTorqueDragPause%Add(TorqueDrag_Thread)
  413. call OnMudSystemPause%Add(MudSystem_Thread)
  414. call OnPipeRams1Pause%Add(PipeRams1_Thread)
  415. call OnPipeRams2Pause%Add(PipeRams2_Thread)
  416. call OnKillLinePause%Add(KillLine_Thread)
  417. call OnChokeLinePause%Add(ChokeLine_Thread)
  418. call OnBlindRamsPause%Add(BlindRams_Thread)
  419. call OnAnnularPause%Add(Annular_Thread)
  420. call OnGeoPause%Add(Geo_Thread)
  421. call OnSamplePause%Add(Sample_Thread)
  422. TotalStrokesPtr => TotalStrokesDue
  423. TotalVolumePumpedPtr => TotalVolumePumpedDue
  424. DistanceDrilledPtr => DistanceDrilledDue
  425. !TODO: CHANGE LATER
  426. call DrillMode_ON()
  427. end subroutine Initialization
  428. subroutine StartSimulation
  429. !DEC$ ATTRIBUTES DLLEXPORT::StartSimulation
  430. !DEC$ ATTRIBUTES ALIAS: 'StartSimulation' :: StartSimulation
  431. implicit none
  432. if(SimulationState_old == SimulationState_Stopped) call OnSimulationStart%RunAll()
  433. IsStopped = .false.
  434. SimulationState = SimulationState_Started
  435. SimulationState_old = SimulationState_Started
  436. BopStackStarted = .false.
  437. Pump1Started = .false.
  438. Pump2Started = .false.
  439. Pump3Started = .false.
  440. ChokeControlStarted = .false.
  441. RopStarted = .false.
  442. RotaryTableStarted = .false.
  443. DrawworksStarted = .false.
  444. FluidFlowStarted = .false.
  445. TorqueDragStarted = .false.
  446. MudSystemStarted = .false.
  447. PipeRams1Started = .false.
  448. PipeRams2Started = .false.
  449. KillLineStarted = .false.
  450. ChokeLineStarted = .false.
  451. BlindRamsStarted = .false.
  452. AnnularStarted = .false.
  453. GeoStarted = .false.
  454. SampleStarted = .false.
  455. #ifdef EnableSimulation
  456. #ifdef M_BopStack
  457. ApiResult = ResumeThread(BopStackThreadHandle)
  458. #endif
  459. #ifdef M_Pump1
  460. ApiResult = ResumeThread(Pump1ThreadHandle)
  461. #endif
  462. #ifdef M_Pump2
  463. ApiResult = ResumeThread(Pump2ThreadHandle)
  464. #endif
  465. #ifdef M_Pump3
  466. ApiResult = ResumeThread(Pump3ThreadHandle)
  467. #endif
  468. #ifdef M_ChokeControl
  469. ApiResult = ResumeThread(ChokeControlThreadHandle)
  470. #endif
  471. #ifdef M_Rop
  472. ApiResult = ResumeThread(RopThreadHandle)
  473. #endif
  474. #ifdef M_Geo
  475. ApiResult = ResumeThread(GeoThreadHandle)
  476. #endif
  477. #ifdef M_RotaryTable
  478. ApiResult = ResumeThread(RotaryTableThreadHandle)
  479. #endif
  480. #ifdef M_Drawworks
  481. ApiResult = ResumeThread(DrawworksThreadHandle)
  482. #endif
  483. #ifdef M_FluidFlow
  484. ApiResult = ResumeThread(FluidFlowThreadHandle)
  485. #endif
  486. #ifdef M_TorqueDrag
  487. ApiResult = ResumeThread(TorqueDragThreadHandle)
  488. #endif
  489. #ifdef M_TopDrive
  490. ApiResult = ResumeThread(TopDriveThreadHandle)
  491. #endif
  492. #ifdef M_MudSystem
  493. ApiResult = ResumeThread(MudSystemThreadHandle)
  494. #endif
  495. #ifdef M_PipeRams1
  496. ApiResult = ResumeThread(PipeRams1ThreadHandle)
  497. #endif
  498. #ifdef M_PipeRams2
  499. ApiResult = ResumeThread(PipeRams2ThreadHandle)
  500. #endif
  501. #ifdef M_KillLine
  502. ApiResult = ResumeThread(KillLineThreadHandle)
  503. #endif
  504. #ifdef M_ChokeLine
  505. ApiResult = ResumeThread(ChokeLineThreadHandle)
  506. #endif
  507. #ifdef M_BlindRams
  508. ApiResult = ResumeThread(BlindRamsThreadHandle)
  509. #endif
  510. #ifdef M_Annular
  511. ApiResult = ResumeThread(AnnularThreadHandle)
  512. #endif
  513. !OperationScenarios
  514. ApiResult = ResumeThread(OperationScenariosThreadHandle)
  515. !PathFinding
  516. ApiResult = ResumeThread(PathFindingThreadHandle)
  517. #ifdef M_Sample
  518. ApiResult = ResumeThread(SampleThreadHandle)
  519. #endif
  520. #endif
  521. end subroutine StartSimulation
  522. subroutine StopSimulation
  523. !DEC$ ATTRIBUTES DLLEXPORT::StopSimulation
  524. !DEC$ ATTRIBUTES ALIAS: 'StopSimulation' :: StopSimulation
  525. use CDrillingConsoleVariables!, only: DrillingConsole%MP1CPSwitchI, DrillingConsole%MP2SwitchI, DrillingConsole%MP1CPSwitch, DrillingConsole%MP2Switch, DrillingConsole%MP1Throttle, DrillingConsole%MP2Throttle, DrillingConsole%MP1ThrottleUpdate, DrillingConsole%MP2ThrottleUpdate
  526. implicit none
  527. DrillingConsole%MP1CPSwitchI = 0
  528. DrillingConsole%MP1CPSwitch = 0
  529. DrillingConsole%MP2SwitchI = 0
  530. DrillingConsole%MP2Switch = .false.
  531. DrillingConsole%MP1ThrottleUpdate = .false.
  532. DrillingConsole%MP2ThrottleUpdate = .false.
  533. DrillingConsole%MP1Throttle = -1.0
  534. DrillingConsole%MP2Throttle = -1.0
  535. !MP1Throttle = 0.0
  536. !MP2Throttle = 0.0
  537. IsSnapshot = .false.
  538. IsStopped = .true.
  539. TotalPumpStrokes = 0
  540. TotalVolumePumped = 0
  541. DistanceDrilled = 0
  542. SimulationState = SimulationState_Stopped
  543. SimulationState_old = SimulationState_Stopped
  544. call OnSimulationStop%RunAll()
  545. call StopThreads()
  546. call InitThreads()
  547. end subroutine StopSimulation
  548. subroutine PauseSimulation
  549. implicit none
  550. if(SimulationState_old == SimulationState_Stopped) then
  551. SimulationState_old = SimulationState_Started
  552. return
  553. endif
  554. SimulationState_old = SimulationState_Paused
  555. #ifdef EnableSimulation
  556. !BopStack
  557. ApiResult = SuspendThread(BopStackThreadHandle)
  558. !Pumps
  559. ApiResult = SuspendThread(Pump1ThreadHandle)
  560. ApiResult = SuspendThread(Pump2ThreadHandle)
  561. ApiResult = SuspendThread(Pump3ThreadHandle)
  562. !ChokeControl
  563. ApiResult = SuspendThread(ChokeControlThreadHandle)
  564. !ROP
  565. ApiResult = SuspendThread(RopThreadHandle)
  566. !Geo
  567. ApiResult = SuspendThread(GeoThreadHandle)
  568. !RotaryTable
  569. ApiResult = SuspendThread(RotaryTableThreadHandle)
  570. !Drawworks
  571. ApiResult = SuspendThread(DrawworksThreadHandle)
  572. !FluidFlow
  573. ApiResult = SuspendThread(FluidFlowThreadHandle)
  574. !TorqueDrag
  575. ApiResult = SuspendThread(TorqueDragThreadHandle)
  576. !TopDrive
  577. ApiResult = SuspendThread(TopDriveThreadHandle)
  578. !MudSystem
  579. ApiResult = SuspendThread(MudSystemThreadHandle)
  580. !PipeRams1
  581. ApiResult = SuspendThread(PipeRams1ThreadHandle)
  582. !PipeRams2
  583. ApiResult = SuspendThread(PipeRams2ThreadHandle)
  584. !KillLine
  585. ApiResult = SuspendThread(KillLineThreadHandle)
  586. !ChokeLine
  587. ApiResult = SuspendThread(ChokeLineThreadHandle)
  588. !BlindRams
  589. ApiResult = SuspendThread(BlindRamsThreadHandle)
  590. !Annular
  591. ApiResult = SuspendThread(AnnularThreadHandle)
  592. !OperationScenarios
  593. ApiResult = SuspendThread(OperationScenariosThreadHandle)
  594. !PathFinding
  595. ApiResult = SuspendThread(PathFindingThreadHandle)
  596. !Sample
  597. ApiResult = SuspendThread(SampleThreadHandle)
  598. #endif
  599. call OnSimulationPause%RunAll()
  600. end subroutine PauseSimulation
  601. logical function IsRunning()
  602. !DEC$ ATTRIBUTES DLLEXPORT :: IsRunning
  603. !DEC$ ATTRIBUTES ALIAS: 'IsRunning' :: IsRunning
  604. implicit none
  605. IsRunning = .not. IsStopped
  606. end function
  607. subroutine OnTimerTick(time, state)
  608. !DEC$ ATTRIBUTES DLLEXPORT :: OnTimerTick
  609. !DEC$ ATTRIBUTES ALIAS: 'OnTimerTick' :: OnTimerTick
  610. implicit none
  611. integer, intent(in) :: time
  612. integer, intent(in) :: state
  613. SimulationState = state
  614. SimulationTime = time
  615. end subroutine
  616. subroutine TimerTick(s)
  617. !DEC$ ATTRIBUTES DLLEXPORT :: TimerTick
  618. !DEC$ ATTRIBUTES ALIAS: 'TimerTick' :: TimerTick
  619. use CBitProblemsVariables
  620. use CBopProblemsVariables
  621. use CChokeProblemsVariables
  622. use CDrillStemProblemsVariables
  623. use CGaugesProblemsVariables
  624. use CHoistingProblemsVariables
  625. use CLostProblemsVariables
  626. use CMudTreatmentProblemsVariables
  627. use COtherProblemsVariables
  628. use CPumpProblemsVariables
  629. use CRotaryProblemsVariables
  630. use CKickProblemsVariables
  631. use GeoMain
  632. implicit none
  633. integer, intent(in) :: s
  634. SimulationTime = s
  635. call ProcessBitProblemsDueTime(s)
  636. call ProcessBopProblemsDueTime(s)
  637. call ProcessChokeProblemsDueTime(s)
  638. call ProcessDrillStemProblemsDueTime(s)
  639. call ProcessGaugesProblemsDueTime(s)
  640. call ProcessHoistingProblemsDueTime(s)
  641. call ProcessLostProblemsDueTime(s)
  642. call ProcessMudTreatmentProblemsDueTime(s)
  643. call ProcessOtherProblemsDueTime(s)
  644. call ProcessPumpProblemsDueTime(s)
  645. call ProcessRotaryProblemsDueTime(s)
  646. call ProcessKickProblemsDueTime(s)
  647. #ifdef S_BopStack
  648. ApiResult = ResumeThread(BopStackThreadHandle)
  649. #endif
  650. #ifdef S_Pump1
  651. ApiResult = ResumeThread(Pump1ThreadHandle)
  652. #endif
  653. #ifdef S_Pump2
  654. ApiResult = ResumeThread(Pump2ThreadHandle)
  655. #endif
  656. #ifdef S_Pump3
  657. ApiResult = ResumeThread(Pump3ThreadHandle)
  658. #endif
  659. #ifdef S_ChokeControl
  660. ApiResult = ResumeThread(ChokeControlThreadHandle)
  661. #endif
  662. #ifdef S_Rop
  663. ApiResult = ResumeThread(RopThreadHandle)
  664. #endif
  665. #ifdef S_RotaryTable
  666. ApiResult = ResumeThread(RotaryTableThreadHandle)
  667. #endif
  668. #ifdef S_Drawworks
  669. ApiResult = ResumeThread(DrawworksThreadHandle)
  670. #endif
  671. #ifdef S_FluidFlow
  672. ApiResult = ResumeThread(FluidFlowThreadHandle)
  673. #endif
  674. #ifdef S_TorqueDrag
  675. ApiResult = ResumeThread(TorqueDragThreadHandle)
  676. #endif
  677. #ifdef S_TopDrive
  678. ApiResult = ResumeThread(TopDriveThreadHandle)
  679. #endif
  680. #ifdef S_MudSystem
  681. ApiResult = ResumeThread(MudSystemThreadHandle)
  682. #endif
  683. #ifdef S_PipeRams1
  684. ApiResult = ResumeThread(PipeRams1ThreadHandle)
  685. #endif
  686. #ifdef S_PipeRams2
  687. ApiResult = ResumeThread(PipeRams2ThreadHandle)
  688. #endif
  689. #ifdef S_KillLine
  690. ApiResult = ResumeThread(KillLineThreadHandle)
  691. #endif
  692. #ifdef S_ChokeLine
  693. ApiResult = ResumeThread(ChokeLineThreadHandle)
  694. #endif
  695. #ifdef S_BlindRams
  696. ApiResult = ResumeThread(BlindRamsThreadHandle)
  697. #endif
  698. #ifdef S_Annular ت
  699. ApiResult = ResumeThread(AnnularThreadHandle)
  700. #endif
  701. #ifdef S_Geo
  702. ApiResult = ResumeThread(GeoThreadHandle)
  703. #endif
  704. #ifdef S_Sample
  705. ApiResult = ResumeThread(SampleThreadHandle)
  706. #endif
  707. end subroutine
  708. subroutine StateChanged(state)
  709. !DEC$ ATTRIBUTES DLLEXPORT :: StateChanged
  710. !DEC$ ATTRIBUTES ALIAS: 'StateChanged' :: StateChanged
  711. implicit none
  712. integer, intent(in) :: state
  713. SimulationState = state
  714. if(SimulationState == SimulationState_Paused) call PauseSimulation()
  715. end subroutine
  716. subroutine SetSimulationSpeed(speed)
  717. !DEC$ ATTRIBUTES DLLEXPORT :: SetSimulationSpeed
  718. !DEC$ ATTRIBUTES ALIAS: 'SetSimulationSpeed' :: SetSimulationSpeed
  719. implicit none
  720. integer, intent(in) :: speed
  721. SimulationSpeed = speed
  722. end subroutine
  723. subroutine SetSnapshot(s)
  724. !DEC$ ATTRIBUTES DLLEXPORT::SetSnapshot
  725. !DEC$ ATTRIBUTES ALIAS: 'SetSnapshot' :: SetSnapshot
  726. implicit none
  727. logical, intent(in) :: s
  728. IsSnapshot = s
  729. !if(IsSnapshot) SimulationState_old = SimulationState_Started
  730. end subroutine SetSnapshot
  731. subroutine TotalStrokesDue(strokes)
  732. use CBitProblemsVariables
  733. use CBopProblemsVariables
  734. use CChokeProblemsVariables
  735. use CDrillStemProblemsVariables
  736. use CGaugesProblemsVariables
  737. use CHoistingProblemsVariables
  738. use CLostProblemsVariables
  739. use CMudTreatmentProblemsVariables
  740. use COtherProblemsVariables
  741. use CPumpProblemsVariables
  742. use CRotaryProblemsVariables
  743. use CKickProblemsVariables
  744. implicit none
  745. integer, intent(in) :: strokes
  746. call ProcessBitProblemsDuePumpStrokes(strokes)
  747. call ProcessBopProblemsDuePumpStrokes(strokes)
  748. call ProcessChokeProblemsDuePumpStrokes(strokes)
  749. call ProcessDrillStemProblemsDuePumpStrokes(strokes)
  750. call ProcessGaugesProblemsDuePumpStrokes(strokes)
  751. call ProcessHoistingProblemsDuePumpStrokes(strokes)
  752. call ProcessLostProblemsDuePumpStrokes(strokes)
  753. call ProcessMudTreatmentProblemsDuePumpStrokes(strokes)
  754. call ProcessOtherProblemsDuePumpStrokes(strokes)
  755. call ProcessPumpProblemsDuePumpStrokes(strokes)
  756. call ProcessRotaryProblemsDuePumpStrokes(strokes)
  757. call ProcessKickProblemsDuePumpStrokes(strokes)
  758. end subroutine
  759. subroutine TotalVolumePumpedDue(volume)
  760. use CBitProblemsVariables
  761. use CBopProblemsVariables
  762. use CChokeProblemsVariables
  763. use CDrillStemProblemsVariables
  764. use CGaugesProblemsVariables
  765. use CHoistingProblemsVariables
  766. use CLostProblemsVariables
  767. use CMudTreatmentProblemsVariables
  768. use COtherProblemsVariables
  769. use CPumpProblemsVariables
  770. use CRotaryProblemsVariables
  771. use CKickProblemsVariables
  772. implicit none
  773. real(8), intent(in) :: volume
  774. call ProcessBitProblemsDueVolumePumped(volume)
  775. call ProcessBopProblemsDueVolumePumped(volume)
  776. call ProcessChokeProblemsDueVolumePumped(volume)
  777. call ProcessDrillStemProblemsDueVolumePumped(volume)
  778. call ProcessGaugesProblemsDueVolumePumped(volume)
  779. call ProcessHoistingProblemsDueVolumePumped(volume)
  780. call ProcessLostProblemsDueVolumePumped(volume)
  781. call ProcessMudTreatmentProblemsDueVolumePumped(volume)
  782. call ProcessOtherProblemsDueVolumePumped(volume)
  783. call ProcessPumpProblemsDueVolumePumped(volume)
  784. call ProcessRotaryProblemsDueVolumePumped(volume)
  785. call ProcessKickProblemsDueVolumePumped(volume)
  786. end subroutine
  787. subroutine DistanceDrilledDue(distance)
  788. use CBitProblemsVariables
  789. use CBopProblemsVariables
  790. use CChokeProblemsVariables
  791. use CDrillStemProblemsVariables
  792. use CGaugesProblemsVariables
  793. use CHoistingProblemsVariables
  794. use CLostProblemsVariables
  795. use CMudTreatmentProblemsVariables
  796. use COtherProblemsVariables
  797. use CPumpProblemsVariables
  798. use CRotaryProblemsVariables
  799. use CKickProblemsVariables
  800. implicit none
  801. real(8), intent(in) :: distance
  802. call ProcessBitProblemsDueDistanceDrilled(distance)
  803. call ProcessBopProblemsDueDistanceDrilled(distance)
  804. call ProcessChokeProblemsDueDistanceDrilled(distance)
  805. call ProcessDrillStemProblemsDueDistanceDrilled(distance)
  806. call ProcessGaugesProblemsDueDistanceDrilled(distance)
  807. call ProcessHoistingProblemsDueDistanceDrilled(distance)
  808. call ProcessLostProblemsDueDistanceDrilled(distance)
  809. call ProcessMudTreatmentProblemsDueDistanceDrilled(distance)
  810. call ProcessOtherProblemsDueDistanceDrilled(distance)
  811. call ProcessPumpProblemsDueDistanceDrilled(distance)
  812. call ProcessRotaryProblemsDueDistanceDrilled(distance)
  813. call ProcessKickProblemsDueDistanceDrilled(distance)
  814. end subroutine
  815. subroutine BopStack_Thread
  816. implicit none
  817. ApiResult = SuspendThread(BopStackThreadHandle)
  818. end subroutine BopStack_Thread
  819. subroutine Pump1_Thread
  820. implicit none
  821. ApiResult = SuspendThread(Pump1ThreadHandle)
  822. end subroutine Pump1_Thread
  823. subroutine Pump2_Thread
  824. implicit none
  825. ApiResult = SuspendThread(Pump2ThreadHandle)
  826. end subroutine Pump2_Thread
  827. subroutine Pump3_Thread
  828. implicit none
  829. ApiResult = SuspendThread(Pump3ThreadHandle)
  830. end subroutine Pump3_Thread
  831. subroutine ChokeControl_Thread
  832. implicit none
  833. ApiResult = SuspendThread(ChokeControlThreadHandle)
  834. end subroutine ChokeControl_Thread
  835. subroutine Rop_Thread
  836. implicit none
  837. ApiResult = SuspendThread(RopThreadHandle)
  838. end subroutine Rop_Thread
  839. subroutine RotaryTable_Thread
  840. implicit none
  841. ApiResult = SuspendThread(RotaryTableThreadHandle)
  842. end subroutine RotaryTable_Thread
  843. subroutine Drawworks_Thread
  844. implicit none
  845. ApiResult = SuspendThread(DrawworksThreadHandle)
  846. end subroutine Drawworks_Thread
  847. subroutine FluidFlow_Thread
  848. implicit none
  849. ApiResult = SuspendThread(FluidFlowThreadHandle)
  850. end subroutine FluidFlow_Thread
  851. subroutine TorqueDrag_Thread
  852. implicit none
  853. ApiResult = SuspendThread(TorqueDragThreadHandle)
  854. end subroutine TorqueDrag_Thread
  855. subroutine TopDrive_Thread
  856. implicit none
  857. ApiResult = SuspendThread(TopDriveThreadHandle)
  858. end subroutine TopDrive_Thread
  859. subroutine MudSystem_Thread
  860. implicit none
  861. ApiResult = SuspendThread(MudSystemThreadHandle)
  862. end subroutine MudSystem_Thread
  863. subroutine PipeRams1_Thread
  864. implicit none
  865. ApiResult = SuspendThread(PipeRams1ThreadHandle)
  866. end subroutine PipeRams1_Thread
  867. subroutine PipeRams2_Thread
  868. implicit none
  869. ApiResult = SuspendThread(PipeRams2ThreadHandle)
  870. end subroutine PipeRams2_Thread
  871. subroutine KillLine_Thread
  872. implicit none
  873. ApiResult = SuspendThread(KillLineThreadHandle)
  874. end subroutine KillLine_Thread
  875. subroutine ChokeLine_Thread
  876. implicit none
  877. ApiResult = SuspendThread(ChokeLineThreadHandle)
  878. end subroutine ChokeLine_Thread
  879. subroutine BlindRams_Thread
  880. implicit none
  881. ApiResult = SuspendThread(BlindRamsThreadHandle)
  882. end subroutine BlindRams_Thread
  883. subroutine Annular_Thread
  884. implicit none
  885. ApiResult = SuspendThread(AnnularThreadHandle)
  886. end subroutine Annular_Thread
  887. subroutine Geo_Thread
  888. implicit none
  889. ApiResult = SuspendThread(GeoThreadHandle)
  890. end subroutine Geo_Thread
  891. subroutine Sample_Thread
  892. implicit none
  893. ApiResult = SuspendThread(SampleThreadHandle)
  894. end subroutine Sample_Thread
  895. end module CSimulation