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.
 
 
 
 
 
 

1355 lines
38 KiB

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