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.
 
 
 
 
 
 

1396 lines
42 KiB

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