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.
 
 
 
 
 
 

1269 lines
47 KiB

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