Simulation Core
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

1270 Zeilen
67 KiB

  1. # 1 "/home/admin/SimulationCore2/Equipments/BopStack/LOSS_INPUTS.f90"
  2. SUBROUTINE DEALLOCATE_ARRAYS()
  3. use SimulationVariables
  4. use UnityModule
  5. implicit none
  6. !===========================================================================
  7. ! RAMLINE MINOR LOSSES INPUT
  8. !===========================================================================
  9. DEALLOCATE (data%State%BopStackInput%MINORS1,data%State%RamLine%MINORDIAMETER_RAMLINE,data%State%RamLine%AREAMINOR_RAMLINE &
  10. ,data%State%RamLine%LF_RAMLINE,data%State%RamLine%CV_RAMLINE,data%State%RamLine%NOTE_RAMLINE,data%State%RAMS%minlosspa,data%State%RAMS%minloss)
  11. !===========================================================================
  12. ! RAMLINE PIPNING LOSSES INPUT
  13. !===========================================================================
  14. DEALLOCATE (data%State%BopStackInput%PIPINGS_RAMLINE,data%State%RamLine%DIAM_RAMLINE_INCH, &
  15. data%State%RamLine%AREA_RAMLINE,data%State%RamLine%LENGT_RAMLINE,data%State%RamLine%ROUGHNESS_RAMLINE,data%State%RamLine%RELROUGH_RAMLINE &
  16. ,data%State%RAMS%Re_ramline,data%State%RAMS%fric,data%State%RAMS%fricloss)
  17. !===========================================================================
  18. ! ANNULAR MINOR LOSSES INPUT
  19. !===========================================================================
  20. DEALLOCATE (data%State%BopStackInput%MINORS_ANNULAR,data%State%AnnularComputational%MINORDIAMETER_ANNULARLINE,data%State%AnnularComputational%AREAMINOR_ANNULARLINE &
  21. ,data%State%AnnularComputational%LF_ANNULARLINE,data%State%AnnularComputational%CV_ANNULARLINE,data%State%AnnularComputational%NOTE_ANNULARLINE,data%State%AnnularComputational%minlosspa_ANNULAR,data%State%AnnularComputational%minloss_ANNULAR)
  22. !===========================================================================
  23. ! ANNULAR PIPNING LOSSES INPUT
  24. !===========================================================================
  25. DEALLOCATE (data%State%BopStackInput%PIPINGS_ANNULAR,data%State%AnnularComputational%DIAM_ANNULARLINE_INCH,data%State%AnnularComputational%AREA_ANNULARLINE, &
  26. data%State%AnnularComputational%LENGT_ANNULARLINE,data%State%AnnularComputational%ROUGHNESS_ANNULARLINE,data%State%AnnularComputational%RELROUGH_ANNULARLINE &
  27. ,data%State%AnnularComputational%Re_ANNULARline,data%State%AnnularComputational%fricANNULAR,data%State%AnnularComputational%friclossANNULAR)
  28. !===========================================================================
  29. ! AIR PUMP LOSSES INPUT
  30. !===========================================================================
  31. DEALLOCATE (data%State%BopStackInput%PIPINGS_AIRPUMP,data%State%RamLine%DIAM_AIR_INCH, &
  32. data%State%RamLine%Re_air,data%State%RamLine%AREA_AIR,data%State%RamLine%LENGT_AIR,data%State%RamLine%ROUGHNESS_AIRPLINE,data%State%RamLine%REL_ROUGHAIR, &
  33. data%State%RamLine%fric_air,data%State%RamLine%fricloss_air)
  34. !================================================================
  35. DEALLOCATE (data%State%BopStackInput%MINORS_AIRPUMP,data%State%RamLine%MINORDIAM_AIR_INCH, &
  36. data%State%RamLine%MINORAREA_AIR,data%State%RamLine%LF_AIR,data%State%RamLine%CV_AIR,data%State%RamLine%NOTE_AIR &
  37. ,data%State%RamLine%minlosspa_air,data%State%RamLine%minloss_air)
  38. !===========================================================================
  39. ! DELAY ARRAYS
  40. !===========================================================================
  41. call data%State%AnnularComputational%Pannular_regDelay%Empty()
  42. END
  43. SUBROUTINE LOSS_INPUTS()
  44. use SimulationVariables
  45. implicit none
  46. INTEGER I
  47. !===========================================================================
  48. ! RAMLINE MINOR LOSSES INPUT
  49. !===========================================================================
  50. data%State%RamLine%NO_MINORSRAMLINE=34
  51. ALLOCATE (data%State%BopStackInput%MINORS1(data%State%RamLine%NO_MINORSRAMLINE,4))
  52. ! ID(INCH) LF CV NOTE(BAR) DESCRIPTION
  53. data%State%BopStackInput%MINORS1(1,1:4)= (/2., 2., 0., 0./) !Acc.tee
  54. data%State%BopStackInput%MINORS1(2,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee
  55. data%State%BopStackInput%MINORS1(3,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee
  56. data%State%BopStackInput%MINORS1(4,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee
  57. data%State%BopStackInput%MINORS1(5,1:4)= (/2., 0.9, 0., 0./) !tee
  58. data%State%BopStackInput%MINORS1(6,1:4)= (/2., 2., 0., 0./) !tee
  59. data%State%BopStackInput%MINORS1(7,1:4)= (/2., 0., 105., 0./) !valve
  60. data%State%BopStackInput%MINORS1(8,1:4)= (/2., 0.9, 0., 0./) !tee
  61. data%State%BopStackInput%MINORS1(9,1:4)= (/2., 0., 105., 0./) !valve
  62. data%State%BopStackInput%MINORS1(10,1:4)= (/2., 0.42, 0., 0./) !elbow
  63. data%State%BopStackInput%MINORS1(11,1:4)= (/2., 0.42, 0., 0./) !elbow
  64. data%State%BopStackInput%MINORS1(12,1:4)= (/2., 0.8, 0., 0./) !unionA
  65. data%State%BopStackInput%MINORS1(13,1:4)= (/2., 0.8, 0., 0./) !unionA
  66. data%State%BopStackInput%MINORS1(14,1:4)= (/2., 1.5, 0., 0./) !elbow
  67. data%State%BopStackInput%MINORS1(15,1:4)= (/2., 0., 425., 0./) !valve
  68. data%State%BopStackInput%MINORS1(16,1:4)= (/2., 2., 0., 0./) !tee
  69. data%State%BopStackInput%MINORS1(17,1:4)= (/0.75, 0., 1.5, 0./) !REGULATOR
  70. data%State%BopStackInput%MINORS1(18,1:4)= (/1., 2., 0., 0./) !tee
  71. data%State%BopStackInput%MINORS1(19,1:4)= (/1., 1.5, 0., 0./) !elbow
  72. data%State%BopStackInput%MINORS1(20,1:4)= (/1., 0.42, 0., 0./) !elbow
  73. data%State%BopStackInput%MINORS1(21,1:4)= (/1., 0.42, 0., 0./) !elbow
  74. data%State%BopStackInput%MINORS1(22,1:4)= (/1., 1.5, 0., 0./) !elbow
  75. data%State%BopStackInput%MINORS1(23,1:4)= (/1., 0., 105., 0./) !valve
  76. data%State%BopStackInput%MINORS1(24,1:4)= (/1., 0.9, 0., 0./) !tee
  77. data%State%BopStackInput%MINORS1(25,1:4)= (/1., 0., 0., 0.5/) !FT
  78. data%State%BopStackInput%MINORS1(26,1:4)= (/1., 0., 0., 3.4/) !filter
  79. data%State%BopStackInput%MINORS1(27,1:4)= (/1., 0., 105., 0./) !valve
  80. data%State%BopStackInput%MINORS1(28,1:4)= (/1., 0.9, 0., 0./) !tee
  81. data%State%BopStackInput%MINORS1(29,1:4)= (/1., 1.5, 0., 0./) !elbow
  82. data%State%BopStackInput%MINORS1(30,1:4)= (/1., 1.5, 0., 0./) !elbow
  83. data%State%BopStackInput%MINORS1(31,1:4)= (/1., 0., 9.2, 0./) !valve
  84. data%State%BopStackInput%MINORS1(32,1:4)= (/1., 0.8, 0., 0./) !unionA
  85. data%State%BopStackInput%MINORS1(33,1:4)= (/1., 0.8, 0., 0./) !unionA
  86. data%State%BopStackInput%MINORS1(34,1:4)= (/0.75, 0.35, 0., 0./) !contraction
  87. ALLOCATE (data%State%RamLine%MINORDIAMETER_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE),data%State%RamLine%AREAMINOR_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE),data%State%RamLine%LF_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE),data%State%RamLine%CV_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE) &
  88. ,data%State%RamLine%NOTE_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE),data%State%RAMS%minlosspa(6,data%State%RamLine%NO_MINORSRAMLINE),data%State%RAMS%minloss(6,data%State%RamLine%NO_MINORSRAMLINE))
  89. DO I=1,data%State%RamLine%NO_MINORSRAMLINE
  90. data%State%RamLine%MINORDIAMETER_RAMLINE(I)=data%State%BopStackInput%MINORS1(I,1)
  91. data%State%RamLine%LF_RAMLINE(I)=data%State%BopStackInput%MINORS1(I,2)
  92. data%State%RamLine%CV_RAMLINE(I)=data%State%BopStackInput%MINORS1(I,3)
  93. data%State%RamLine%NOTE_RAMLINE(I)=data%State%BopStackInput%MINORS1(I,4)
  94. data%State%RamLine%AREAMINOR_RAMLINE(I)=PI*(data%State%RamLine%MINORDIAMETER_RAMLINE(I)*0.0254)**2/4. !D(in), AREA(m)
  95. ENDDO
  96. !===========================================================================
  97. ! RAMLINE PIPNING LOSSES INPUT
  98. !===========================================================================
  99. data%State%RamLine%NO_PIPINGSRAMLINE=15
  100. ALLOCATE (data%State%BopStackInput%PIPINGS_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE,3))
  101. ! ID(INCH) L(MM) ROUGHNESS(MM)=e DESCRIPTION
  102. data%State%BopStackInput%PIPINGS_RAMLINE(1,1:3)= (/2., 1035., 0.03/) !Avg.acc.distance
  103. data%State%BopStackInput%PIPINGS_RAMLINE(2,1:3)= (/2., 730., 0.03/) !Acc.end.horizontal
  104. data%State%BopStackInput%PIPINGS_RAMLINE(3,1:3)= (/2., 2000., 0.03/) !Acc.end.vertical
  105. data%State%BopStackInput%PIPINGS_RAMLINE(4,1:3)= (/2., 6000., 0.05/) !Hyd.hose
  106. data%State%BopStackInput%PIPINGS_RAMLINE(5,1:3)= (/2., 2370., 0.03/) !Corner.vertical1
  107. data%State%BopStackInput%PIPINGS_RAMLINE(6,1:3)= (/2., 210., 0.03/) !Add.from.bend
  108. data%State%BopStackInput%PIPINGS_RAMLINE(7,1:3)= (/1., 780., 0.03/) !Corner.horizontal1
  109. data%State%BopStackInput%PIPINGS_RAMLINE(8,1:3)= (/1., 780., 0.03/) !Corner.horizontal2
  110. data%State%BopStackInput%PIPINGS_RAMLINE(9,1:3)= (/1., 750., 0.03/) !Extra.length.back
  111. data%State%BopStackInput%PIPINGS_RAMLINE(10,1:3)= (/1., 800., 0.03/) !Corner.horizontal3
  112. data%State%BopStackInput%PIPINGS_RAMLINE(11,1:3)= (/1., 1650., 0.03/) !Corner.vertical2
  113. data%State%BopStackInput%PIPINGS_RAMLINE(12,1:3)= (/1., 340., 0.03/) !12.Valves.horizontal
  114. data%State%BopStackInput%PIPINGS_RAMLINE(13,1:3)= (/1., 1650., 0.03/) !Valves.vertical
  115. data%State%BopStackInput%PIPINGS_RAMLINE(14,1:3)= (/1., 31000., 10./) !Hyd.hose
  116. data%State%BopStackInput%PIPINGS_RAMLINE(15,1:3)= (/1., 526., 0.03/) !Add.from.bend
  117. ALLOCATE (data%State%RamLine%DIAM_RAMLINE_INCH(data%State%RamLine%NO_PIPINGSRAMLINE), &
  118. data%State%RamLine%AREA_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RamLine%LENGT_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RamLine%ROUGHNESS_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RamLine%RELROUGH_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE) &
  119. ,data%State%RAMS%Re_ramline(6,data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RAMS%fric(6,data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RAMS%fricloss(6,data%State%RamLine%NO_PIPINGSRAMLINE))
  120. DO I=1,data%State%RamLine%NO_PIPINGSRAMLINE
  121. data%State%RamLine%DIAM_RAMLINE_INCH(I)=data%State%BopStackInput%PIPINGS_RAMLINE(I,1)
  122. data%State%RamLine%LENGT_RAMLINE(I)=data%State%BopStackInput%PIPINGS_RAMLINE(I,2)
  123. data%State%RamLine%ROUGHNESS_RAMLINE(I)=data%State%BopStackInput%PIPINGS_RAMLINE(I,3)
  124. data%State%RamLine%AREA_RAMLINE(I)=PI*(data%State%RamLine%DIAM_RAMLINE_INCH(I)*0.0254)**2/4 !D(in), AREA(m)
  125. data%State%RamLine%RELROUGH_RAMLINE(I)=data%State%RamLine%ROUGHNESS_RAMLINE(I)/(data%State%RamLine%DIAM_RAMLINE_INCH(I)*25.4) !e/D
  126. !DIAM_RAMLINE_MM(I)=DIAM_RAMLINE_MM(I)*.001 ! (m)
  127. data%State%RamLine%LENGT_RAMLINE(I)=data%State%RamLine%LENGT_RAMLINE(I)*.001 ! (m)
  128. ENDDO
  129. !===========================================================================
  130. ! ANNULAR PREVENTER MINOR LOSSES INPUT
  131. !===========================================================================
  132. data%State%AnnularComputational%NO_MinorsAnnularLine=29
  133. ALLOCATE (data%State%BopStackInput%MINORS_ANNULAR(data%State%AnnularComputational%NO_MinorsAnnularLine,4))
  134. ! ID(INCH) LF CV NOTE(BAR) DESCRIPTION
  135. data%State%BopStackInput%MINORS_ANNULAR(1,1:4)= (/2., 2., 0., 0./) !Acc.tee
  136. data%State%BopStackInput%MINORS_ANNULAR(2,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee
  137. data%State%BopStackInput%MINORS_ANNULAR(3,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee
  138. data%State%BopStackInput%MINORS_ANNULAR(4,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee
  139. data%State%BopStackInput%MINORS_ANNULAR(5,1:4)= (/2., 0.9, 0., 0./) !tee
  140. data%State%BopStackInput%MINORS_ANNULAR(6,1:4)= (/2., 2., 0., 0./) !tee
  141. data%State%BopStackInput%MINORS_ANNULAR(7,1:4)= (/2., 0., 105., 0./) !valve
  142. data%State%BopStackInput%MINORS_ANNULAR(8,1:4)= (/2., 0.9, 0., 0./) !tee
  143. data%State%BopStackInput%MINORS_ANNULAR(9,1:4)= (/2., 0., 105., 0./) !valve
  144. data%State%BopStackInput%MINORS_ANNULAR(10,1:4)= (/2., 0.42, 0., 0./) !elbow
  145. data%State%BopStackInput%MINORS_ANNULAR(11,1:4)= (/2., 0.42, 0., 0./) !elbow
  146. data%State%BopStackInput%MINORS_ANNULAR(12,1:4)= (/2., 0.8, 0., 0./) !unionA
  147. data%State%BopStackInput%MINORS_ANNULAR(13,1:4)= (/2., 0.8, 0., 0./) !unionA
  148. data%State%BopStackInput%MINORS_ANNULAR(14,1:4)= (/2., 1.5, 0., 0./) !elbow
  149. data%State%BopStackInput%MINORS_ANNULAR(15,1:4)= (/2., 0., 425., 0./) !valve
  150. data%State%BopStackInput%MINORS_ANNULAR(16,1:4)= (/2., 2., 0., 0./) !tee
  151. data%State%BopStackInput%MINORS_ANNULAR(17,1:4)= (/0.75, 0., 1.5, 0./) !REGULATOR
  152. data%State%BopStackInput%MINORS_ANNULAR(18,1:4)= (/1., 2., 0., 0./) !tee
  153. data%State%BopStackInput%MINORS_ANNULAR(19,1:4)= (/1., 1.5, 0., 0./) !elbow
  154. data%State%BopStackInput%MINORS_ANNULAR(20,1:4)= (/1., 0.42, 0., 0./) !elbow
  155. data%State%BopStackInput%MINORS_ANNULAR(21,1:4)= (/1., 0.42, 0., 0./) !elbow
  156. data%State%BopStackInput%MINORS_ANNULAR(22,1:4)= (/1., 1.5, 0., 0./) !elbow
  157. data%State%BopStackInput%MINORS_ANNULAR(23,1:4)= (/1., 0., 3.2, 0./) !valve
  158. data%State%BopStackInput%MINORS_ANNULAR(24,1:4)= (/1., 2., 0., 0./) !tee
  159. data%State%BopStackInput%MINORS_ANNULAR(25,1:4)= (/1., 1.5, 0., 0./) !elbow
  160. data%State%BopStackInput%MINORS_ANNULAR(26,1:4)= (/1., 0.42, 0., 0./) !elbow
  161. data%State%BopStackInput%MINORS_ANNULAR(27,1:4)= (/1., 0.42, 0., 0./) !elbow
  162. data%State%BopStackInput%MINORS_ANNULAR(28,1:4)= (/1., 1.5, 0., 0./) !elbow
  163. data%State%BopStackInput%MINORS_ANNULAR(29,1:4)= (/1., 0., 3.2, 0./) !valve
  164. ALLOCATE (data%State%AnnularComputational%MINORDIAMETER_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%AREAMINOR_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%LF_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine) &
  165. ,data%State%AnnularComputational%CV_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%NOTE_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%minlosspa_ANNULAR(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%minloss_ANNULAR(data%State%AnnularComputational%NO_MinorsAnnularLine))
  166. DO I=1,data%State%AnnularComputational%NO_MinorsAnnularLine
  167. data%State%AnnularComputational%MINORDIAMETER_ANNULARLINE(I)=data%State%BopStackInput%MINORS_ANNULAR(I,1)
  168. data%State%AnnularComputational%LF_ANNULARLINE(I)=data%State%BopStackInput%MINORS_ANNULAR(I,2)
  169. data%State%AnnularComputational%CV_ANNULARLINE(I)=data%State%BopStackInput%MINORS_ANNULAR(I,3)
  170. data%State%AnnularComputational%NOTE_ANNULARLINE(I)=data%State%BopStackInput%MINORS_ANNULAR(I,4)
  171. data%State%AnnularComputational%AREAMINOR_ANNULARLINE(I)=PI*(data%State%AnnularComputational%MINORDIAMETER_ANNULARLINE(I)*0.0254)**2/4. !D(in), AREA(m)
  172. ENDDO
  173. !===========================================================================
  174. ! ANNULAR PREVENTER PIPNING LOSSES INPUT
  175. !===========================================================================
  176. data%State%AnnularComputational%NO_PipingsAnnularLine=10
  177. ALLOCATE (data%State%BopStackInput%PIPINGS_ANNULAR(data%State%AnnularComputational%NO_PipingsAnnularLine,3))
  178. ! ID(INCH) L(MM) ROUGHNESS(MM)=e DESCRIPTION
  179. data%State%BopStackInput%PIPINGS_ANNULAR(1,1:3)= (/2., 1035., 0.03/) !Avg.acc.distance
  180. data%State%BopStackInput%PIPINGS_ANNULAR(2,1:3)= (/2., 730., 0.03/) !Acc.endhorizontal
  181. data%State%BopStackInput%PIPINGS_ANNULAR(3,1:3)= (/2., 2000., 0.03/) !Acc.endvertical
  182. data%State%BopStackInput%PIPINGS_ANNULAR(4,1:3)= (/2., 6000., 0.03/) !Hyd.hose
  183. data%State%BopStackInput%PIPINGS_ANNULAR(5,1:3)= (/2., 2370., 0.03/) !Corner.vertical1
  184. data%State%BopStackInput%PIPINGS_ANNULAR(6,1:3)= (/2., 210., 0.03/) !Add.frombend
  185. data%State%BopStackInput%PIPINGS_ANNULAR(7,1:3)= (/2., 1000., 0.03/) !manifold
  186. data%State%BopStackInput%PIPINGS_ANNULAR(8,1:3)= (/1., 46000., 0.03/) !pipe
  187. data%State%BopStackInput%PIPINGS_ANNULAR(9,1:3)= (/2., 1000., 0.03/) !manifold
  188. data%State%BopStackInput%PIPINGS_ANNULAR(10,1:3)= (/1., 46000., 0.03/) !pipe
  189. ALLOCATE (data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%AREA_ANNULARLINE(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%LENGT_ANNULARLINE(data%State%AnnularComputational%NO_PipingsAnnularLine) &
  190. ,data%State%AnnularComputational%ROUGHNESS_ANNULARLINE(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%RELROUGH_ANNULARLINE(data%State%AnnularComputational%NO_PipingsAnnularLine) &
  191. ,data%State%AnnularComputational%Re_ANNULARline(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%fricANNULAR(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%friclossANNULAR(data%State%AnnularComputational%NO_PipingsAnnularLine))
  192. DO I=1,data%State%AnnularComputational%NO_PipingsAnnularLine
  193. data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(I)=data%State%BopStackInput%PIPINGS_ANNULAR(I,1)
  194. data%State%AnnularComputational%LENGT_ANNULARLINE(I)=data%State%BopStackInput%PIPINGS_ANNULAR(I,2)
  195. data%State%AnnularComputational%ROUGHNESS_ANNULARLINE(I)=data%State%BopStackInput%PIPINGS_ANNULAR(I,3)
  196. data%State%AnnularComputational%AREA_ANNULARLINE(I)=PI*(data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(I)*0.0254)**2/4. !D(in), AREA(m)
  197. data%State%AnnularComputational%RELROUGH_ANNULARLINE(I)=data%State%AnnularComputational%ROUGHNESS_ANNULARLINE(I)/(data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(I)*25.4)
  198. !DIAM_ANNULARLINE_MM(I)=DIAM_ANNULARLINE_MM(I)*.001 ! (m)
  199. data%State%AnnularComputational%LENGT_ANNULARLINE(I)=data%State%AnnularComputational%LENGT_ANNULARLINE(I)*.001 ! (m)
  200. ENDDO
  201. !===========================================================================
  202. ! AIR PUMP LOSSES INPUT
  203. !===========================================================================
  204. data%State%RamLine%NO_PIPINGS_AIRPLINE=1
  205. ALLOCATE (data%State%BopStackInput%PIPINGS_AIRPUMP(data%State%RamLine%NO_PIPINGS_AIRPLINE,3))
  206. ! ID(INCH) L(MM) ROUGHNESS(MM)=e DESCRIPTION
  207. data%State%BopStackInput%PIPINGS_AIRPUMP(1,1:3)= (/2., 10000., 0.03/) !Avg.acc.distance
  208. ALLOCATE (data%State%RamLine%DIAM_AIR_INCH(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%Re_air(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%AREA_AIR(data%State%RamLine%NO_PIPINGS_AIRPLINE), &
  209. data%State%RamLine%LENGT_AIR(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%ROUGHNESS_AIRPLINE(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%REL_ROUGHAIR(data%State%RamLine%NO_PIPINGS_AIRPLINE), &
  210. data%State%RamLine%fric_air(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%fricloss_air(data%State%RamLine%NO_PIPINGS_AIRPLINE))
  211. DO I=1,data%State%RamLine%NO_PIPINGS_AIRPLINE
  212. data%State%RamLine%DIAM_AIR_INCH(I)=data%State%BopStackInput%PIPINGS_AIRPUMP(I,1)
  213. data%State%RamLine%LENGT_AIR(I)=data%State%BopStackInput%PIPINGS_AIRPUMP(I,2)
  214. data%State%RamLine%ROUGHNESS_AIRPLINE(I)=data%State%BopStackInput%PIPINGS_AIRPUMP(I,3)
  215. data%State%RamLine%AREA_AIR(I)=PI*(data%State%RamLine%DIAM_AIR_INCH(I)*0.0254)**2/4 !D(in), AREA(m)
  216. data%State%RamLine%REL_ROUGHAIR(I)=data%State%RamLine%ROUGHNESS_AIRPLINE(I)/(data%State%RamLine%DIAM_AIR_INCH(I)*25.4)
  217. !DIAM_RAMLINE_MM(I)=DIAM_RAMLINE_MM(I)*.001 ! (m)
  218. data%State%RamLine%LENGT_AIR(I)=data%State%RamLine%LENGT_AIR(I)*.001 ! (m)
  219. ENDDO
  220. !================================================================
  221. data%State%RamLine%NO_MINORS_AIRPLINE=6
  222. ALLOCATE (data%State%BopStackInput%MINORS_AIRPUMP(data%State%RamLine%NO_MINORS_AIRPLINE,4))
  223. ! ID(INCH) LF CV NOTE(BAR) DESCRIPTION
  224. data%State%BopStackInput%MINORS_AIRPUMP(1,1:4)= (/2., 10., 0., 0./) !Acc.tee
  225. data%State%BopStackInput%MINORS_AIRPUMP(2,1:4)= (/2., 11., 0., 0./) !elbow
  226. data%State%BopStackInput%MINORS_AIRPUMP(3,1:4)= (/1., 0., 0., 3.4/) !filter
  227. data%State%BopStackInput%MINORS_AIRPUMP(4,1:4)= (/2., 0., 105., 0./) !valve
  228. data%State%BopStackInput%MINORS_AIRPUMP(5,1:4)= (/1., 0., 9.2, 0./) !valve
  229. data%State%BopStackInput%MINORS_AIRPUMP(6,1:4)= (/2., 6.4, 0., 0./) !unionA
  230. ALLOCATE (data%State%RamLine%MINORDIAM_AIR_INCH(data%State%RamLine%NO_MINORS_AIRPLINE),data%State%RamLine%MINORAREA_AIR(data%State%RamLine%NO_MINORS_AIRPLINE), &
  231. data%State%RamLine%LF_AIR(data%State%RamLine%NO_MINORS_AIRPLINE),data%State%RamLine%CV_AIR(data%State%RamLine%NO_MINORS_AIRPLINE),data%State%RamLine%NOTE_AIR(data%State%RamLine%NO_MINORS_AIRPLINE) &
  232. ,data%State%RamLine%minlosspa_air(data%State%RamLine%NO_MINORS_AIRPLINE),data%State%RamLine%minloss_air(data%State%RamLine%NO_MINORS_AIRPLINE))
  233. DO I=1,data%State%RamLine%NO_MINORS_AIRPLINE
  234. data%State%RamLine%MINORDIAM_AIR_INCH(I)=data%State%BopStackInput%MINORS_AIRPUMP(I,1)
  235. data%State%RamLine%LF_AIR(I)=data%State%BopStackInput%MINORS_AIRPUMP(I,2)
  236. data%State%RamLine%CV_AIR(I)=data%State%BopStackInput%MINORS_AIRPUMP(I,3)
  237. data%State%RamLine%NOTE_AIR(I)=data%State%BopStackInput%MINORS_AIRPUMP(I,4)
  238. data%State%RamLine%MINORAREA_AIR(I)=PI*(data%State%RamLine%MINORDIAM_AIR_INCH(I)*0.0254)**2/4. !D(in), AREA(m)
  239. ENDDO
  240. END
  241. SUBROUTINE pumps_charge_bottle()
  242. use SimulationVariables
  243. USE CAccumulatorVariables
  244. USE CBopStackVariables
  245. use CBopControlPanel
  246. use SimulationVariables
  247. USE CEquipmentsConstants
  248. ! use CSimulationVariables
  249. implicit none
  250. !Pannular_regset=min(AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously
  251. !write(*,*) 'pumps_charge_bottle'
  252. if(data%Equipments%BopControlPanel%ByePassValve == -1.0) then
  253. data%State%BopStackAcc%ByPassOld= -1.0
  254. elseif(data%Equipments%BopControlPanel%ByePassValve == 1.0) then
  255. data%State%BopStackAcc%ByPassOld= 1.0
  256. endif
  257. !=====================================================================
  258. ! ACCUMULATOR
  259. !=====for a 10 gal bottle,precharge=1000psig curve BOSCH-isotherm=====
  260. !for charging bottles by the pump
  261. !((((((((IN OUTER LOOP))))))
  262. ! ba1=1003; ba2=.03375; ba3=4.014; ba4=.2458;
  263. if (data%State%RamLine%AIRP_SWITCH==0) data%State%Pumps%DELTAV_AIR=0
  264. data%State%RamLine%FVR=data%State%RamLine%FVR+data%State%Pumps%DELTAV_AIR+data%State%Pumps%DELTAV_ELECP
  265. data%State%RamLine%pacc_before=data%State%RamLine%P_ACC
  266. data%State%RamLine%P_ACC=data%State%RamLine%B1*exp(data%State%RamLine%B2*data%State%RamLine%FVR/data%State%BopStackAcc%NOBOTTLES)+data%State%RamLine%B3*exp(data%State%RamLine%B4*data%State%RamLine%FVR/data%State%BopStackAcc%NOBOTTLES) ! adiabatic(psig)<<<< 8=no. of bottles
  267. !=====================================================================
  268. if(data%State%BopStackAcc%ByPassOld == 1.0) then
  269. if (data%State%BopStackAcc%pram_reg<data%State%BopStackAcc%PRAMS_REGSET) then
  270. !pram_reg=pram_reg+(p_acc-pacc_before)
  271. data%State%BopStackAcc%PressureDifference= (data%State%RamLine%P_ACC-data%State%RamLine%pacc_before)
  272. else
  273. !pram_reg=PRAMS_REGSET
  274. data%State%BopStackAcc%PressureDifference= data%State%BopStackAcc%PRAMS_REGSET - data%State%BopStackAcc%pram_reg
  275. endif
  276. !old=pram_reg
  277. !difference= new-old
  278. if (ABS(data%State%BopStackAcc%PressureDifference) > BaseDifferenceP) then
  279. data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20.
  280. else
  281. if (data%State%BopStackAcc%pram_reg<data%State%BopStackAcc%PRAMS_REGSET) then
  282. data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+(data%State%RamLine%P_ACC-data%State%RamLine%pacc_before)
  283. else
  284. data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%PRAMS_REGSET
  285. endif
  286. endif
  287. else !if(ByPassOld == -1.0) then
  288. !old=pram_reg
  289. !new=p_acc- MAXVAL(data%State%RAM%loss_before)
  290. !difference= new-old
  291. data%State%BopStackAcc%PressureDifference= data%State%RamLine%P_ACC- MAXVAL(data%State%RAM%loss_before) - data%State%BopStackAcc%pram_reg
  292. if (ABS(data%State%BopStackAcc%PressureDifference) > BaseDifferenceP) then
  293. data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20.
  294. else
  295. data%State%BopStackAcc%pram_reg= data%State%RamLine%P_ACC- MAXVAL(data%State%RAM%loss_before)
  296. endif
  297. endif
  298. !Pannular_reg= min(p_acc,Pannular_regset)
  299. end
  300. SUBROUTINE airpump_code()
  301. use SimulationVariables
  302. use CSounds
  303. implicit none
  304. INTEGER I
  305. data%State%Pumps%QAIR=data%State%Pumps%Qiter+.1 !(gpm) maximum flow for the start
  306. data%State%RamLine%diffp_air=-10
  307. data%State%RamLine%losses_air=10
  308. !===================================================================
  309. ! AIR OPERATED PUMP
  310. !=================for air consumption at 8 bar======================
  311. do while (data%State%RamLine%diffp_air<0)
  312. data%State%Pumps%QAIR=data%State%Pumps%QAIR-.1
  313. ! Qup=QAIR_PUMP;
  314. ! bba1 =31.8; bba2 =-725.7 ; bba3 =4154;
  315. data%State%Pumps%P_AIRP=data%State%RamLine%BBA1*data%State%Pumps%QAIR**2+data%State%RamLine%BBA2*data%State%Pumps%QAIR+data%State%RamLine%BBA3 !(psig)
  316. data%State%RamLine%kinetic_air=sg*wdens*(data%State%Pumps%QAIR*6.30902e-5/((1/4.)*pi*(2*0.254e-1)**2))**2/(2*6895) !(psi)
  317. data%State%RamLine%diffp_air=data%State%Pumps%P_AIRP+data%State%RamLine%kinetic_air-data%State%RamLine%P_ACC
  318. end do !returns Qup
  319. do while (abs((data%State%RamLine%diffp_air-data%State%RamLine%losses_air)/data%State%RamLine%diffp_air)>data%State%Pumps%TOL_AIR) !finding correct QAIR_pump for 1 timecounter_ram
  320. if (data%State%RamLine%diffp_air-data%State%RamLine%losses_air>0) then
  321. data%State%Pumps%QAIR=data%State%Pumps%QAIR+.01
  322. else
  323. data%State%Pumps%QAIR=data%State%Pumps%QAIR-.01
  324. endif
  325. !===================================================================
  326. ! AIR OPERATED PUMP
  327. ! Maximator - Model: GX (35)
  328. !=================for air consumption at 8 bar======================
  329. data%State%Pumps%P_AIRP=data%State%RamLine%BBA1*data%State%Pumps%QAIR**2+data%State%RamLine%BBA2*data%State%Pumps%QAIR+data%State%RamLine%BBA3 !(psig)
  330. data%State%RamLine%kinetic_air=sg*wdens*(data%State%Pumps%QAIR*6.30902e-005/((1/4.)*pi*(2*0.254e-1)**2))**2/(2*6895) !(psi)
  331. data%State%RamLine%diffp_air=data%State%Pumps%P_AIRP+data%State%RamLine%kinetic_air-data%State%RamLine%P_ACC
  332. !===========================LOSSES====================================
  333. do i=1,data%State%RamLine%NO_PIPINGS_AIRPLINE
  334. data%State%RamLine%Re_air(i)=data%State%Pumps%QAIR*6.30902e-005*data%State%RamLine%DIAM_AIR_INCH(I)*0.0254/(data%State%RamLine%AREA_AIR(i)*nu)
  335. enddo
  336. do i=1,data%State%RamLine%NO_PIPINGS_AIRPLINE
  337. if (data%State%RamLine%Re_air(i)<Re_cr) then
  338. data%State%RamLine%fric_air(i)=64/data%State%RamLine%Re_air(i)
  339. else
  340. data%State%RamLine%fric_air(i)=1/(-1.8*log10((data%State%RamLine%REL_ROUGHAIR(i)/3.7)**1.11+6.9/data%State%RamLine%Re_air(i)))**2
  341. endif
  342. data%State%RamLine%fricloss_air(i)=((data%State%RamLine%fric_air(i)*(wdens*sg*data%State%RamLine%LENGT_AIR(i)*(data%State%Pumps%QAIR*6.30902e-005/data%State%RamLine%AREA_AIR(i))**2))/(2*data%State%RamLine%DIAM_AIR_INCH(I)*0.0254))/6895
  343. enddo
  344. data%State%RamLine%pipe_loss1air=sum(data%State%RamLine%fricloss_air) !loss before regulator(psi)
  345. do i=1,data%State%RamLine%NO_MINORS_AIRPLINE
  346. if (data%State%RamLine%LF_AIR(i)/=0) then
  347. data%State%RamLine%minlosspa_air(i)=data%State%RamLine%LF_AIR(i)*wdens*sg*(data%State%Pumps%QAIR*6.30902e-005/data%State%RamLine%MINORAREA_AIR(i))**2/2 !(Pa)
  348. data%State%RamLine%minloss_air(i)=data%State%RamLine%minlosspa_air(i)/6895 !(psi)
  349. elseif (data%State%RamLine%CV_AIR(i)/=0) then
  350. data%State%RamLine%minlosspa_air(i)=1000*sg*((11.7*data%State%Pumps%QAIR*6.30902e-005*3600)/(data%State%RamLine%CV_AIR(i)))**2 !(pa)
  351. data%State%RamLine%minloss_air(i)=data%State%RamLine%minlosspa_air(i)/6895 !(psi)
  352. else
  353. data%State%RamLine%minlosspa_air(i)=data%State%RamLine%NOTE_AIR(i)*1e5 !(pa)
  354. data%State%RamLine%minloss_air(i)=data%State%RamLine%minlosspa_air(i)/6895 !(psi)
  355. endif
  356. enddo
  357. data%State%RamLine%minor_loss1air=sum(data%State%RamLine%minloss_air) !loss before regulator(psi)
  358. data%State%RamLine%static_loss1air=0
  359. data%State%RamLine%losses_air=data%State%RamLine%pipe_loss1air+data%State%RamLine%minor_loss1air+data%State%RamLine%static_loss1air !(psi)
  360. !=========================================================================
  361. end do !returns correct QAIR_PUMP for 1 counter
  362. data%State%RamLine%counter_airp=data%State%RamLine%counter_airp+1
  363. data%State%Pumps%Qiter=data%State%Pumps%QAIR
  364. data%State%BopStackAcc%Cumulative_AirVolume= data%State%BopStackAcc%Cumulative_AirVolume + ((data%State%Pumps%QAIR * data%State%RamLine%DeltaT_BOP / 60.0 ) / (6.71*0.004329004) ) ! =strokes
  365. !write(*,*) 'Cumulative_AirVolume=' , Cumulative_AirVolume
  366. if ( data%State%BopStackAcc%Cumulative_AirVolume > 1.0 ) then
  367. data%State%BopStackAcc%SoundKoomeyAirPump= 120.0
  368. data%State%BopStackAcc%Cumulative_AirVolume= data%State%BopStackAcc%Cumulative_AirVolume - 1.0
  369. else
  370. data%State%BopStackAcc%SoundKoomeyAirPump= 0.0
  371. endif
  372. !SoundKoomeyAirPump= int ( (QAIR_PUMP/ (6.71*0.004329004)) ) ! 6.71: Volume per stroke (in^3) , 0.004329004: in^3 to gal
  373. ! 2.0 : two air pumps 60:seconds
  374. !write(*,*) 'sedaaaa=' ,(QAIR_PUMP/ (6.71*0.004329004)) *DeltaT_BOP/(60.0*2.0)
  375. call SetSoundKoomeyAirPump(data%State%BopStackAcc%SoundKoomeyAirPump)
  376. data%State%Pumps%DELTAV_AIR=data%State%Pumps%QAIR*data%State%RamLine%DeltaT_BOP/60. !(galon) delta_t=1sec , Q(gpm)
  377. !write(*,*) 'QAIR_PUMP=' , QAIR_PUMP
  378. !((((((((IN OUTER LOOP))))))
  379. !fvr_air=fvr_air+deltav_air !=fvr_after (galon) for next timecounter_ram
  380. !========================================================
  381. !WRITE(50,50) QAIR_PUMP,p_airp, &
  382. !p_acc,diffp_air,losses_air,deltav_air
  383. 50 FORMAT(6(f15.5))
  384. end
  385. SUBROUTINE bop_code(ramtype,H_RAMBOP,RNUMBER)
  386. use SimulationVariables
  387. USE CAccumulatorVariables
  388. use CBopControlPanel
  389. use SimulationVariables
  390. USE CEquipmentsConstants
  391. ! use CSimulationVariables
  392. use SimulationVariables !@
  393. use UnityModule
  394. implicit none
  395. integer ramtype, I
  396. real H_RAMBOP
  397. INTEGER RNUMBER
  398. !Pannular_regset=min(AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously
  399. !====================================================
  400. ! BOP back pressure IN PRESENCE OF DP
  401. !====================================================
  402. if (data%State%RAM(RNUMBER)%bop_type==2) then
  403. data%State%RAM(RNUMBER)%checkp= data%State%RAM(RNUMBER)%p_bop
  404. if ( data%State%RAM(RNUMBER)%vdis_tot<data%State%ShearRAM%VA) then
  405. data%State%RAM(RNUMBER)%p_bop=data%State%ShearRAM%PA
  406. elseif (data%State%ShearRAM%VA<= data%State%RAM(RNUMBER)%vdis_tot .and. data%State%RAM(RNUMBER)%vdis_tot<=data%State%ShearRAM%VB) then
  407. data%State%RAM(RNUMBER)%p_bop=data%State%ShearRAM%PA+data%State%ShearRAM%PB*(( data%State%RAM(RNUMBER)%vdis_tot-data%State%ShearRAM%VA)/(data%State%ShearRAM%VB-data%State%ShearRAM%VA))
  408. else
  409. data%State%RAM(RNUMBER)%p_bop=data%State%ShearRAM%PA
  410. endif
  411. if ( data%State%RAM(RNUMBER)%checkp/=data%State%ShearRAM%PA .and. data%State%RAM(RNUMBER)%p_bop==data%State%ShearRAM%PA) then
  412. data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%Qzero
  413. else
  414. data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%flow
  415. endif
  416. endif
  417. !====================================================
  418. ! BOP back pressure without DP
  419. !====================================================
  420. if (data%State%RAM(RNUMBER)%bop_type==3) then
  421. data%State%RAM(RNUMBER)%p_bop=data%State%ShearRAM%PA
  422. ! Q=flow
  423. endif
  424. data%State%RAM(RNUMBER)%clock=0
  425. !======================Losses============================
  426. data%State%RAM(RNUMBER)%loss_after=0 !initial value
  427. data%State%RAM(RNUMBER)%diffp_ram=1000 !initial value
  428. data%State%RAM(RNUMBER)%loss_before=0
  429. !Q=0.0055; %initial flow rate (m^3/s)
  430. data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%flow
  431. do while (abs( data%State%RAM(RNUMBER)%diffp_ram- data%State%RAM(RNUMBER)%loss_after)/ data%State%RAM(RNUMBER)%diffp_ram>data%State%RAM(RNUMBER)%tol)
  432. if (data%State%RAM(RNUMBER)%Bottles_Charged_MalfActive==.true.) exit
  433. ! while abs( data%State%RAM(RNUMBER)%diffp_ram- data%State%RAM(RNUMBER)%loss_after)>10
  434. data%State%RAM(RNUMBER)%clock= data%State%RAM(RNUMBER)%clock+1
  435. if ( data%State%RAM(RNUMBER)%clock>20) then
  436. ! tclock=clock
  437. data%State%RAM(RNUMBER)%tol= data%State%RAM(RNUMBER)%TOLZERO+(floor( data%State%RAM(RNUMBER)%clock/10)-1)*.001
  438. endif
  439. ! if (clock==1) continue
  440. if ( data%State%RAM(RNUMBER)%clock/=1 .and. data%State%RAM(RNUMBER)%loss_after> data%State%RAM(RNUMBER)%diffp_ram) then
  441. data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%Q-.1
  442. elseif ( data%State%RAM(RNUMBER)%clock/=1 .and. data%State%RAM(RNUMBER)%loss_after<= data%State%RAM(RNUMBER)%diffp_ram) then
  443. data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%Q+.01
  444. endif
  445. !====================Before Regulator=========================
  446. !pipe_loss1=3.2; % should be replaced by formula
  447. do i=1,data%State%RamLine%NO_PIPINGSRAMLINE
  448. data%State%RAMS%Re_ramline(RNUMBER,i)=data%State%RAM(RNUMBER)%Q*6.30902e-5*data%State%RamLine%DIAM_RAMLINE_INCH(i)*0.0254/(data%State%RamLine%AREA_RAMLINE(i)*nu)
  449. enddo
  450. do i=1,data%State%RamLine%NO_PIPINGSRAMLINE
  451. if ( data%State%RAMS%Re_ramline(RNUMBER,i)<Re_cr) then
  452. data%State%RAMS%fric(RNUMBER,i)=64/ data%State%RAMS%Re_ramline(RNUMBER,i)
  453. else
  454. data%State%RAMS%fric(RNUMBER,i)=1/(-1.8*log10((data%State%RamLine%RELROUGH_RAMLINE(i)/3.7)**1.11+6.9/ data%State%RAMS%Re_ramline(RNUMBER,i)))**2
  455. endif
  456. data%State%RAMS%fricloss(RNUMBER,i)=(( data%State%RAMS%fric(RNUMBER,i)*(wdens*sg*data%State%RamLine%LENGT_RAMLINE(i)*(data%State%RAM(RNUMBER)%Q*6.30902e-5/data%State%RamLine%AREA_RAMLINE(i))**2))/(2*data%State%RamLine%DIAM_RAMLINE_INCH(i)*0.0254))/6895
  457. enddo
  458. data%State%RAM(RNUMBER)%pipe_loss1=sum( data%State%RAMS%fricloss(RNUMBER,1:6)) !loss before regulator(psi)
  459. ! Q*6.30902e-5 for (gpm) to (m^3/sec)
  460. do i=1,data%State%RamLine%NO_MINORSRAMLINE
  461. if (data%State%RamLine%LF_RAMLINE(i)/=0) then
  462. data%State%RAMS%minlosspa(RNUMBER,i)=data%State%RamLine%LF_RAMLINE(i)*wdens*sg*(data%State%RAM(RNUMBER)%Q*6.30902e-5/data%State%RamLine%AREAMINOR_RAMLINE(i))**2/2 !(Pa)
  463. data%State%RAMS%minloss(RNUMBER,i)= data%State%RAMS%minlosspa(RNUMBER,i)/6895 !(psi)
  464. elseif (data%State%RamLine%CV_RAMLINE(i)/=0) then
  465. data%State%RAMS%minlosspa(RNUMBER,i)=1000*sg*((11.7*data%State%RAM(RNUMBER)%Q*6.30902e-5*3600)/(data%State%RamLine%CV_RAMLINE(i)))**2 !(pa)
  466. data%State%RAMS%minloss(RNUMBER,i)= data%State%RAMS%minlosspa(RNUMBER,i)/6895 !(psi)
  467. else
  468. data%State%RAMS%minlosspa(RNUMBER,i)=data%State%RamLine%NOTE_RAMLINE(i)*1e5 !(pa)
  469. data%State%RAMS%minloss(RNUMBER,i)= data%State%RAMS%minlosspa(RNUMBER,i)/6895 !(psi)
  470. endif
  471. enddo
  472. data%State%RAMS%minloss(RNUMBER,17)= 5.*data%State%RAM(RNUMBER)%Q ! <==== regulator loss (psig)
  473. data%State%RAM(RNUMBER)%minor_loss1=sum( data%State%RAMS%minloss(RNUMBER,1:16)) !loss before regulator(psi)
  474. data%State%RAM(RNUMBER)%static_loss1=0
  475. data%State%RAM(RNUMBER)%kinetic_loss1=sg*wdens*(data%State%RAM(RNUMBER)%Q*6.30902e-5/((1/4.)*pi*(.72*0.254e-1)**2))**2/(2*6895) !(psi)
  476. !.72 for regulator diameter)
  477. data%State%RAM(RNUMBER)%loss_before= data%State%RAM(RNUMBER)%pipe_loss1+ data%State%RAM(RNUMBER)%minor_loss1+ data%State%RAM(RNUMBER)%static_loss1+ data%State%RAM(RNUMBER)%kinetic_loss1 !(psi)
  478. !===================after Regulator======================
  479. ! all in (psi)
  480. data%State%RAM(RNUMBER)%pipe_loss2=sum( data%State%RAMS%fricloss(RNUMBER,7:data%State%RamLine%NO_PIPINGSRAMLINE)) !7=after regulator<<<<<<<
  481. data%State%RAM(RNUMBER)%minor_loss2=sum( data%State%RAMS%minloss(RNUMBER,17:data%State%RamLine%NO_MINORSRAMLINE)) !17=after regulator<<<<<<<
  482. data%State%RAM(RNUMBER)%deltah=H_RAMBOP-data%State%ShearRAM%H_REGRAM
  483. ! data%State%RAM(RNUMBER)%static_loss2pa= data%State%RAM(RNUMBER)%deltah*sg*wdens*gravity; %(pa)
  484. data%State%RAM(RNUMBER)%static_loss2= data%State%RAM(RNUMBER)%deltah*sg*wdens*gravity/6895 !(psi)
  485. data%State%RAM(RNUMBER)%kinetic_loss2=0
  486. data%State%RAM(RNUMBER)%loss_after= data%State%RAM(RNUMBER)%pipe_loss2+ data%State%RAM(RNUMBER)%minor_loss2+ data%State%RAM(RNUMBER)%static_loss2 !(psi)
  487. !=======================================================
  488. if(data%Equipments%BopControlPanel%ByePassValve == -1.0) then
  489. data%State%BopStackAcc%ByPassOld= -1.0
  490. elseif(data%Equipments%BopControlPanel%ByePassValve == 1.0) then
  491. data%State%BopStackAcc%ByPassOld= 1.0
  492. endif
  493. ! write(*,*) 'ByPassOld=', ByPassOld
  494. !==========================p_regulator======================
  495. if (data%State%BopStackAcc%PRAMS_REGSET<data%State%RamLine%P_ACC- data%State%RAM(RNUMBER)%loss_before) then
  496. if(data%State%BopStackAcc%ByPassOld == 1.0) then
  497. !old=pram_reg
  498. !new=PRAMS_REGSET- sum(data%State%RAMS%minloss(2:6,17)) ! 2:6 = RNUMBER
  499. !difference= new-old
  500. data%State%BopStackAcc%PressureDifference= data%State%BopStackAcc%PRAMS_REGSET- sum(data%State%RAMS%minloss(2:6,17)) - data%State%BopStackAcc%pram_reg
  501. if (ABS(data%State%BopStackAcc%PressureDifference) > BaseDifferenceP) then
  502. data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20.
  503. else
  504. data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%PRAMS_REGSET- sum(data%State%RAMS%minloss(2:6,17)) ! 2:6 = RNUMBER
  505. endif
  506. !pram_reg=PRAMS_REGSET- sum(data%State%RAMS%minloss(2:6,17)) ! 2:6 = RNUMBER
  507. else !(ByPassOld == -1.0)
  508. !old=pram_reg
  509. !new=p_acc- data%State%RAM(RNUMBER)%loss_before
  510. !difference= new-old
  511. data%State%BopStackAcc%PressureDifference= data%State%RamLine%P_ACC- data%State%RAM(RNUMBER)%loss_before - data%State%BopStackAcc%pram_reg
  512. if (ABS(data%State%BopStackAcc%PressureDifference) > BaseDifferenceP) then
  513. data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20.
  514. else
  515. data%State%BopStackAcc%pram_reg= data%State%RamLine%P_ACC- data%State%RAM(RNUMBER)%loss_before
  516. endif
  517. endif
  518. !pram_reg=p_acc- data%State%RAM(RNUMBER)%loss_before
  519. else
  520. data%State%BopStackAcc%pram_reg=data%State%RamLine%P_ACC- data%State%RAM(RNUMBER)%loss_before- sum(data%State%RAMS%minloss(2:6,17)) ! 2:6 = RNUMBER
  521. endif
  522. !===========================================================
  523. !====================Flow Rate calculation==================
  524. data%State%RAM(RNUMBER)%diffp_ram=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17)- data%State%RAM(RNUMBER)%p_bop
  525. !write(*,*) 'Q calculation'
  526. end do ! returns correct Q for one timecounter_ram
  527. !write(*,*)'data%State%RAM(RNUMBER)%Q= ' , data%State%RAM(RNUMBER)%Q
  528. !write(*,*) 'UpperRamsLeakMalf , Bottles_Charged_MalfActive=' , UpperRamsLeakMalf , Bottles_Charged_MalfActive
  529. if (data%State%RAM(RNUMBER)%Bottles_Charged_MalfActive==.true.) then
  530. data%State%RAM(RNUMBER)%Q= 5.0 ! gpm
  531. !write(*,*) 'malffffffffff'
  532. endif
  533. data%State%RAM(RNUMBER)%flow=data%State%RAM(RNUMBER)%Q
  534. !====================p_accumulator for next iterate==================
  535. ! deltav=Q*1*1000; %delta_t=1sec (lit)
  536. ! fvr=fvr-deltav; %=fvr_after (lit)
  537. ! p_acc=0.001178*fvr^3+0.02019*fvr^2+16.1*fvr+2379; %(psia)
  538. ! vdis_bottles=fvr_tot-fvr; %from the start***needed for p_bop calculating (lit)
  539. !========for a 10 gal bottle,precharge=1000psig curve BOSCH======
  540. data%State%RAM(RNUMBER)%deltav_bottles=data%State%RAM(RNUMBER)%Q*data%State%RamLine%DeltaT_BOP/60. !(galon) delta_t=1sec , Q(gpm)
  541. data%State%RamLine%FVR=data%State%RamLine%FVR- data%State%RAM(RNUMBER)%deltav_bottles !=fvr_after (galon)
  542. ! b1=993.7; b2=0.164; b3=5.492; b4=0.9796;
  543. data%State%RAM(RNUMBER)%p_acccheck=data%State%RamLine%P_ACC
  544. data%State%RamLine%P_ACC=data%State%RamLine%B1*exp(data%State%RamLine%B2*data%State%RamLine%FVR/data%State%BopStackAcc%NOBOTTLES)+data%State%RamLine%B3*exp(data%State%RamLine%B4*data%State%RamLine%FVR/data%State%BopStackAcc%NOBOTTLES) !(psig)<<<< 8=no. of bottles
  545. !formula is derived for fvr (galon)
  546. !vdis_bottles=fvr_tot-fvr
  547. data%State%RAM(RNUMBER)%vdis_bottles= data%State%RAM(RNUMBER)%vdis_bottles+ data%State%RAM(RNUMBER)%deltav_bottles
  548. data%State%RamLine%NoActiveRmas=6.-real(data%State%Annular%Annular_closed+data%State%RamLine%ShearBop_closed+data%State%PipeRam1%closed+data%State%PipeRam2%closed+data%State%ChokeLine%closed+data%State%KillLine%closed)
  549. data%State%RAM(RNUMBER)%vdis_elecp= data%State%RAM(RNUMBER)%vdis_elecp+(data%State%Pumps%DELTAV_ELECP/data%State%RamLine%NoActiveRmas) !overal discharged
  550. data%State%RAM(RNUMBER)%fvr_air= data%State%RAM(RNUMBER)%fvr_air+(data%State%Pumps%DELTAV_AIR/data%State%RamLine%NoActiveRmas) !=fvr_after (galon) for next timecounter_ram
  551. !write(*,*) 'deltav_air , NoActiveRmas' , deltav_air , NoActiveRmas
  552. data%State%RAM(RNUMBER)%vdis_tot= data%State%RAM(RNUMBER)%vdis_bottles+ data%State%RAM(RNUMBER)%fvr_air+ data%State%RAM(RNUMBER)%vdis_elecp !overal
  553. ! write(*,*) data%State%RAM(RNUMBER)%vdis_tot, vdis_bottles, data%State%RAM(RNUMBER)%fvr_air, vdis_elecp !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  554. if (ramtype==1) then !for shear ram
  555. if (data%State%RamLine%ShearRamIsClosing) then
  556. data%State%ShearRAM%IDshearBop=(2.*(data%State%ShearRAM%NeededVolumeShearRams- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%ShearRAM%AbopShearRam) +data%State%ShearRAM%ShearIsNotAllowed*data%State%ShearRAM%ODDrillpipe_inShearRam
  557. !write(*,*) 'stop now' !, IDshearBop, NeededVolumeShearRams, data%State%RAM(RNUMBER)%vdis_tot, AbopShearRam
  558. endif
  559. if (data%State%RamLine%ShearRamIsOpening) then
  560. data%State%ShearRAM%IDshearBop=data%State%ShearRAM%IDshearBopBase-2.*(data%State%ShearRAM%NeededVolumeShearRams- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%ShearRAM%AbopShearRam
  561. endif
  562. if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%ShearRAM%NeededVolumeShearRams) then
  563. data%State%RamLine%ShearBop_closed=1
  564. !ShearBop_closed_withPossibility= ShearBop_closed * TD_BOPConnectionPossibility(3)
  565. data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17)
  566. data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck
  567. if (data%State%RamLine%ShearRamIsClosing) then
  568. data%State%ShearRAM%IDshearBop=0. + data%State%ShearRAM%ShearIsNotAllowed*data%State%ShearRAM%ODDrillpipe_inShearRam
  569. data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOn
  570. data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOn
  571. data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOff
  572. data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOff
  573. if (data%State%TD_BOP%BOPConnectionPossibility(3) == 1 .and. data%State%ShearRAM%ShearIsNotAllowed==0) then
  574. CALL CloseMiddleRams
  575. data%State%RamLine%ShearBop_Situation_forTD= 1 ! closed - for TD code
  576. endif
  577. endif
  578. if (data%State%RamLine%ShearRamIsOpening) then
  579. data%State%ShearRAM%IDshearBop=data%State%ShearRAM%IDshearBopBase
  580. data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOn
  581. data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOn
  582. data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOff
  583. data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOff
  584. CALL OpenMiddleRams
  585. data%State%RamLine%ShearBop_Situation_forTD= 0 ! open - for TD code
  586. endif
  587. endif
  588. data%State%ShearRAM%IDshearBopFinal= data%State%ShearRAM%IDshearBop ! for output data
  589. endif
  590. if (ramtype==2) then !for pipe ram1
  591. if (data%State%PipeRam1%IsClosing) then
  592. data%State%PipeRam1%ID=(2.*(data%State%PipeRam1%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%PipeRam1%A)+max(data%State%PipeRam1%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase)
  593. endif
  594. if (data%State%PipeRam1%IsOpening) then
  595. data%State%PipeRam1%ID=data%State%PipeRam1%IDBase-2.*(data%State%PipeRam1%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%PipeRam1%A
  596. endif
  597. if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%PipeRam1%NeededVolume) then
  598. data%State%PipeRam1%closed=1
  599. !PipeRam1_Situation_forTD= PipeRam1_closed * TD_BOPConnectionPossibility(2)
  600. data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17)
  601. data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck
  602. if (data%State%PipeRam1%IsClosing) then
  603. data%State%PipeRam1%ID=max(data%State%PipeRam1%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase)
  604. data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOn
  605. data%State%BopStackInput%UpperRamsCloseLEDMine = LedOn
  606. data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOff
  607. data%State%BopStackInput%UpperRamsOpenLEDMine = LedOff
  608. if (data%State%TD_BOP%BOPConnectionPossibility(2) == 1) then
  609. CALL CloseUpperRams ! for C code
  610. call Set_BlowoutFromAnnular(.true.)
  611. data%State%PipeRam1%Situation_forTD= 1 ! closed - for TD code
  612. endif
  613. endif
  614. if (data%State%PipeRam1%IsOpening) then
  615. data%State%PipeRam1%ID=data%State%PipeRam1%IDBase
  616. data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOn
  617. data%State%BopStackInput%UpperRamsOpenLEDMine = LedOn
  618. data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOff
  619. data%State%BopStackInput%UpperRamsCloseLEDMine = LedOff
  620. Call OpenUpperRams ! for C code
  621. data%State%PipeRam1%Situation_forTD= 0 ! open - for TD code
  622. endif
  623. endif
  624. data%State%ShearRAM%IDPipeRam1Final= data%State%PipeRam1%ID ! for output data
  625. endif
  626. if (ramtype==3) then !for pipe ram2
  627. if (data%State%PipeRam2%IsClosing) then
  628. data%State%PipeRam2%ID=(2.*(data%State%PipeRam2%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%PipeRam1%A)+max(data%State%PipeRam2%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase)
  629. endif
  630. if (data%State%PipeRam2%IsOpening) then
  631. data%State%PipeRam2%ID=data%State%PipeRam1%IDBase-2.*(data%State%PipeRam2%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%PipeRam1%A
  632. endif
  633. if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%PipeRam2%NeededVolume) then
  634. data%State%PipeRam2%closed=1
  635. !PipeRam2_closed_withPossibility= PipeRam2_closed * TD_BOPConnectionPossibility(4)
  636. data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17)
  637. data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck
  638. if (data%State%PipeRam2%IsClosing) then
  639. data%State%PipeRam2%ID=max(data%State%PipeRam2%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase)
  640. data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOn
  641. data%State%BopStackInput%LowerRamsCloseLEDMine = LedOn
  642. data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOff
  643. data%State%BopStackInput%LowerRamsOpenLEDMine = LedOff
  644. if (data%State%TD_BOP%BOPConnectionPossibility(4) == 1) then
  645. CALL CloseLowerRams
  646. data%State%PipeRam2%Situation_forTD= 1 ! closed - for TD code
  647. endif
  648. endif
  649. if (data%State%PipeRam2%IsOpening) then
  650. data%State%PipeRam2%ID=data%State%PipeRam1%IDBase
  651. data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOn
  652. data%State%BopStackInput%LowerRamsOpenLEDMine = LedOn
  653. data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOff
  654. data%State%BopStackInput%LowerRamsCloseLEDMine = LedOff
  655. CALL OpenLowerRams
  656. data%State%PipeRam2%Situation_forTD= 0 ! open - for TD code
  657. endif
  658. endif
  659. data%State%ShearRAM%IDPipeRam2Final= data%State%PipeRam2%ID ! for output data
  660. endif
  661. if (ramtype==4) then !for Choke Line
  662. if (data%State%ChokeLine%IsClosing) then
  663. data%State%ChokeLine%ID=(2.*(data%State%ChokeLine%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%ChokeLine%Abop)+max(data%State%ChokeLine%ODDrillpipe_in,data%State%ChokeLine%ODDrillpipe_inBase)
  664. endif
  665. if (data%State%ChokeLine%IsOpening) then
  666. data%State%ChokeLine%ID=data%State%ChokeLine%IDBase-2.*(data%State%ChokeLine%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%ChokeLine%Abop
  667. endif
  668. if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%ChokeLine%NeededVolume) then
  669. data%State%ChokeLine%closed=1
  670. data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17)
  671. data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck
  672. if (data%State%ChokeLine%IsClosing) then
  673. data%State%ChokeLine%ID=max(data%State%ChokeLine%ODDrillpipe_in,data%State%ChokeLine%ODDrillpipe_inBase)
  674. data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOn
  675. data%State%BopStackInput%ChokeLineCloseLEDMine = LedOn
  676. data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOff
  677. data%State%BopStackInput%ChokeLineOpenLEDMine = LedOff
  678. CALL CloseChokeLine
  679. endif
  680. if (data%State%ChokeLine%IsOpening) then
  681. data%State%ChokeLine%ID=data%State%ChokeLine%IDBase
  682. data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOn
  683. data%State%BopStackInput%ChokeLineOpenLEDMine = LedOn
  684. data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOff
  685. data%State%BopStackInput%ChokeLineCloseLEDMine = LedOff
  686. CALL OpenChokeLine
  687. endif
  688. endif
  689. endif
  690. if (ramtype==5) then !for Kill Line
  691. if (data%State%KillLine%IsClosing) then
  692. data%State%KillLine%ID=(2.*(data%State%KillLine%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%KillLine%Abop)+max(data%State%KillLine%ODDrillpipe_in,data%State%KillLine%ODDrillpipe_inBase)
  693. endif
  694. if (data%State%KillLine%IsOpening) then
  695. data%State%KillLine%ID=data%State%KillLine%IDBase-2.*(data%State%KillLine%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%KillLine%Abop
  696. endif
  697. if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%KillLine%NeededVolume) then
  698. data%State%KillLine%closed=1
  699. data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17)
  700. data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck
  701. if (data%State%KillLine%IsClosing) then
  702. data%State%KillLine%ID=max(data%State%KillLine%ODDrillpipe_in,data%State%KillLine%ODDrillpipe_inBase)
  703. data%Equipments%BopControlPanel%KillLineCloseLED = LedOn
  704. data%State%BopStackInput%KillLineCloseLedMine = LedOn
  705. data%Equipments%BopControlPanel%KillLineOpenLED = LedOff
  706. data%State%BopStackInput%KillLineOpenLedMine = LedOff
  707. CALL CloseKillLine
  708. endif
  709. if (data%State%KillLine%IsOpening) then
  710. data%State%KillLine%ID=data%State%KillLine%IDBase
  711. data%Equipments%BopControlPanel%KillLineOpenLED = LedOn
  712. data%State%BopStackInput%KillLineOpenLedMine = LedOn
  713. data%Equipments%BopControlPanel%KillLineCloseLED = LedOff
  714. data%State%BopStackInput%KillLineCloseLedMine = LedOff
  715. CALL OpenKillLine
  716. endif
  717. endif
  718. endif
  719. !if (ramtype==4) then !for annular
  720. ! if (AnnularIsClosing) then
  721. ! IDAnnular=((NeededVolumeAnnular-vdis_tot)*231./AbopAnnular)+ODDrillpipe_inAnnular
  722. ! endif
  723. !
  724. ! if (AnnularIsOpening) then
  725. ! IDAnnular=IDAnnularBase-(NeededVolumeAnnular-vdis_tot)*231./AbopAnnular
  726. ! endif
  727. !
  728. ! if (vdis_tot>NeededVolumeAnnular) then
  729. !
  730. ! Annular_closed=1
  731. ! p_acc= data%State%RAM(RNUMBER)%p_acccheck
  732. !
  733. ! if (AnnularIsClosing) then
  734. ! IDAnnular=ODDrillpipe_inAnnular
  735. ! AnnularCloseLed = LedOn
  736. ! AnnularOpenLed = LedOff
  737. ! endif
  738. !
  739. ! if (AnnularIsOpening) then
  740. ! IDAnnular=IDAnnularBase
  741. ! AnnularOpenLed = LedOn
  742. ! AnnularCloseLed = LedOff
  743. ! endif
  744. !
  745. ! endif
  746. !
  747. !endif
  748. end
  749. SUBROUTINE bop_codeAnnular(RNUMBER)
  750. use SimulationVariables
  751. use CBopControlPanel
  752. use SimulationVariables
  753. USE CEquipmentsConstants
  754. use SimulationVariables !@
  755. implicit none
  756. INTEGER RNUMBER, I
  757. !Pannular_regset=min(AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously
  758. !====================================================
  759. ! BOP back pressure without DP
  760. !====================================================
  761. !if (bop_type==3) then
  762. !p_annular=510.725-(30.145*IDAnnular)
  763. data%State%AnnularComputational%p_annular=448-(19.7*data%State%Annular%IDAnnular)
  764. ! Q=flow
  765. ! endif
  766. data%State%RAM(RNUMBER)%clock=0
  767. !======================Losses============================
  768. data%State%RAM(RNUMBER)%loss_after=0 !initial value
  769. data%State%RAM(RNUMBER)%diffp_ram=1000 !initial value
  770. data%State%RAM(RNUMBER)%loss_before=0
  771. !Q=0.0055; %initial flow rate (m^3/s)
  772. data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%flow
  773. !write(*,*) 'Q1=' , Q
  774. !write(*,*) 'tol=' , tol
  775. do while (abs( data%State%RAM(RNUMBER)%diffp_ram- data%State%RAM(RNUMBER)%loss_after)/ data%State%RAM(RNUMBER)%diffp_ram>data%State%Annular%tolAnnular)
  776. if (data%State%RAM(RNUMBER)%Bottles_Charged_MalfActive==.true.) exit
  777. ! while abs( data%State%RAM(RNUMBER)%diffp_ram- data%State%RAM(RNUMBER)%loss_after)>10
  778. data%State%RAM(RNUMBER)%clock= data%State%RAM(RNUMBER)%clock+1
  779. if ( data%State%RAM(RNUMBER)%clock>20) then
  780. ! tclock=clock
  781. data%State%Annular%tolAnnular=data%State%Annular%tolzeroAnnular+(floor( data%State%RAM(RNUMBER)%clock/10)-1)*.001
  782. endif
  783. ! if (clock==1) continue
  784. if ( data%State%RAM(RNUMBER)%clock/=1 .and. data%State%RAM(RNUMBER)%loss_after> data%State%RAM(RNUMBER)%diffp_ram) then
  785. data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%Q-.1
  786. elseif ( data%State%RAM(RNUMBER)%clock/=1 .and. data%State%RAM(RNUMBER)%loss_after<= data%State%RAM(RNUMBER)%diffp_ram) then
  787. data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%Q+.01
  788. endif
  789. !====================Before Regulator=========================
  790. do i=1,data%State%AnnularComputational%NO_PipingsAnnularLine
  791. data%State%AnnularComputational%Re_ANNULARline(i)=data%State%RAM(RNUMBER)%Q*6.30902e-5*data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(i)*0.0254/(data%State%AnnularComputational%AREA_ANNULARLINE(i)*nu)
  792. enddo
  793. do i=1,data%State%AnnularComputational%NO_PipingsAnnularLine
  794. if (data%State%AnnularComputational%Re_ANNULARline(i)<Re_cr) then
  795. data%State%AnnularComputational%fricANNULAR(i)=64/data%State%AnnularComputational%Re_ANNULARline(i)
  796. else
  797. data%State%AnnularComputational%fricANNULAR(i)=1/(-1.8*log10((data%State%AnnularComputational%RELROUGH_ANNULARLINE(i)/3.7)**1.11+6.9/data%State%AnnularComputational%Re_ANNULARline(i)))**2
  798. endif
  799. data%State%AnnularComputational%friclossANNULAR(i)=((data%State%AnnularComputational%fricANNULAR(i)*(wdens*sg*data%State%AnnularComputational%LENGT_ANNULARLINE(i)*(data%State%RAM(RNUMBER)%Q*6.30902e-5/data%State%AnnularComputational%AREA_ANNULARLINE(i))**2))/(2*data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(i)*0.0254))/6895
  800. enddo
  801. data%State%RAM(RNUMBER)%pipe_loss1=sum(data%State%AnnularComputational%friclossANNULAR(1:6)) !loss before regulator(psi)
  802. do i=1,data%State%AnnularComputational%NO_MinorsAnnularLine
  803. if (data%State%AnnularComputational%LF_ANNULARLINE(i)/=0) then
  804. data%State%AnnularComputational%minlosspa_ANNULAR(i)=data%State%AnnularComputational%LF_ANNULARLINE(i)*wdens*sg*(data%State%RAM(RNUMBER)%Q*6.30902e-5/data%State%AnnularComputational%AREAMINOR_ANNULARLINE(i))**2/2 !(Pa)
  805. data%State%AnnularComputational%minloss_ANNULAR(i)=data%State%AnnularComputational%minlosspa_ANNULAR(i)/6895 !(psi)
  806. elseif (data%State%AnnularComputational%CV_ANNULARLINE(i)/=0) then
  807. data%State%AnnularComputational%minlosspa_ANNULAR(i)=1000*sg*((11.7*data%State%RAM(RNUMBER)%Q*6.30902e-5*3600)/(data%State%AnnularComputational%CV_ANNULARLINE(i)))**2 !(pa)
  808. data%State%AnnularComputational%minloss_ANNULAR(i)=data%State%AnnularComputational%minlosspa_ANNULAR(i)/6895 !(psi)
  809. else
  810. data%State%AnnularComputational%minlosspa_ANNULAR(i)=data%State%AnnularComputational%NOTE_ANNULARLINE(i)*1e5 !(pa)
  811. data%State%AnnularComputational%minloss_ANNULAR(i)=data%State%AnnularComputational%minlosspa_ANNULAR(i)/6895 !(psi)
  812. endif
  813. enddo
  814. data%State%AnnularComputational%minloss_ANNULAR(17)= 3.4*data%State%RAM(RNUMBER)%Q ! <==== regulator loss (psig)
  815. data%State%RAM(RNUMBER)%minor_loss1=sum(data%State%AnnularComputational%minloss_ANNULAR(1:16)) !loss before regulator(psi)
  816. data%State%RAM(RNUMBER)%static_loss1=0
  817. data%State%RAM(RNUMBER)%kinetic_loss1=sg*wdens*(data%State%RAM(RNUMBER)%Q*6.30902e-5/((1/4.)*pi*(.72*0.254e-1)**2))**2/(2*6895) !(psi)
  818. !.72 for regulator diameter)
  819. data%State%RAM(RNUMBER)%loss_before= data%State%RAM(RNUMBER)%pipe_loss1+ data%State%RAM(RNUMBER)%minor_loss1+ data%State%RAM(RNUMBER)%static_loss1+ data%State%RAM(RNUMBER)%kinetic_loss1 !(psi)
  820. !===================after Regulator======================
  821. ! all in (psi)
  822. data%State%RAM(RNUMBER)%pipe_loss2=sum(data%State%AnnularComputational%friclossANNULAR(7:data%State%AnnularComputational%NO_PipingsAnnularLine)) !7=after regulator<<<<<<<
  823. data%State%RAM(RNUMBER)%minor_loss2=sum(data%State%AnnularComputational%minloss_ANNULAR(17:data%State%AnnularComputational%NO_MinorsAnnularLine)) !17=after regulator<<<<<<<
  824. data%State%RAM(RNUMBER)%deltah=data%State%Annular%H_AnnularBop-data%State%ShearRAM%H_REGRAM
  825. ! data%State%RAM(RNUMBER)%static_loss2pa= data%State%RAM(RNUMBER)%deltah*sg*wdens*gravity; %(pa)
  826. data%State%RAM(RNUMBER)%static_loss2= data%State%RAM(RNUMBER)%deltah*sg*wdens*gravity/6895 !(psi)
  827. data%State%RAM(RNUMBER)%kinetic_loss2=0
  828. data%State%RAM(RNUMBER)%loss_after= data%State%RAM(RNUMBER)%pipe_loss2+ data%State%RAM(RNUMBER)%minor_loss2+ data%State%RAM(RNUMBER)%static_loss2 !(psi)
  829. !=======================================================
  830. !==========================p_regulator======================
  831. if (data%State%Annular%Pannular_regset<data%State%RamLine%P_ACC- data%State%RAM(RNUMBER)%loss_before) then
  832. !!new= Pannular_regset-minloss_ANNULAR(17)
  833. !
  834. !CALL Pannular_regDelay%AddToFirst( Pannular_regset-minloss_ANNULAR(17) )
  835. !CALL Pannular_regDelay%Remove(Pannular_regDelay%Length())
  836. !Pannular_reg= Pannular_regDelay%Last()
  837. data%State%Annular%Pannular_reg= data%State%Annular%Pannular_regset-data%State%AnnularComputational%minloss_ANNULAR(17)
  838. ! data%State%RAM(RNUMBER)%loss_after= data%State%RAM(RNUMBER)%loss_after-minloss(17); %minloss(17)=regulator loss
  839. else
  840. !!new= p_acc- data%State%RAM(RNUMBER)%loss_before-minloss_ANNULAR(17)
  841. !
  842. !CALL Pannular_regDelay%AddToFirst( p_acc- data%State%RAM(RNUMBER)%loss_before-minloss_ANNULAR(17) )
  843. !CALL Pannular_regDelay%Remove(Pannular_regDelay%Length())
  844. !Pannular_reg= Pannular_regDelay%Last()
  845. data%State%Annular%Pannular_reg= data%State%RamLine%P_ACC- data%State%RAM(RNUMBER)%loss_before-data%State%AnnularComputational%minloss_ANNULAR(17)
  846. endif
  847. !===========================================================
  848. !====================Flow Rate calculation==================
  849. data%State%RAM(RNUMBER)%diffp_ram=data%State%Annular%Pannular_reg+data%State%AnnularComputational%minloss_ANNULAR(17)-data%State%AnnularComputational%p_annular
  850. end do ! returns correct Q for one timecounter_ram
  851. if (data%State%RAM(RNUMBER)%Bottles_Charged_MalfActive==.true.) then
  852. data%State%RAM(RNUMBER)%Q= 5.0 ! gpm
  853. !write(*,*) 'malffffffffff'
  854. endif
  855. data%State%RAM(RNUMBER)%flow=data%State%RAM(RNUMBER)%Q
  856. !write(*,*) 'minloss_ANNULAR(17)=' , minloss_ANNULAR(17)
  857. !write(*,*) '%loss_after=' ,data%State%RAM(RNUMBER)%loss_after
  858. !====================p_accumulator for next iterate==================
  859. ! deltav=Q*1*1000; %delta_t=1sec (lit)
  860. ! fvr=fvr-deltav; %=fvr_after (lit)
  861. ! p_acc=0.001178*fvr^3+0.02019*fvr^2+16.1*fvr+2379; %(psia)
  862. ! vdis_bottles=fvr_tot-fvr; %from the start***needed for p_BOP calculating (lit)
  863. !========for a 10 gal bottle,precharge=1000psig curve BOSCH======
  864. data%State%RAM(RNUMBER)%deltav_bottles=data%State%RAM(RNUMBER)%Q*data%State%RamLine%DeltaT_BOP/60. !(galon) delta_t=1sec , Q(gpm)
  865. data%State%RamLine%FVR=data%State%RamLine%FVR- data%State%RAM(RNUMBER)%deltav_bottles !=fvr_after (galon)
  866. ! b1=993.7; b2=0.164; b3=5.492; b4=0.9796;
  867. data%State%RAM(RNUMBER)%p_acccheck=data%State%RamLine%P_ACC
  868. data%State%RamLine%P_ACC=data%State%RamLine%B1*exp(data%State%RamLine%B2*data%State%RamLine%FVR/data%State%BopStackAcc%NOBOTTLES)+data%State%RamLine%B3*exp(data%State%RamLine%B4*data%State%RamLine%FVR/data%State%BopStackAcc%NOBOTTLES) !(psig)<<<< 8=no. of bottles
  869. !formula is derived for fvr (galon)
  870. !vdis_bottles=fvr_tot-fvr
  871. data%State%RAM(RNUMBER)%vdis_bottles= data%State%RAM(RNUMBER)%vdis_bottles+ data%State%RAM(RNUMBER)%deltav_bottles
  872. data%State%RamLine%NoActiveRmas=6.-real(data%State%Annular%Annular_closed+data%State%RamLine%ShearBop_closed+data%State%PipeRam1%closed+data%State%PipeRam2%closed+data%State%ChokeLine%closed+data%State%KillLine%closed)
  873. data%State%RAM(RNUMBER)%vdis_elecp= data%State%RAM(RNUMBER)%vdis_elecp+(data%State%Pumps%DELTAV_ELECP/data%State%RamLine%NoActiveRmas) !overal discharged
  874. data%State%RAM(RNUMBER)%fvr_air= data%State%RAM(RNUMBER)%fvr_air+(data%State%Pumps%DELTAV_AIR/data%State%RamLine%NoActiveRmas) !=fvr_after (galon) for next timecounter_ram
  875. data%State%RAM(RNUMBER)%vdis_tot= data%State%RAM(RNUMBER)%vdis_bottles+ data%State%RAM(RNUMBER)%fvr_air+ data%State%RAM(RNUMBER)%vdis_elecp !overal
  876. !write(*,*) 'data%State%RAM(RNUMBER)%vdis_tot=' , data%State%RAM(RNUMBER)%vdis_tot!, vdis_bottles,fvr_air, vdis_elecp !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  877. !write(*,*) 'a)IDAnnular=' , IDAnnular
  878. ! WRITE(*,*) 'a)NeededVolumeAnnular=' , NeededVolumeAnnular
  879. !
  880. ! write(*,*) 'AbopAnnular= ' , AbopAnnular
  881. ! write(*,*) 'max=' , max(ODDrillpipe_inAnnular,ODDrillpipe_inAnnularBase)
  882. !if (ramtype==4) then !for annular
  883. if (data%State%Annular%AnnularIsClosing) then
  884. data%State%Annular%IDAnnular=(2.*(data%State%Annular%NeededVolumeAnnular- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%Annular%AbopAnnular)+max(data%State%Annular%ODDrillpipe_inAnnular,data%State%Annular%ODDrillpipe_inAnnularBase)
  885. !write(*,*) 'b)IDAnnular=' , IDAnnular
  886. endif
  887. if (data%State%Annular%AnnularIsOpening) then
  888. data%State%Annular%IDAnnular=data%State%Annular%IDAnnularBase-2.*(data%State%Annular%NeededVolumeAnnular- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%Annular%AbopAnnular
  889. endif
  890. if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%Annular%NeededVolumeAnnular) then
  891. data%State%Annular%Annular_closed=1
  892. !Annular_closed_withPossibility= Annular_closed * TD_BOPConnectionPossibility(1)
  893. !pram_reg=pram_reg+minloss_ANNULAR(17)
  894. data%State%Annular%Pannular_reg= data%State%Annular%Pannular_reg+data%State%AnnularComputational%minloss_ANNULAR(17)
  895. data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck
  896. if (data%State%Annular%AnnularIsClosing) then
  897. data%State%Annular%IDAnnular=max(data%State%Annular%ODDrillpipe_inAnnular,data%State%Annular%ODDrillpipe_inAnnularBase)
  898. data%Equipments%BopControlPanel%AnnularCloseLED = LedOn
  899. data%State%BopStackInput%AnnularCloseLedMine = LedOn
  900. data%Equipments%BopControlPanel%AnnularOpenLED = LedOff
  901. data%State%BopStackInput%AnnularOpenLedMine = LedOff
  902. if (data%State%TD_BOP%BOPConnectionPossibility(1) == 1) then
  903. CALL CloseAnnular
  904. data%State%Annular%Annular_Situation_forTD= 1 ! closed - for TD code
  905. endif
  906. endif
  907. if (data%State%Annular%AnnularIsOpening) then
  908. data%State%Annular%IDAnnular=data%State%Annular%IDAnnularBase
  909. data%Equipments%BopControlPanel%AnnularOpenLED = LedOn
  910. data%State%BopStackInput%AnnularOpenLedMine = LedOn
  911. data%Equipments%BopControlPanel%AnnularCloseLED = LedOff
  912. data%State%BopStackInput%AnnularCloseLedMine = LedOff
  913. CALL OpenAnnular
  914. data%State%Annular%Annular_Situation_forTD= 0 ! open - for TD code
  915. endif
  916. endif
  917. data%State%ShearRAM%IDAnnularFinal= data%State%Annular%IDAnnular ! for output data
  918. !endif
  919. end