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
42 KiB

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