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.
 
 
 
 
 
 

1300 lines
42 KiB

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