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.
 
 
 
 
 
 

1393 lines
40 KiB

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