Simulation Core
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

1269 linhas
67 KiB

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