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.
 
 
 
 
 
 

1267 lines
69 KiB

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