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.
 
 
 
 
 
 

1358 lines
38 KiB

  1. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/MudPathFinding/CManifolds.f90"
  2. module CManifolds
  3. use CStack
  4. use CArrangement
  5. ! use CPathChangeEvents
  6. ! use CDrillingConsoleVariables
  7. use SimulationVariables
  8. ! use ConfigurationVariables, only: EquipmentControl
  9. implicit none
  10. public
  11. integer, parameter :: ValveCount = 128
  12. integer, parameter :: MinSource = 71
  13. integer, parameter :: MaxSource = 90
  14. integer, parameter :: MinRelation = 91
  15. integer, parameter :: MaxRelation = 128
  16. Type::ManifoldType
  17. type(Arrangement) :: Valve(ValveCount)
  18. type(Path), allocatable :: OpenPaths(:)
  19. type(Stack) :: Fringe
  20. logical :: IsRepititveOutput
  21. logical :: IsSafetyValveInstalled
  22. logical :: IsSafetyValveInstalled_KellyMode
  23. logical :: IsSafetyValveInstalled_TripMode
  24. logical :: IsSafetyValveInstalled_TopDrive
  25. logical :: SafetyValve
  26. logical :: IsIBopInstalled
  27. logical :: IBop
  28. logical :: IsKellyCockInstalled
  29. logical :: KellyCock
  30. logical :: IsTopDriveIBopInstalled
  31. logical :: TopDriveIBop
  32. logical :: IsFloatValveInstalled
  33. logical :: FloatValve
  34. logical :: IsPathsDirty = .false.
  35. logical :: IsTraverse = .false.
  36. End type ManifoldType
  37. type(ManifoldType)::Manifold
  38. contains
  39. subroutine PathFinding_Setup()
  40. ! use CSimulationVariables
  41. implicit none
  42. Manifold%IsTraverse = .false.
  43. call Setup()
  44. !call OnSimulationInitialization%Add(PathFinding_Init)
  45. !call OnSimulationStop%Add(PathFinding_Init)
  46. !!**call OnpPathFindingStep%Add(PathFinding_Step)
  47. !!**call OnpPathFindingOutput%Add(PathFinding_Output)
  48. ! !**call OnpPathFindingMain%Add(PathFindingMainBody)
  49. end subroutine
  50. subroutine PathFinding_Init
  51. implicit none
  52. Manifold%IsTraverse = .false.
  53. call Setup()
  54. end subroutine PathFinding_Init
  55. subroutine PathFinding_Step
  56. if (Manifold%IsPathsDirty) then
  57. Manifold%IsPathsDirty = .false.
  58. call Traverse()
  59. endif
  60. end subroutine PathFinding_Step
  61. ! subroutine PathFinding_Output
  62. ! implicit none
  63. ! end subroutine PathFinding_Output
  64. ! subroutine PathFindingMainBody
  65. ! ! use CSimulationVariables
  66. ! implicit none
  67. ! loop : do
  68. ! if(IsStopped) call Quit()
  69. ! call sleepqq(50)
  70. ! if (Manifold%IsPathsDirty) then
  71. ! Manifold%IsPathsDirty = .false.
  72. ! call Traverse()
  73. ! endif
  74. ! end do loop
  75. ! end subroutine PathFindingMainBody
  76. subroutine Traverse()
  77. use CLog5
  78. implicit none
  79. integer :: i, Duration
  80. integer, dimension(8) :: StartTime,EndTime !TODO: clean up
  81. call DATE_AND_TIME(values=StartTime) !TODO: clean up
  82. !**call BeforeTraverse%RunAll()
  83. if(allocated(Manifold%OpenPaths)) deallocate(Manifold%OpenPaths)
  84. do i=MinSource, MaxSource
  85. if(IsValveOpen(i)) then
  86. call AddRootNode(i)
  87. call AddChildren(Manifold%Valve(i))
  88. endif
  89. enddo
  90. call PostProcess(Manifold%OpenPaths)
  91. !**call AfterTraverse%RunAll()
  92. Manifold%IsTraverse = .true.
  93. !TODO: clean up
  94. # 118
  95. endsubroutine
  96. subroutine PostProcess(pathArr)
  97. implicit none
  98. type(Path), allocatable, intent(inout) :: pathArr(:)
  99. integer :: i
  100. if(.not.allocated(pathArr)) return
  101. i = 1
  102. do
  103. call pathArr(i)%Purge(MinRelation, MaxRelation)
  104. if(pathArr(i)%Length() <= 2) then
  105. call RemovePath(pathArr, i)
  106. else
  107. i = i + 1
  108. endif
  109. if(i > size(pathArr)) exit
  110. enddo
  111. end subroutine
  112. subroutine AddRootNode(valve)
  113. implicit none
  114. integer, intent(in) :: valve
  115. call Manifold%Fringe%Push(valve)
  116. end subroutine
  117. recursive subroutine AddChildren(node)
  118. implicit none
  119. type(Arrangement), intent(inout) :: node
  120. integer :: i,t
  121. do i=1, Manifold%Valve(node%Number)%Length()
  122. t = Manifold%Valve(node%Number)%Adjacent(i)
  123. if(IsValveOpen(t)) then
  124. if(Manifold%Fringe%DoesHave(t)) cycle
  125. call Manifold%Fringe%Push(t)
  126. if(Manifold%Valve(t)%IsSource()) then
  127. call AddPath(Manifold%OpenPaths, Manifold%Fringe%List)
  128. call Manifold%Fringe%Pop()
  129. cycle
  130. endif
  131. call AddChildren(Manifold%Valve(node%Adjacent(i)))
  132. end if
  133. enddo
  134. call Manifold%Fringe%Pop()
  135. end subroutine
  136. logical function IsValveOpen(no)
  137. implicit none
  138. integer, intent(in) :: no
  139. IsValveOpen = Manifold%Valve(no)%Status
  140. end function
  141. subroutine AddPath(pathArr, p)
  142. implicit none
  143. type(Path), intent(in) :: p
  144. type(Path), allocatable, intent(inout) :: pathArr(:)
  145. type(Path), allocatable :: tempArr(:)
  146. integer :: i, isize
  147. if(p%IsNull()) return
  148. if(p%Length()<=1) return
  149. !**call OnpPathOpen%RunAll(p%Valves)
  150. if(allocated(pathArr)) then
  151. isize = size(pathArr)
  152. ! check to see if already have a path same as p
  153. do i=1,isize
  154. if(pathArr(i)%First()==p%First() .and. pathArr(i)%Last()==p%Last()) then
  155. ! if there is then
  156. ! check to see if both have exacly a same length
  157. if(pathArr(i)%Length()==p%Length())then
  158. ! now they are the same so ignore adding this one
  159. return
  160. else
  161. !if they have different lengths then choose the shorter one
  162. if(pathArr(i)%Length()>p%Length())pathArr(i) = p
  163. return
  164. endif
  165. endif
  166. end do
  167. !TODO: if p last valve is input source then ignore adding it
  168. !TODO: if p start valve is output source then ignore adding it
  169. ! if p is a new entry then add it to the collections of found paths
  170. allocate(tempArr(isize+1))
  171. do i=1,isize
  172. tempArr(i) = pathArr(i)
  173. end do
  174. tempArr(isize+1) = p
  175. deallocate(pathArr)
  176. call move_alloc(tempArr, pathArr)
  177. else
  178. allocate(pathArr(1))
  179. pathArr(1) = p
  180. end if
  181. endsubroutine
  182. subroutine RemovePath(pathArr, index)
  183. implicit none
  184. integer, intent(in) :: index
  185. type(Path), allocatable, intent(inout) :: pathArr(:)
  186. type(Path), allocatable :: tempArr(:)
  187. integer :: i
  188. logical :: found
  189. if(index <= 0 .or. index > size(pathArr)) return
  190. if(.not.allocated(pathArr))return
  191. allocate(tempArr(size(pathArr)-1))
  192. found = .false.
  193. do i=1, size(pathArr)
  194. if(i==index) then
  195. found = .true.
  196. cycle
  197. end if
  198. if(found) then
  199. tempArr(i-1) = pathArr(i)
  200. !!**call OnpPathClose%RunAll(pathArr(i)%Valves)
  201. else
  202. tempArr(i) = pathArr(i)
  203. endif
  204. end do
  205. deallocate(pathArr)
  206. call move_alloc(tempArr, pathArr)
  207. endsubroutine
  208. subroutine Setup()
  209. implicit none
  210. integer :: i
  211. ! initialize all valves
  212. do i = 1, ValveCount
  213. call Manifold%Valve(i)%init(i)
  214. end do
  215. ! open source valves
  216. do i = MinSource , MaxSource
  217. Manifold%Valve(i)%Status = .true.
  218. Manifold%Valve(i)%ValveType = InputOutput
  219. end do
  220. do i = MinRelation , MaxRelation
  221. Manifold%Valve(i)%Status = .true.
  222. Manifold%Valve(i)%ValveType = Relation
  223. end do
  224. ! make adjustments
  225. call Manifold%Valve(1)%AdjacentTo(91)
  226. call Manifold%Valve(2)%AdjacentTo(92)
  227. call Manifold%Valve(2)%AdjacentTo(117)
  228. call Manifold%Valve(3)%AdjacentTo(93)
  229. call Manifold%Valve(3)%AdjacentTo(118)
  230. call Manifold%Valve(4)%AdjacentTo(94)
  231. call Manifold%Valve(5)%AdjacentTo(95)
  232. call Manifold%Valve(6)%AdjacentTo(91)
  233. call Manifold%Valve(6)%AdjacentTo(92)
  234. call Manifold%Valve(7)%AdjacentTo(92)
  235. call Manifold%Valve(7)%AdjacentTo(93)
  236. call Manifold%Valve(8)%AdjacentTo(93)
  237. call Manifold%Valve(8)%AdjacentTo(94)
  238. call Manifold%Valve(9)%AdjacentTo(91)
  239. call Manifold%Valve(9)%AdjacentTo(96)
  240. call Manifold%Valve(10)%AdjacentTo(94)
  241. call Manifold%Valve(10)%AdjacentTo(98)
  242. call Manifold%Valve(11)%AdjacentTo(96)
  243. call Manifold%Valve(11)%AdjacentTo(97)
  244. call Manifold%Valve(12)%AdjacentTo(97)
  245. call Manifold%Valve(12)%AdjacentTo(98)
  246. call Manifold%Valve(13)%AdjacentTo(96)
  247. call Manifold%Valve(13)%AdjacentTo(99)
  248. call Manifold%Valve(14)%AdjacentTo(78)
  249. call Manifold%Valve(14)%AdjacentTo(97)
  250. !call Valve(14)%AdjacentTo(126)
  251. call Manifold%Valve(15)%AdjacentTo(98)
  252. call Manifold%Valve(15)%AdjacentTo(99)
  253. call Manifold%Valve(16)%AdjacentTo(121)
  254. !call Valve(16)%AdjacentTo()
  255. call Manifold%Valve(17)%AdjacentTo(122)
  256. !call Valve(17)%AdjacentTo()
  257. call Manifold%Valve(18)%AdjacentTo(123)
  258. !call Valve(18)%AdjacentTo()
  259. call Manifold%Valve(19)%AdjacentTo(101)
  260. call Manifold%Valve(19)%AdjacentTo(102)
  261. call Manifold%Valve(20)%AdjacentTo(100)
  262. call Manifold%Valve(21)%AdjacentTo(101)
  263. call Manifold%Valve(22)%AdjacentTo(102)
  264. call Manifold%Valve(23)%AdjacentTo(71)
  265. call Manifold%Valve(24)%AdjacentTo(71)
  266. call Manifold%Valve(25)%AdjacentTo(108)
  267. call Manifold%Valve(25)%AdjacentTo(118)
  268. call Manifold%Valve(26)%AdjacentTo(109)
  269. call Manifold%Valve(26)%AdjacentTo(117)
  270. call Manifold%Valve(27)%AdjacentTo(32)
  271. call Manifold%Valve(27)%AdjacentTo(108)
  272. call Manifold%Valve(28)%AdjacentTo(33)
  273. call Manifold%Valve(28)%AdjacentTo(108)
  274. call Manifold%Valve(29)%AdjacentTo(110)
  275. call Manifold%Valve(29)%AdjacentTo(113)
  276. call Manifold%Valve(30)%AdjacentTo(34)
  277. call Manifold%Valve(30)%AdjacentTo(109)
  278. call Manifold%Valve(31)%AdjacentTo(35)
  279. call Manifold%Valve(31)%AdjacentTo(109)
  280. call Manifold%Valve(32)%AdjacentTo(27)
  281. call Manifold%Valve(32)%AdjacentTo(61)
  282. call Manifold%Valve(33)%AdjacentTo(28)
  283. call Manifold%Valve(33)%AdjacentTo(62)
  284. call Manifold%Valve(34)%AdjacentTo(30)
  285. call Manifold%Valve(34)%AdjacentTo(63)
  286. call Manifold%Valve(35)%AdjacentTo(31)
  287. call Manifold%Valve(35)%AdjacentTo(64)
  288. call Manifold%Valve(36)%AdjacentTo(116)
  289. call Manifold%Valve(37)%AdjacentTo(78)
  290. call Manifold%Valve(38)%AdjacentTo(71)
  291. call Manifold%Valve(39)%AdjacentTo(77)
  292. !call Valve(40)%AdjacentTo(105)
  293. call Manifold%Valve(40)%AdjacentTo(80)
  294. call Manifold%Valve(41)%AdjacentTo(77)
  295. call Manifold%Valve(42)%AdjacentTo(71)
  296. call Manifold%Valve(43)%AdjacentTo(106)
  297. call Manifold%Valve(44)%AdjacentTo(77)
  298. call Manifold%Valve(45)%AdjacentTo(71)
  299. call Manifold%Valve(46)%AdjacentTo(104)
  300. call Manifold%Valve(47)%AdjacentTo(104)
  301. call Manifold%Valve(47)%AdjacentTo(117)
  302. call Manifold%Valve(48)%AdjacentTo(69)
  303. call Manifold%Valve(48)%AdjacentTo(79)
  304. call Manifold%Valve(49)%AdjacentTo(104)
  305. call Manifold%Valve(49)%AdjacentTo(79)
  306. !call Valve(50)%AdjacentTo(48)
  307. call Manifold%Valve(50)%AdjacentTo(51)
  308. !call Valve(50)%AdjacentTo(54)
  309. call Manifold%Valve(50)%AdjacentTo(104)
  310. call Manifold%Valve(51)%AdjacentTo(50)
  311. call Manifold%Valve(51)%AdjacentTo(52)
  312. call Manifold%Valve(52)%AdjacentTo(51)
  313. !call Valve(52)%AdjacentTo(127)
  314. call Manifold%Valve(52)%AdjacentTo(80)
  315. !call Valve(53)%AdjacentTo(103)
  316. !call Valve(53)%AdjacentTo(105)
  317. call Manifold%Valve(53)%AdjacentTo(80)
  318. !call Valve(54)%AdjacentTo(69)
  319. !call Valve(54)%AdjacentTo(124)
  320. !call Valve(55)%AdjacentTo(103)
  321. !call Valve(55)%AdjacentTo(124)
  322. call Manifold%Valve(56)%AdjacentTo(128)
  323. call Manifold%Valve(56)%AdjacentTo(127)
  324. !call Valve(57)%AdjacentTo(14)
  325. !call Valve(57)%AdjacentTo(103)
  326. !call Valve(57)%AdjacentTo(126)
  327. call Manifold%Valve(58)%AdjacentTo(78)
  328. call Manifold%Valve(59)%AdjacentTo(78)
  329. call Manifold%Valve(60)%AdjacentTo(78)
  330. call Manifold%Valve(61)%AdjacentTo(32)
  331. call Manifold%Valve(61)%AdjacentTo(115)
  332. call Manifold%Valve(62)%AdjacentTo(33)
  333. call Manifold%Valve(62)%AdjacentTo(114)
  334. call Manifold%Valve(63)%AdjacentTo(112)
  335. call Manifold%Valve(63)%AdjacentTo(34)
  336. call Manifold%Valve(64)%AdjacentTo(35)
  337. call Manifold%Valve(64)%AdjacentTo(111)
  338. call Manifold%Valve(65)%AdjacentTo(120)
  339. call Manifold%Valve(66)%AdjacentTo(120)
  340. call Manifold%Valve(67)%AdjacentTo(73)
  341. call Manifold%Valve(68)%AdjacentTo(125)
  342. call Manifold%Valve(68)%AdjacentTo(126)
  343. call Manifold%Valve(69)%AdjacentTo(48)
  344. call Manifold%Valve(69)%AdjacentTo(124)
  345. !call Valve(70)%AdjacentTo()
  346. !call Valve(70)%AdjacentTo()
  347. call Manifold%Valve(71)%AdjacentTo(20)
  348. call Manifold%Valve(71)%AdjacentTo(44)
  349. call Manifold%Valve(71)%AdjacentTo(59)
  350. call Manifold%Valve(72)%AdjacentTo(21)
  351. call Manifold%Valve(72)%AdjacentTo(23)
  352. call Manifold%Valve(73)%AdjacentTo(22)
  353. call Manifold%Valve(74)%AdjacentTo(24)
  354. !call Valve(75)%AdjacentTo()
  355. !call Valve(76)%AdjacentTo()
  356. call Manifold%Valve(77)%AdjacentTo(43)
  357. call Manifold%Valve(77)%AdjacentTo(58)
  358. !call Valve(78)%AdjacentTo()
  359. call Manifold%Valve(79)%AdjacentTo(48)
  360. call Manifold%Valve(79)%AdjacentTo(49)
  361. call Manifold%Valve(80)%AdjacentTo(52)
  362. call Manifold%Valve(80)%AdjacentTo(107)
  363. call Manifold%Valve(81)%AdjacentTo(53)
  364. call Manifold%Valve(82)%AdjacentTo(16)
  365. call Manifold%Valve(83)%AdjacentTo(17)
  366. call Manifold%Valve(84)%AdjacentTo(18)
  367. !call Valve(85)%AdjacentTo()
  368. !call Valve(86)%AdjacentTo()
  369. !call Valve(87)%AdjacentTo()
  370. !call Valve(88)%AdjacentTo()
  371. !!call Valve(89)%AdjacentTo()
  372. !call Valve(90)%AdjacentTo()
  373. call Manifold%Valve(91)%AdjacentTo(6)
  374. call Manifold%Valve(91)%AdjacentTo(9)
  375. call Manifold%Valve(91)%AdjacentTo(75)
  376. call Manifold%Valve(92)%AdjacentTo(6)
  377. call Manifold%Valve(92)%AdjacentTo(7)
  378. call Manifold%Valve(92)%AdjacentTo(2)
  379. call Manifold%Valve(93)%AdjacentTo(3)
  380. call Manifold%Valve(93)%AdjacentTo(7)
  381. call Manifold%Valve(93)%AdjacentTo(8)
  382. call Manifold%Valve(94)%AdjacentTo(8)
  383. call Manifold%Valve(94)%AdjacentTo(10)
  384. call Manifold%Valve(94)%AdjacentTo(95)
  385. call Manifold%Valve(95)%AdjacentTo(76)
  386. call Manifold%Valve(95)%AdjacentTo(94)
  387. call Manifold%Valve(96)%AdjacentTo(9)
  388. call Manifold%Valve(96)%AdjacentTo(11)
  389. call Manifold%Valve(96)%AdjacentTo(13)
  390. call Manifold%Valve(97)%AdjacentTo(11)
  391. call Manifold%Valve(97)%AdjacentTo(12)
  392. call Manifold%Valve(97)%AdjacentTo(14)
  393. call Manifold%Valve(98)%AdjacentTo(10)
  394. call Manifold%Valve(98)%AdjacentTo(12)
  395. call Manifold%Valve(98)%AdjacentTo(15)
  396. call Manifold%Valve(99)%AdjacentTo(13)
  397. call Manifold%Valve(99)%AdjacentTo(15)
  398. call Manifold%Valve(99)%AdjacentTo(125)
  399. !call Valve(100)%AdjacentTo(16)
  400. call Manifold%Valve(100)%AdjacentTo(82)
  401. call Manifold%Valve(100)%AdjacentTo(101)
  402. !call Valve(101)%AdjacentTo(17)
  403. call Manifold%Valve(101)%AdjacentTo(19)
  404. call Manifold%Valve(101)%AdjacentTo(83)
  405. call Manifold%Valve(101)%AdjacentTo(100)
  406. !call Valve(102)%AdjacentTo(18)
  407. call Manifold%Valve(102)%AdjacentTo(19)
  408. call Manifold%Valve(102)%AdjacentTo(84)
  409. !call Valve(103)%AdjacentTo(53)
  410. !call Valve(103)%AdjacentTo(56)
  411. call Manifold%Valve(103)%AdjacentTo(124)
  412. !call Valve(103)%AdjacentTo(56)
  413. !call Valve(103)%AdjacentTo(78)
  414. call Manifold%Valve(104)%AdjacentTo(46)
  415. call Manifold%Valve(104)%AdjacentTo(47)
  416. call Manifold%Valve(104)%AdjacentTo(49)
  417. call Manifold%Valve(104)%AdjacentTo(50)
  418. !call Valve(105)%AdjacentTo(53)
  419. !call Valve(105)%AdjacentTo(107)
  420. !call Valve(105)%AdjacentTo(127)
  421. call Manifold%Valve(106)%AdjacentTo(40)
  422. call Manifold%Valve(106)%AdjacentTo(45)
  423. call Manifold%Valve(107)%AdjacentTo(41)
  424. !call Valve(107)%AdjacentTo(105)
  425. call Manifold%Valve(107)%AdjacentTo(119)
  426. !call Valve(107)%AdjacentTo(42)
  427. call Manifold%Valve(108)%AdjacentTo(25)
  428. call Manifold%Valve(108)%AdjacentTo(27)
  429. call Manifold%Valve(108)%AdjacentTo(28)
  430. call Manifold%Valve(108)%AdjacentTo(110)
  431. call Manifold%Valve(109)%AdjacentTo(26)
  432. call Manifold%Valve(109)%AdjacentTo(30)
  433. call Manifold%Valve(109)%AdjacentTo(31)
  434. call Manifold%Valve(109)%AdjacentTo(110)
  435. call Manifold%Valve(110)%AdjacentTo(29)
  436. call Manifold%Valve(110)%AdjacentTo(85)
  437. call Manifold%Valve(110)%AdjacentTo(108)
  438. call Manifold%Valve(110)%AdjacentTo(109)
  439. call Manifold%Valve(111)%AdjacentTo(37)
  440. call Manifold%Valve(111)%AdjacentTo(64)
  441. call Manifold%Valve(111)%AdjacentTo(112)
  442. call Manifold%Valve(112)%AdjacentTo(63)
  443. call Manifold%Valve(112)%AdjacentTo(111)
  444. call Manifold%Valve(112)%AdjacentTo(113)
  445. call Manifold%Valve(113)%AdjacentTo(29)
  446. call Manifold%Valve(113)%AdjacentTo(112)
  447. call Manifold%Valve(113)%AdjacentTo(114)
  448. call Manifold%Valve(114)%AdjacentTo(62)
  449. call Manifold%Valve(114)%AdjacentTo(113)
  450. call Manifold%Valve(114)%AdjacentTo(115)
  451. call Manifold%Valve(115)%AdjacentTo(36)
  452. call Manifold%Valve(115)%AdjacentTo(61)
  453. call Manifold%Valve(115)%AdjacentTo(114)
  454. call Manifold%Valve(116)%AdjacentTo(38)
  455. call Manifold%Valve(116)%AdjacentTo(39)
  456. call Manifold%Valve(117)%AdjacentTo(2)
  457. call Manifold%Valve(117)%AdjacentTo(26)
  458. call Manifold%Valve(117)%AdjacentTo(47)
  459. call Manifold%Valve(118)%AdjacentTo(3)
  460. call Manifold%Valve(118)%AdjacentTo(25)
  461. call Manifold%Valve(118)%AdjacentTo(46)
  462. call Manifold%Valve(119)%AdjacentTo(42)
  463. call Manifold%Valve(119)%AdjacentTo(60)
  464. call Manifold%Valve(119)%AdjacentTo(107)
  465. call Manifold%Valve(120)%AdjacentTo(71)
  466. !call Valve(121)%AdjacentTo(16)
  467. call Manifold%Valve(121)%AdjacentTo(1)
  468. call Manifold%Valve(121)%AdjacentTo(65)
  469. !call Valve(122)%AdjacentTo(17)
  470. call Manifold%Valve(122)%AdjacentTo(4)
  471. call Manifold%Valve(122)%AdjacentTo(66)
  472. !call Valve(123)%AdjacentTo(18)
  473. call Manifold%Valve(123)%AdjacentTo(5)
  474. call Manifold%Valve(123)%AdjacentTo(67)
  475. !call Valve(124)%AdjacentTo(54)
  476. !call Valve(124)%AdjacentTo(55)
  477. call Manifold%Valve(124)%AdjacentTo(69)
  478. call Manifold%Valve(124)%AdjacentTo(103)
  479. call Manifold%Valve(125)%AdjacentTo(68)
  480. call Manifold%Valve(125)%AdjacentTo(99)
  481. ! call Valve(125)%AdjacentTo(126)
  482. call Manifold%Valve(126)%AdjacentTo(128)
  483. call Manifold%Valve(126)%AdjacentTo(68)
  484. !call Valve(126)%AdjacentTo(125)
  485. call Manifold%Valve(127)%AdjacentTo(56)
  486. call Manifold%Valve(127)%AdjacentTo(78)
  487. !call Valve(127)%AdjacentTo(105)
  488. call Manifold%Valve(128)%AdjacentTo(56)
  489. call Manifold%Valve(128)%AdjacentTo(126)
  490. ! initialization
  491. call ChangeValve(60, .true.)
  492. call RemoveIBop()
  493. call ToggleFillupHead(.false.)
  494. call ToggleMudBox(.false.)
  495. call RemoveTopDriveIBop()
  496. call InstallSafetyValve_KellyMode()
  497. call KellyDisconnected()
  498. end subroutine
  499. subroutine KellyConnected()
  500. !use CLog3
  501. implicit none
  502. call Manifold%Valve(127)%RemoveAdjacent(78)
  503. call Manifold%Valve(127)%AdjacentTo(103)
  504. call Manifold%Valve(103)%AdjacentTo(127)
  505. # 711
  506. Manifold%IsPathsDirty = .true.
  507. end subroutine
  508. subroutine KellyDisconnected()
  509. !use CLog3
  510. implicit none
  511. call Manifold%Valve(127)%RemoveAdjacent(103)
  512. call Manifold%Valve(103)%RemoveAdjacent(127)
  513. call Manifold%Valve(127)%AdjacentTo(78)
  514. # 727
  515. Manifold%IsPathsDirty = .true.
  516. end subroutine
  517. subroutine InstallSafetyValve_KellyMode()
  518. implicit none
  519. Manifold%IsSafetyValveInstalled_KellyMode = .true.
  520. call RemoveTopDriveIBop()
  521. ! Remove Safey Valve (54)
  522. call Manifold%Valve(124)%RemoveAdjacent(54)
  523. call Manifold%Valve(54)%RemoveAdjacent(124)
  524. call Manifold%Valve(69)%RemoveAdjacent(54)
  525. call Manifold%Valve(54)%RemoveAdjacent(69)
  526. ! Remove 126-103 cnn
  527. call Manifold%Valve(128)%RemoveAdjacent(127)
  528. call Manifold%Valve(127)%RemoveAdjacent(128)
  529. ! now make cnn
  530. call Manifold%Valve(124)%AdjacentTo(69)
  531. call Manifold%Valve(69)%AdjacentTo(124)
  532. call Manifold%Valve(128)%AdjacentTo(56)
  533. call Manifold%Valve(56)%AdjacentTo(128)
  534. call Manifold%Valve(56)%AdjacentTo(127)
  535. call Manifold%Valve(127)%AdjacentTo(56)
  536. # 771
  537. data%Equipments%DrillingConsole%IRSafetyValveLed = 1
  538. call OpenSafetyValve_KellyMode()
  539. end subroutine
  540. subroutine RemoveSafetyValve_KellyMode()
  541. implicit none
  542. Manifold%IsSafetyValveInstalled_KellyMode = .false.
  543. call Manifold%Valve(128)%RemoveAdjacent(56)
  544. call Manifold%Valve(56)%RemoveAdjacent(128)
  545. call Manifold%Valve(127)%RemoveAdjacent(56)
  546. call Manifold%Valve(56)%RemoveAdjacent(127)
  547. call Manifold%Valve(127)%AdjacentTo(128)
  548. call Manifold%Valve(128)%AdjacentTo(127)
  549. data%Equipments%DrillingConsole%IRSafetyValveLed = 0
  550. call CloseSafetyValve_KellyMode()
  551. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  552. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  553. # 797
  554. end subroutine
  555. subroutine OpenSafetyValve_KellyMode()
  556. implicit none
  557. if(.not.Manifold%IsSafetyValveInstalled_KellyMode) return
  558. data%Equipments%DrillingConsole%OpenSafetyValveLed = 1
  559. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  560. Manifold%SafetyValve = .true.
  561. call ChangeValve(56, Manifold%SafetyValve)
  562. # 811
  563. end subroutine
  564. subroutine CloseSafetyValve_KellyMode()
  565. implicit none
  566. if(.not.Manifold%IsSafetyValveInstalled_KellyMode) return
  567. data%Equipments%DrillingConsole%CloseSafetyValveLed = 1
  568. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  569. Manifold%SafetyValve = .false.
  570. call ChangeValve(56, Manifold%SafetyValve)
  571. # 825
  572. end subroutine
  573. subroutine InstallSafetyValve_TripMode()
  574. implicit none
  575. Manifold%IsSafetyValveInstalled_TripMode = .true.
  576. call Manifold%Valve(128)%RemoveAdjacent(56)
  577. call Manifold%Valve(56)%RemoveAdjacent(128)
  578. call Manifold%Valve(127)%RemoveAdjacent(56)
  579. call Manifold%Valve(56)%RemoveAdjacent(127)
  580. call Manifold%Valve(69)%RemoveAdjacent(124)
  581. call Manifold%Valve(124)%RemoveAdjacent(69)
  582. call Manifold%Valve(127)%AdjacentTo(128)
  583. call Manifold%Valve(128)%AdjacentTo(127)
  584. call Manifold%Valve(124)%AdjacentTo(54)
  585. call Manifold%Valve(54)%AdjacentTo(124)
  586. call Manifold%Valve(54)%AdjacentTo(69)
  587. call Manifold%Valve(69)%AdjacentTo(54)
  588. data%Equipments%DrillingConsole%IRSafetyValveLed = 1
  589. call OpenSafetyValve_TripMode()
  590. # 866
  591. end subroutine
  592. subroutine RemoveSafetyValve_TripMode()
  593. implicit none
  594. Manifold%IsSafetyValveInstalled_TripMode = .false.
  595. call Manifold%Valve(124)%RemoveAdjacent(54)
  596. call Manifold%Valve(54)%RemoveAdjacent(124)
  597. call Manifold%Valve(54)%RemoveAdjacent(69)
  598. call Manifold%Valve(69)%RemoveAdjacent(54)
  599. call Manifold%Valve(124)%AdjacentTo(69)
  600. call Manifold%Valve(69)%AdjacentTo(124)
  601. data%Equipments%DrillingConsole%IRSafetyValveLed = 0
  602. call CloseSafetyValve_TripMode()
  603. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  604. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  605. # 890
  606. end subroutine
  607. subroutine OpenSafetyValve_TripMode()
  608. implicit none
  609. if(.not.Manifold%IsSafetyValveInstalled_TripMode) return
  610. data%Equipments%DrillingConsole%OpenSafetyValveLed = 1
  611. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  612. Manifold%SafetyValve = .true.
  613. call ChangeValve(54, Manifold%SafetyValve)
  614. # 904
  615. end subroutine
  616. subroutine CloseSafetyValve_TripMode()
  617. implicit none
  618. if(.not.Manifold%IsSafetyValveInstalled_TripMode) return
  619. data%Equipments%DrillingConsole%CloseSafetyValveLed = 1
  620. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  621. Manifold%SafetyValve = .false.
  622. call ChangeValve(54, Manifold%SafetyValve)
  623. # 918
  624. end subroutine
  625. subroutine InstallSafetyValve_TopDrive()
  626. implicit none
  627. Manifold%IsSafetyValveInstalled_TopDrive = .true.
  628. call Manifold%Valve(128)%RemoveAdjacent(56)
  629. call Manifold%Valve(56)%RemoveAdjacent(128)
  630. call Manifold%Valve(127)%RemoveAdjacent(56)
  631. call Manifold%Valve(56)%RemoveAdjacent(127)
  632. call Manifold%Valve(69)%RemoveAdjacent(124)
  633. call Manifold%Valve(124)%RemoveAdjacent(69)
  634. call Manifold%Valve(124)%AdjacentTo(54)
  635. call Manifold%Valve(54)%AdjacentTo(124)
  636. call Manifold%Valve(54)%AdjacentTo(69)
  637. call Manifold%Valve(69)%AdjacentTo(54)
  638. data%Equipments%DrillingConsole%IRSafetyValveLed = 1
  639. call OpenSafetyValve_TopDrive()
  640. # 953
  641. end subroutine
  642. subroutine RemoveSafetyValve_TopDrive()
  643. implicit none
  644. Manifold%IsSafetyValveInstalled_TopDrive = .false.
  645. call Manifold%Valve(124)%RemoveAdjacent(54)
  646. call Manifold%Valve(54)%RemoveAdjacent(124)
  647. call Manifold%Valve(54)%RemoveAdjacent(69)
  648. call Manifold%Valve(69)%RemoveAdjacent(54)
  649. call Manifold%Valve(124)%AdjacentTo(69)
  650. call Manifold%Valve(69)%AdjacentTo(124)
  651. data%Equipments%DrillingConsole%IRSafetyValveLed = 0
  652. call CloseSafetyValve_TopDrive()
  653. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  654. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  655. # 977
  656. end subroutine
  657. subroutine OpenSafetyValve_TopDrive()
  658. implicit none
  659. if(.not.Manifold%IsSafetyValveInstalled_TopDrive) return
  660. data%Equipments%DrillingConsole%OpenSafetyValveLed = 1
  661. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  662. Manifold%SafetyValve = .true.
  663. # 990
  664. call ChangeValve(54, Manifold%SafetyValve)
  665. end subroutine
  666. subroutine CloseSafetyValve_TopDrive()
  667. implicit none
  668. if(.not.Manifold%IsSafetyValveInstalled_TopDrive) return
  669. data%Equipments%DrillingConsole%CloseSafetyValveLed = 1
  670. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  671. Manifold%SafetyValve = .false.
  672. # 1004
  673. call ChangeValve(54, Manifold%SafetyValve)
  674. end subroutine
  675. subroutine InstallIBop()
  676. implicit none
  677. Manifold%IsIBopInstalled = .true.
  678. call Manifold%Valve(103)%RemoveAdjacent(124)
  679. call Manifold%Valve(124)%RemoveAdjacent(103)
  680. call Manifold%Valve(55)%AdjacentTo(103)
  681. call Manifold%Valve(55)%AdjacentTo(124)
  682. call Manifold%Valve(103)%AdjacentTo(55)
  683. call Manifold%Valve(124)%AdjacentTo(55)
  684. # 1032
  685. data%Equipments%DrillingConsole%IRIBopLed = 1
  686. call OpenIBop()
  687. end subroutine
  688. subroutine RemoveIBop()
  689. implicit none
  690. Manifold%IsIBopInstalled = .false.
  691. call Manifold%Valve(55)%RemoveAdjacent(103)
  692. call Manifold%Valve(55)%RemoveAdjacent(124)
  693. call Manifold%Valve(103)%RemoveAdjacent(55)
  694. call Manifold%Valve(124)%RemoveAdjacent(55)
  695. call Manifold%Valve(103)%AdjacentTo(124)
  696. call Manifold%Valve(124)%AdjacentTo(103)
  697. # 1053
  698. data%Equipments%DrillingConsole%IRIBopLed = 0
  699. Manifold%IBop = .false.
  700. call ChangeValve(55, Manifold%IBop)
  701. end subroutine
  702. subroutine OpenIBop()
  703. implicit none
  704. if(.not.Manifold%IsIBopInstalled) return
  705. Manifold%IBop = .true.
  706. # 1067
  707. call ChangeValve(55, Manifold%IBop)
  708. end subroutine
  709. subroutine CloseIBop()
  710. implicit none
  711. if(.not.Manifold%IsIBopInstalled) return
  712. Manifold%IBop = .false.
  713. # 1079
  714. call ChangeValve(55, Manifold%IBop)
  715. end subroutine
  716. subroutine InstallKellyCock()
  717. implicit none
  718. Manifold%IsKellyCockInstalled = .true.
  719. call Manifold%Valve(125)%RemoveAdjacent(126)
  720. call Manifold%Valve(126)%RemoveAdjacent(125)
  721. call Manifold%Valve(125)%AdjacentTo(68)
  722. call Manifold%Valve(68)%AdjacentTo(125)
  723. call Manifold%Valve(68)%AdjacentTo(126)
  724. call Manifold%Valve(126)%AdjacentTo(68)
  725. # 1105
  726. call OpenKellyCock()
  727. end subroutine
  728. subroutine RemoveKellyCock()
  729. implicit none
  730. Manifold%IsKellyCockInstalled = .false.
  731. call Manifold%Valve(125)%RemoveAdjacent(68)
  732. call Manifold%Valve(126)%RemoveAdjacent(68)
  733. call Manifold%Valve(68)%RemoveAdjacent(125)
  734. call Manifold%Valve(68)%RemoveAdjacent(126)
  735. call Manifold%Valve(125)%AdjacentTo(126)
  736. call Manifold%Valve(126)%AdjacentTo(125)
  737. Manifold%KellyCock = .false.
  738. call ChangeValve(68, Manifold%KellyCock)
  739. data%Equipments%DrillingConsole%CloseKellyCockLed = 0
  740. data%Equipments%DrillingConsole%OpenKellyCockLed = 0
  741. # 1130
  742. end subroutine
  743. subroutine OpenKellyCock()
  744. implicit none
  745. if(.not.Manifold%IsKellyCockInstalled) return
  746. data%Equipments%DrillingConsole%OpenKellyCockLed = 1
  747. data%Equipments%DrillingConsole%CloseKellyCockLed = 0
  748. Manifold%KellyCock = .true.
  749. # 1143
  750. call ChangeValve(68, Manifold%KellyCock)
  751. end subroutine
  752. subroutine CloseKellyCock()
  753. implicit none
  754. if(.not.Manifold%IsKellyCockInstalled) return
  755. data%Equipments%DrillingConsole%CloseKellyCockLed = 1
  756. data%Equipments%DrillingConsole%OpenKellyCockLed = 0
  757. Manifold%KellyCock = .false.
  758. # 1157
  759. call ChangeValve(68, Manifold%KellyCock)
  760. end subroutine
  761. subroutine InstallTopDriveIBop()
  762. implicit none
  763. Manifold%IsTopDriveIBopInstalled = .true.
  764. call Manifold%Valve(126)%RemoveAdjacent(128)
  765. call Manifold%Valve(128)%RemoveAdjacent(126)
  766. call Manifold%Valve(126)%AdjacentTo(70)
  767. call Manifold%Valve(70)%AdjacentTo(126)
  768. call Manifold%Valve(128)%AdjacentTo(70)
  769. call Manifold%Valve(70)%AdjacentTo(128)
  770. # 1185
  771. call OpenTopDriveIBop()
  772. end subroutine
  773. subroutine RemoveTopDriveIBop()
  774. implicit none
  775. Manifold%IsTopDriveIBopInstalled = .false.
  776. call Manifold%Valve(126)%RemoveAdjacent(70)
  777. call Manifold%Valve(70)%RemoveAdjacent(126)
  778. call Manifold%Valve(128)%RemoveAdjacent(70)
  779. call Manifold%Valve(70)%RemoveAdjacent(128)
  780. call Manifold%Valve(126)%AdjacentTo(128)
  781. call Manifold%Valve(128)%AdjacentTo(126)
  782. # 1204
  783. Manifold%TopDriveIBop = .false.
  784. call ChangeValve(70, Manifold%TopDriveIBop)
  785. end subroutine
  786. subroutine OpenTopDriveIBop()
  787. implicit none
  788. if(.not.Manifold%IsTopDriveIBopInstalled) return
  789. Manifold%TopDriveIBop = .true.
  790. call ChangeValve(70, Manifold%TopDriveIBop)
  791. # 1216
  792. end subroutine
  793. subroutine CloseTopDriveIBop()
  794. implicit none
  795. if(.not.Manifold%IsTopDriveIBopInstalled) return
  796. Manifold%TopDriveIBop = .false.
  797. call ChangeValve(70, Manifold%TopDriveIBop)
  798. # 1226
  799. end subroutine
  800. subroutine InstallFloatValve()
  801. implicit none
  802. Manifold%IsFloatValveInstalled = .true.
  803. call Manifold%Valve(69)%RemoveAdjacent(79)
  804. call Manifold%Valve(79)%RemoveAdjacent(69)
  805. call Manifold%Valve(48)%AdjacentTo(69)
  806. call Manifold%Valve(48)%AdjacentTo(79)
  807. call Manifold%Valve(69)%AdjacentTo(48)
  808. call Manifold%Valve(79)%AdjacentTo(48)
  809. # 1251
  810. call OpenFloatValve()
  811. end subroutine
  812. subroutine RemoveFloatValve()
  813. implicit none
  814. Manifold%IsFloatValveInstalled = .false.
  815. call Manifold%Valve(48)%RemoveAdjacent(69)
  816. call Manifold%Valve(48)%RemoveAdjacent(79)
  817. call Manifold%Valve(69)%RemoveAdjacent(48)
  818. call Manifold%Valve(79)%RemoveAdjacent(48)
  819. call Manifold%Valve(69)%AdjacentTo(79)
  820. call Manifold%Valve(79)%AdjacentTo(69)
  821. # 1269
  822. Manifold%FloatValve = .false.
  823. call ChangeValve(48, Manifold%FloatValve)
  824. end subroutine
  825. subroutine OpenFloatValve()
  826. implicit none
  827. if(.not.Manifold%IsFloatValveInstalled) return
  828. Manifold%FloatValve = .true.
  829. # 1280
  830. call ChangeValve(48, Manifold%FloatValve)
  831. end subroutine
  832. subroutine CloseFloatValve()
  833. implicit none
  834. if(.not.Manifold%IsFloatValveInstalled) return
  835. Manifold%FloatValve = .false.
  836. # 1290
  837. call ChangeValve(48, Manifold%FloatValve)
  838. end subroutine
  839. subroutine ToggleFillupHead(v)
  840. implicit none
  841. logical, intent(in) :: v
  842. if(v) then
  843. call Manifold%Valve(14)%RemoveAdjacent(78)
  844. call Manifold%Valve(14)%AdjacentTo(57)
  845. call Manifold%Valve(57)%AdjacentTo(14)
  846. call Manifold%Valve(57)%AdjacentTo(103)
  847. call Manifold%Valve(103)%AdjacentTo(57)
  848. else
  849. call Manifold%Valve(14)%RemoveAdjacent(57)
  850. call Manifold%Valve(57)%RemoveAdjacent(14)
  851. call Manifold%Valve(57)%RemoveAdjacent(103)
  852. call Manifold%Valve(103)%RemoveAdjacent(57)
  853. call Manifold%Valve(14)%AdjacentTo(78)
  854. endif
  855. Manifold%IsPathsDirty = .true.
  856. call ChangeValve(57, .true.)
  857. end subroutine
  858. subroutine ToggleMudBox(v)
  859. implicit none
  860. logical, intent(in) :: v
  861. call ChangeValve(53, v)
  862. end subroutine
  863. subroutine ToggleMiddleRams(v)
  864. implicit none
  865. logical, intent(in) :: v
  866. Manifold%Valve(50)%Status = v
  867. call ChangeValve(69, v)
  868. end subroutine
  869. subroutine ChangeValve(i, state)
  870. implicit none
  871. integer, intent(in) :: i
  872. logical, intent(in) :: state
  873. if(Manifold%Valve(i)%Status==state) return
  874. Manifold%Valve(i)%Status = state
  875. if(i == 41 .or. i == 42) then
  876. if(Manifold%Valve(41)%Status == .false. .and. Manifold%Valve(42)%Status == .false.) then
  877. Manifold%Valve(60)%Status = .true.
  878. else
  879. Manifold%Valve(60)%Status = .false.
  880. endif
  881. endif
  882. # 1367
  883. !call Traverse()
  884. Manifold%IsPathsDirty = .true.
  885. end subroutine
  886. subroutine DisplayOpenPaths()
  887. implicit none
  888. integer :: i
  889. if(allocated(Manifold%OpenPaths)) then
  890. do i = 1, size(Manifold%OpenPaths)
  891. call Manifold%OpenPaths(i)%Display()
  892. end do
  893. end if
  894. end subroutine
  895. subroutine DisplayOpenPathsWrite()
  896. implicit none
  897. integer :: i
  898. if(allocated(Manifold%OpenPaths)) then
  899. do i = 1, size(Manifold%OpenPaths)
  900. call Manifold%OpenPaths(i)%DisplayWrite()
  901. end do
  902. end if
  903. end subroutine
  904. end module CManifolds