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.
 
 
 
 
 
 

539 regels
32 KiB

  1. module ChokeControlMain
  2. USE CHOKEVARIABLES
  3. use SimulationVariables !@
  4. implicit none
  5. public
  6. contains
  7. ! subroutine ChokeControl_Setup()
  8. ! ! use CSimulationVariables
  9. ! implicit none
  10. ! call OnSimulationInitialization%Add(ChokeControl_Init)
  11. ! call OnSimulationStop%Add(ChokeControl_Init)
  12. ! call OnChokeControlStep%Add(ChokeControl_Step)
  13. ! call OnChokeControlOutput%Add(ChokeControl_Output)
  14. ! call OnChokeControlMain%Add(ChokeControlMainBody)
  15. ! end subroutine
  16. subroutine ChokeControl_Init
  17. call Choke_StartUp()
  18. end subroutine ChokeControl_Init
  19. subroutine ChokeControl_Step
  20. use ChokeModule
  21. implicit none
  22. INTEGER CHNUMBER
  23. IF(data%Equipments%ChokeControlPanel%ChokeSelectorSwitch) THEN
  24. data%Equipments%ChokeControlPanel%Choke1LED=1
  25. data%Equipments%ChokeControlPanel%Choke2LED=0
  26. CHNUMBER=1
  27. ELSE
  28. data%Equipments%ChokeControlPanel%Choke2LED=1
  29. data%Equipments%ChokeControlPanel%Choke1LED=0
  30. CHNUMBER=2
  31. ENDIF
  32. if(ABS(data%Equipments%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) then
  33. if (data%Equipments%ChokeControlPanel%ChokeControlLever == 1.0) then
  34. data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .true.
  35. data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .false.
  36. endif
  37. if (data%Equipments%ChokeControlPanel%ChokeControlLever == -1.0) then
  38. data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .true.
  39. data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .false.
  40. endif
  41. data%State%AirPumpLine%TIME=data%State%AirPumpLine%TIME+data%State%AirPumpLine%DeltaT_Choke !overal time (s)
  42. call airpump_code_CHOKE(CHNUMBER)
  43. else
  44. call CHOKE_MainBody2()
  45. endif
  46. end subroutine ChokeControl_Step
  47. ! subroutine ChokeControl_Output
  48. ! implicit none
  49. ! end subroutine ChokeControl_Output
  50. ! subroutine ChokeControlMainBody
  51. ! use CRigSizeVariables
  52. ! use CHOKE
  53. ! implicit none
  54. ! CALL Choke_StartUp()
  55. ! loop1: DO
  56. ! CALL CHOKE_MainBody
  57. ! call sleepqq(100)
  58. ! !IF (IsStopped==.true.) THEN
  59. ! ! EXIT loop1
  60. ! !ENDIF
  61. ! !write(*,*) '1111111111111'
  62. ! if(IsStopped) then
  63. ! !write(*,*) '22222222222222'
  64. ! CALL DEALLOCATE_ARRAYS_CHOKE()
  65. ! !write(*,*) '333333333'
  66. ! call Quit()
  67. ! end if
  68. ! ENDDO loop1
  69. ! CLOSE(150)
  70. ! !CALL DEALLOCATE_ARRAYS_CHOKE()
  71. ! end subroutine ChokeControlMainBody
  72. SUBROUTINE Choke_StartUp()
  73. USE CHOKEVARIABLES
  74. use SimulationVariables
  75. USE CChokeProblemsVariables
  76. implicit none
  77. CALL LOSS_INPUTS_CHOKE()
  78. !OPEN(150,FILE='CHOKE_AIRPUMP_OUTPUTS.DAT')
  79. !data%State%CHOOKE(1)%WashoutMalf=1
  80. !data%State%CHOOKE(1)%PlugMalf=0
  81. !data%State%CHOOKE(1)%FailMalf=0
  82. !
  83. !data%State%CHOOKE(2)%WashoutMalf=1
  84. !data%State%CHOOKE(2)%PlugMalf=0
  85. !data%State%CHOOKE(2)%FailMalf=0
  86. !
  87. !
  88. !ChokeAirFail=0
  89. !
  90. !GaugeChokePositionMailf=0
  91. data%State%Choke%kRatio=1.4
  92. data%State%Choke%Cp=0.24
  93. data%State%Choke%CL=0.8
  94. data%State%Choke%x1=0.5
  95. data%State%Choke%LiquidPPG=9.
  96. data%State%Choke%LiquidDensity=data%State%Choke%LiquidPPG*7.48 !lbm/ft**3
  97. data%State%Choke%VL=1.0/data%State%Choke%LiquidDensity !SpecificVolume of Liquid
  98. data%State%Choke%Cv=data%State%Choke%Cp/data%State%Choke%kRatio
  99. data%State%Choke%nPolytripic=1+(data%State%Choke%x1*(data%State%Choke%Cp-data%State%Choke%Cv)/(data%State%Choke%x1*data%State%Choke%Cv+(1-data%State%Choke%x1)*data%State%Choke%CL))
  100. data%State%Choke%VG1=1./0.748 !lbm/ft**3 Specific Volume of Air, Upstream
  101. data%State%Choke%Cdrag=0.8
  102. data%State%Choke%Pwh=1400. !psi
  103. data%State%Choke%Patm=14.7
  104. data%State%Choke%MixDens2=data%State%Choke%x1*data%State%Choke%VG1 !lbm/ft**3
  105. data%State%Choke%epsilon_abs= 1e-5
  106. data%State%Choke%epsilon_step= 1e-5
  107. !ChokeDiameter= 32/64. !in
  108. data%State%CHOOKE%PercentClose= 0.0
  109. !AreaChoke=0.01334635
  110. ! data%State%CHOOKE(1)%AreaChoke=0.01334635
  111. !ChokeAreaFullyOpen = 123.d0 / 64.d0 ! fully open area is 123/64 in^2 = 0.01334635 ft^2
  112. data%State%AirPumpLine%DeltaT_Choke=0.1
  113. !TotalStrokes1=0.
  114. !TotalStrokes2=0.
  115. data%State%Choke%HydraulicChoke1WashoutCoef= 0.0
  116. data%State%Choke%HydraulicChoke2WashoutCoef= 0.0
  117. data%State%Choke%ChokePlugTimeDelay = int(180./data%State%AirPumpLine%DeltaT_Choke) ! =1800 = 180/0.1 : for 3 min delay
  118. data%State%Choke%Present_HydraulicChoke1Plug = REAL(data%problems%ChokeProblems%HydraulicChoke1PluggedPercent)/100.
  119. data%State%Choke%HydraulicChoke1PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke1PluggedPercent
  120. data%State%Choke%Plug1TimeCounter= 0
  121. data%State%Choke%DeltaPlug1Percent = 0.0
  122. data%State%Choke%Present_HydraulicChoke2Plug = REAL(data%problems%ChokeProblems%HydraulicChoke2PluggedPercent)/100.
  123. data%State%Choke%HydraulicChoke2PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke2PluggedPercent
  124. data%State%Choke%Plug2TimeCounter= 0
  125. data%State%Choke%DeltaPlug2Percent = 0.0
  126. !======================AIRPUMP INPUTS(CONSTANTS)===========================
  127. data%State%AirPumpLine%CourseBase= 24. !cm
  128. data%State%CHOOKE%PassedCourse= 0.
  129. data%Equipments%ChokeControlPanel%ChokePosition=0.
  130. data%State%AirPumpLine%Acylinder= PI*(8.**2)/4. ! (CM^2), 8=DIAMETER, 24=course , 3785.412: cm^3 to galon
  131. data%State%CHOOKE%ChokeIsOpening = .false.
  132. data%State%CHOOKE%ChokeIsClosing = .false.
  133. data%State%AirPumpLine%P_AIRP=0
  134. data%State%AirDrivenPump%cc1 = 0.1354; data%State%AirDrivenPump%cc2 = -2.066; data%State%AirDrivenPump%cc3 = -21.09; data%State%AirDrivenPump%cc4 = -51.36; data%State%AirDrivenPump%cc5 = 5935 ! FOR OUTPUT IN GPM
  135. ! cc1 = 4.754e-07; cc2 = -0.0001676; cc3 = -0.03953; cc4 = -2.223; cc5 = 5935 FOR OUTPUT IN IN^3/MIN
  136. data%State%AirPumpLine%Pdownstrem= 4950 !+0.01*Pchoke (psi) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  137. data%State%AirPumpLine%QITER=5. !(gpm)
  138. ! Q=0.0003585; true
  139. data%State%AirPumpLine%TIME=0
  140. data%State%AirPumpLine%TOL_AIR=0.05
  141. data%State%AirPumpLine%alpha_Qair=0
  142. data%State%AirPumpLine%alpha_timeair=0
  143. data%State%AirPumpLine%alpha_Pdownstrem=data%State%AirPumpLine%Pdownstrem
  144. data%State%AirPumpLine%alpha_diffpair=0
  145. data%State%AirPumpLine%alpha_lossesair=0
  146. end
  147. SUBROUTINE DEALLOCATE_ARRAYS_CHOKE()
  148. USE CHOKEVARIABLES
  149. use SimulationVariables !@
  150. implicit none
  151. write(*,*) 'deallocateeeeeeeeeeeee'
  152. !===========================================================================
  153. ! AIR PUMP LOSSES INPUT
  154. !===========================================================================
  155. !if(allocated(PIPINGS_AIRPUMP)) deallocate(PIPINGS_AIRPUMP)
  156. DEALLOCATE (data%State%AirPumpLine%PIPINGS_AIRPUMP,data%State%AirPumpLine%DIAM_AIR_INCH, &
  157. data%State%AirPumpLine%Re_air,data%State%AirPumpLine%AREA_AIR,data%State%AirPumpLine%LENGT_AIR,data%State%AirPumpLine%ROUGHNESS_AIRPLINE,data%State%AirPumpLine%REL_ROUGHAIR, &
  158. data%State%AirPumpLine%fric_air,data%State%AirPumpLine%fricloss_air)
  159. !================================================================
  160. DEALLOCATE (data%State%AirPumpLine%MINORS_AIRPUMP,data%State%AirPumpLine%MINORDIAM_AIR_INCH, &
  161. data%State%AirPumpLine%MINORAREA_AIR,data%State%AirPumpLine%LF_AIR,data%State%AirPumpLine%CV_AIR,data%State%AirPumpLine%NOTE_AIR &
  162. ,data%State%AirPumpLine%minlosspa_air,data%State%AirPumpLine%minloss_air)
  163. END
  164. SUBROUTINE LOSS_INPUTS_CHOKE()
  165. USE CHOKEVARIABLES
  166. use SimulationVariables
  167. implicit none
  168. Integer I
  169. !===========================================================================
  170. ! AIR PUMP LOSSES INPUT
  171. !===========================================================================
  172. data%State%AirPumpLine%NO_PIPINGS_AIRPLINE=1
  173. ALLOCATE (data%State%AirPumpLine%PIPINGS_AIRPUMP(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE,3))
  174. ! ID(INCH) L(MM) ROUGHNESS(MM)=e DESCRIPTION
  175. data%State%AirPumpLine%PIPINGS_AIRPUMP(1,1:3)= (/0.5, 60960., 0.03/) !Avg.acc.distance
  176. !60960= 200 ft
  177. ALLOCATE(data%State%AirPumpLine%DIAM_AIR_INCH(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE))
  178. ALLOCATE(data%State%AirPumpLine%Re_air(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE))
  179. ALLOCATE(data%State%AirPumpLine%AREA_AIR(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE))
  180. ALLOCATE(data%State%AirPumpLine%LENGT_AIR(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE))
  181. ALLOCATE(data%State%AirPumpLine%ROUGHNESS_AIRPLINE(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE))
  182. ALLOCATE(data%State%AirPumpLine%REL_ROUGHAIR(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE))
  183. ALLOCATE(data%State%AirPumpLine%fric_air(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE))
  184. ALLOCATE(data%State%AirPumpLine%fricloss_air(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE))
  185. DO I=1,data%State%AirPumpLine%NO_PIPINGS_AIRPLINE
  186. data%State%AirPumpLine%DIAM_AIR_INCH(I)=data%State%AirPumpLine%PIPINGS_AIRPUMP(I,1)
  187. data%State%AirPumpLine%LENGT_AIR(I)=data%State%AirPumpLine%PIPINGS_AIRPUMP(I,2)
  188. data%State%AirPumpLine%ROUGHNESS_AIRPLINE(I)=data%State%AirPumpLine%PIPINGS_AIRPUMP(I,3)
  189. data%State%AirPumpLine%AREA_AIR(I)=PI*(data%State%AirPumpLine%DIAM_AIR_INCH(I)*0.0254)**2/4 !D(in), AREA(m)
  190. data%State%AirPumpLine%REL_ROUGHAIR(I)=data%State%AirPumpLine%ROUGHNESS_AIRPLINE(I)/(data%State%AirPumpLine%DIAM_AIR_INCH(I)*25.4)
  191. !DIAM_RAMLINE_MM(I)=DIAM_RAMLINE_MM(I)*.001 ! (m)
  192. data%State%AirPumpLine%LENGT_AIR(I)=data%State%AirPumpLine%LENGT_AIR(I)*.001 ! (m)
  193. ENDDO
  194. !================================================================
  195. data%State%AirPumpLine%NO_MINORS_AIRPLINE=6
  196. ALLOCATE (data%State%AirPumpLine%MINORS_AIRPUMP(data%State%AirPumpLine%NO_MINORS_AIRPLINE,4))
  197. ! ID(INCH) LF CV NOTE(BAR) DESCRIPTION
  198. data%State%AirPumpLine%MINORS_AIRPUMP(1,1:4)= (/2., 10., 0., 0./) !Acc.tee
  199. data%State%AirPumpLine%MINORS_AIRPUMP(2,1:4)= (/2., 11., 0., 0./) !elbow
  200. data%State%AirPumpLine%MINORS_AIRPUMP(3,1:4)= (/1., 0., 0., 3.4/) !filter
  201. data%State%AirPumpLine%MINORS_AIRPUMP(4,1:4)= (/2., 0., 105., 0./) !valve
  202. data%State%AirPumpLine%MINORS_AIRPUMP(5,1:4)= (/1., 0., 9.2, 0./) !valve
  203. data%State%AirPumpLine%MINORS_AIRPUMP(6,1:4)= (/2., 6.4, 0., 0./) !unionA
  204. ALLOCATE (data%State%AirPumpLine%MINORDIAM_AIR_INCH(data%State%AirPumpLine%NO_MINORS_AIRPLINE),data%State%AirPumpLine%MINORAREA_AIR(data%State%AirPumpLine%NO_MINORS_AIRPLINE), &
  205. data%State%AirPumpLine%LF_AIR(data%State%AirPumpLine%NO_MINORS_AIRPLINE),data%State%AirPumpLine%CV_AIR(data%State%AirPumpLine%NO_MINORS_AIRPLINE),data%State%AirPumpLine%NOTE_AIR(data%State%AirPumpLine%NO_MINORS_AIRPLINE) &
  206. ,data%State%AirPumpLine%minlosspa_air(data%State%AirPumpLine%NO_MINORS_AIRPLINE),data%State%AirPumpLine%minloss_air(data%State%AirPumpLine%NO_MINORS_AIRPLINE))
  207. DO I=1,data%State%AirPumpLine%NO_MINORS_AIRPLINE
  208. data%State%AirPumpLine%MINORDIAM_AIR_INCH(I)=data%State%AirPumpLine%MINORS_AIRPUMP(I,1)
  209. data%State%AirPumpLine%LF_AIR(I)=data%State%AirPumpLine%MINORS_AIRPUMP(I,2)
  210. data%State%AirPumpLine%CV_AIR(I)=data%State%AirPumpLine%MINORS_AIRPUMP(I,3)
  211. data%State%AirPumpLine%NOTE_AIR(I)=data%State%AirPumpLine%MINORS_AIRPUMP(I,4)
  212. data%State%AirPumpLine%MINORAREA_AIR(I)=PI*(data%State%AirPumpLine%MINORDIAM_AIR_INCH(I)*0.0254)**2/4. !D(in), AREA(m)
  213. ENDDO
  214. END
  215. ! SUBROUTINE PIPE_RAMS_CHOKE(CHNUMBER)
  216. ! USE CHOKEVARIABLES
  217. ! use ConfigurationVariables !@
  218. ! Use CSimulationVariables
  219. ! implicit none
  220. ! INTEGER CHNUMBER
  221. ! Integer I
  222. ! loop3: do while (ABS(data%Equipments%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0)
  223. ! if (data%Equipments%ChokeControlPanel%ChokeControlLever == 1.0) then
  224. ! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .true.
  225. ! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .false.
  226. ! endif
  227. ! if (data%Equipments%ChokeControlPanel%ChokeControlLever == -1.0) then
  228. ! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .true.
  229. ! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .false.
  230. ! endif
  231. ! data%State%AirPumpLine%TIME=data%State%AirPumpLine%TIME+data%State%AirPumpLine%DeltaT_Choke !overal time (s)
  232. ! call airpump_code_CHOKE(CHNUMBER)
  233. ! call sleepqq(100)
  234. ! if (IsStopped == .true.) return
  235. ! end do loop3 !while finished_Choke==0
  236. ! end
  237. SUBROUTINE airpump_code_CHOKE(CHNUMBER)
  238. USE CHOKEVARIABLES
  239. use SimulationVariables !@
  240. use CChokeManifold
  241. use SimulationVariables
  242. use CSounds
  243. USE CChokeProblemsVariables
  244. implicit none
  245. Integer I
  246. INTEGER CHNUMBER
  247. data%State%AirDrivenPump%QAIR_PUMP=data%State%AirPumpLine%QITER+.1 !(gpm) maximum flow for the start
  248. data%State%AirPumpLine%diffp_air=-10
  249. data%State%AirPumpLine%losses_air=10
  250. !===================================================================
  251. ! AIR OPERATED PUMP
  252. ! MODEL 10-6000W030 RATIO 55:1
  253. !=================for air consumption at 100 psig===================
  254. do while (data%State%AirPumpLine%diffp_air<0)
  255. data%State%AirDrivenPump%QAIR_PUMP=data%State%AirDrivenPump%QAIR_PUMP-.1
  256. ! Qup=data%State%AirDrivenPump%QAIR_PUMP;
  257. !cc1 = 1354; cc2 = -2066; cc3 = -2109; cc4 = -513.6; cc5 = 5935 FOR OUTPUT IN GPM
  258. data%State%AirPumpLine%P_AIRP=data%State%AirDrivenPump%cc1*(data%State%AirDrivenPump%QAIR_PUMP**4) + data%State%AirDrivenPump%cc2*(data%State%AirDrivenPump%QAIR_PUMP**3) + data%State%AirDrivenPump%cc3*(data%State%AirDrivenPump%QAIR_PUMP**2) + data%State%AirDrivenPump%cc4*data%State%AirDrivenPump%QAIR_PUMP + data%State%AirDrivenPump%cc5 !(psig)
  259. ! kinetic_air=sg*wdens*(QAIR_PUMP*6.30902e-5/((1/4.)*pi*(2*0.254e-1)**2))**2/(2*6895) !(psi)
  260. data%State%AirPumpLine%diffp_air= data%State%AirPumpLine%P_AIRP - data%State%AirPumpLine%Pdownstrem
  261. end do !returns Qup
  262. do while (abs((data%State%AirPumpLine%diffp_air-data%State%AirPumpLine%losses_air)/data%State%AirPumpLine%diffp_air)>data%State%AirPumpLine%TOL_AIR) !finding correct QAIR_pump for 1 timecounter_ram
  263. if (data%State%AirPumpLine%diffp_air-data%State%AirPumpLine%losses_air>0) then
  264. data%State%AirDrivenPump%QAIR_PUMP=data%State%AirDrivenPump%QAIR_PUMP+.005
  265. else
  266. data%State%AirDrivenPump%QAIR_PUMP=data%State%AirDrivenPump%QAIR_PUMP-.005
  267. endif
  268. !===================================================================
  269. ! AIR OPERATED PUMP
  270. ! MODEL 10-6000W030 RATIO 55:1
  271. !=================for air consumption at 100 psig===================
  272. data%State%AirPumpLine%P_AIRP=data%State%AirDrivenPump%cc1*(data%State%AirDrivenPump%QAIR_PUMP**4) + data%State%AirDrivenPump%cc2*(data%State%AirDrivenPump%QAIR_PUMP**3) + data%State%AirDrivenPump%cc3*(data%State%AirDrivenPump%QAIR_PUMP**2) + data%State%AirDrivenPump%cc4*data%State%AirDrivenPump%QAIR_PUMP + data%State%AirDrivenPump%cc5 !(psig)
  273. !kinetic_air=sg*wdens*(QAIR_PUMP*6.30902e-005/((1/4.)*pi*(2*0.254e-1)**2))**2/(2*6895) !(psi)
  274. data%State%AirPumpLine%diffp_air= data%State%AirPumpLine%P_AIRP - data%State%AirPumpLine%Pdownstrem
  275. !===========================LOSSES====================================
  276. do i=1,data%State%AirPumpLine%NO_PIPINGS_AIRPLINE
  277. data%State%AirPumpLine%Re_air(i)=data%State%AirDrivenPump%QAIR_PUMP*6.30902e-005*data%State%AirPumpLine%DIAM_AIR_INCH(I)*0.0254/(data%State%AirPumpLine%AREA_AIR(i)*nu)
  278. enddo
  279. do i=1,data%State%AirPumpLine%NO_PIPINGS_AIRPLINE
  280. if (data%State%AirPumpLine%Re_air(i)<Re_cr) then
  281. data%State%AirPumpLine%fric_air(i)=64/data%State%AirPumpLine%Re_air(i)
  282. else
  283. data%State%AirPumpLine%fric_air(i)=1/(-1.8*log10((data%State%AirPumpLine%REL_ROUGHAIR(i)/3.7)**1.11+6.9/data%State%AirPumpLine%Re_air(i)))**2
  284. endif
  285. data%State%AirPumpLine%fricloss_air(i)=((data%State%AirPumpLine%fric_air(i)*(wdens*sg*data%State%AirPumpLine%LENGT_AIR(i)*(data%State%AirDrivenPump%QAIR_PUMP*6.30902e-005/data%State%AirPumpLine%AREA_AIR(i))**2))/(2*data%State%AirPumpLine%DIAM_AIR_INCH(I)*0.0254))/6895
  286. enddo
  287. data%State%AirPumpLine%pipe_loss1air=sum(data%State%AirPumpLine%fricloss_air) !loss before regulator(psi)
  288. do i=1,data%State%AirPumpLine%NO_MINORS_AIRPLINE
  289. if (data%State%AirPumpLine%LF_AIR(i)/=0) then
  290. data%State%AirPumpLine%minlosspa_air(i)=data%State%AirPumpLine%LF_AIR(i)*wdens*sg*(data%State%AirDrivenPump%QAIR_PUMP*6.30902e-005/data%State%AirPumpLine%MINORAREA_AIR(i))**2/2 !(Pa)
  291. data%State%AirPumpLine%minloss_air(i)=data%State%AirPumpLine%minlosspa_air(i)/6895 !(psi)
  292. elseif (data%State%AirPumpLine%CV_AIR(i)/=0) then
  293. data%State%AirPumpLine%minlosspa_air(i)=1000*sg*((11.7*data%State%AirDrivenPump%QAIR_PUMP*6.30902e-005*3600)/(data%State%AirPumpLine%CV_AIR(i)))**2 !(pa)
  294. data%State%AirPumpLine%minloss_air(i)=data%State%AirPumpLine%minlosspa_air(i)/6895 !(psi)
  295. else
  296. data%State%AirPumpLine%minlosspa_air(i)=data%State%AirPumpLine%NOTE_AIR(i)*1e5 !(pa)
  297. data%State%AirPumpLine%minloss_air(i)=data%State%AirPumpLine%minlosspa_air(i)/6895 !(psi)
  298. endif
  299. enddo
  300. data%State%AirPumpLine%minor_loss1air=sum(data%State%AirPumpLine%minloss_air) !loss before regulator(psi)
  301. data%State%AirPumpLine%static_loss1air=0
  302. data%State%AirPumpLine%losses_air=data%State%AirPumpLine%pipe_loss1air+data%State%AirPumpLine%minor_loss1air+data%State%AirPumpLine%static_loss1air !(psi)
  303. !=========================================================================
  304. end do !returns correct QAIR_PUMP for 1 counter
  305. data%State%AirPumpLine%QITER=data%State%AirDrivenPump%QAIR_PUMP
  306. data%State%AirDrivenPump%QAIR_PUMP=data%State%AirDrivenPump%QAIR_PUMP*(data%Equipments%ChokeControlPanel%ChokeRateControlKnob/10.) ! final Q (gpm)
  307. data%State%Choke%Cumulative_AirVolume_Choke= data%State%Choke%Cumulative_AirVolume_Choke + ((data%State%AirDrivenPump%QAIR_PUMP * data%State%AirPumpLine%DeltaT_Choke / 60.0 ) / (1.5*0.004329004) ) ! =strokes
  308. if ( data%State%Choke%Cumulative_AirVolume_Choke > 1.0 ) then
  309. data%State%Choke%SoundChokePump= 60
  310. data%State%Choke%Cumulative_AirVolume_Choke= data%State%Choke%Cumulative_AirVolume_Choke - 1.0
  311. else
  312. data%State%Choke%SoundChokePump= 0.0
  313. endif
  314. data%State%AirPumpLine%DELTAV_AIR=data%State%AirDrivenPump%QAIR_PUMP*data%State%AirPumpLine%DeltaT_Choke/60 !(galon) delta_t=1sec , Q(gpm)
  315. if (data%State%CHOOKE(CHNUMBER)%ChokeIsClosing) data%State%CHOOKE(CHNUMBER)%PassedCourse=data%State%CHOOKE(CHNUMBER)%PassedCourse + (data%State%AirPumpLine%DELTAV_AIR*3785.412/data%State%AirPumpLine%Acylinder)!*(ChokeRateControlKnob/10.) ! 3785.412 : GALON TO CM^3
  316. if (data%State%CHOOKE(CHNUMBER)%ChokeIsOpening) data%State%CHOOKE(CHNUMBER)%PassedCourse=data%State%CHOOKE(CHNUMBER)%PassedCourse - (data%State%AirPumpLine%DELTAV_AIR*3785.412/data%State%AirPumpLine%Acylinder)!*(ChokeRateControlKnob/10.)
  317. !DeltaT_Choke= 1sec or 2sec
  318. !((((((((IN OUTER LOOP))))))
  319. !===============AIR PUMP OUTPUTS=========================
  320. data%State%AirPumpLine%alpha_timeair=data%State%AirPumpLine%TIME ! overal time (s)
  321. data%State%AirPumpLine%alpha_Pdownstrem=data%State%AirPumpLine%Pdownstrem
  322. data%State%AirPumpLine%alpha_pairp=data%State%AirPumpLine%P_AIRP
  323. data%State%AirPumpLine%alpha_Qair=data%State%AirDrivenPump%QAIR_PUMP
  324. !write(*,*) 'diffp_air=',diffp_air
  325. !pause
  326. data%State%AirPumpLine%alpha_diffpair=data%State%AirPumpLine%diffp_air
  327. data%State%AirPumpLine%alpha_lossesair=data%State%AirPumpLine%losses_air
  328. !========================================================
  329. !OPEN(150,FILE='CHOKE_AIRPUMP_OUTPUTS.DAT')
  330. if (data%State%CHOOKE(CHNUMBER)%ChokeIsClosing .AND. data%State%CHOOKE(CHNUMBER)%PassedCourse>data%State%AirPumpLine%CourseBase) then
  331. data%State%CHOOKE(CHNUMBER)%PassedCourse=data%State%AirPumpLine%CourseBase
  332. data%State%Choke%SoundChokePump= 0.0
  333. endif
  334. if (data%State%CHOOKE(CHNUMBER)%ChokeIsOpening .AND. data%State%CHOOKE(CHNUMBER)%PassedCourse<0.) then
  335. data%State%CHOOKE(CHNUMBER)%PassedCourse=0.
  336. data%State%Choke%SoundChokePump= 0.0
  337. endif
  338. call SetSoundChokePump(data%State%Choke%SoundChokePump)
  339. data%State%CHOOKE(CHNUMBER)%PercentClose= data%State%CHOOKE(CHNUMBER)%PassedCourse/data%State%AirPumpLine%CourseBase
  340. IF (data%Equipments%ChokeControlPanel%Choke1LED==1) THEN
  341. data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(1)%PercentClose*10
  342. ELSE ! Choke2LED==1
  343. data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(2)%PercentClose*10
  344. ENDIF
  345. !CALL SetHydraulicChock1(nint(MIN(data%State%CHOOKE(1)%PercentClose / 0.91 , 1.0)*100))
  346. ! CALL SetHydraulicChock2(nint(MIN(data%State%CHOOKE(2)%PercentClose / 0.91 , 1.0)*100))
  347. ! .91 >> 9 percent clearance
  348. ! =================== calculating Area
  349. ! AreaChoke=0.5
  350. ! .91 >> 9 percent clearance
  351. data%State%CHOOKE(1)%AreaChoke=0.01334635-(0.01334635* MIN(data%State%CHOOKE(1)%PercentClose / 0.91 , 1.0)) !ft^2 0.01334635 is ChokeAreaFullyOpen (ft^2)
  352. data%State%CHOOKE(2)%AreaChoke=0.01334635-(0.01334635* MIN(data%State%CHOOKE(2)%PercentClose/ 0.91 , 1.0)) !ft^2
  353. data%State%Choke%HydraulicChoke1WashoutCoef= data%State%Choke%HydraulicChoke1WashoutCoef * data%State%CHOOKE(1)%WashoutMalf
  354. data%State%Choke%HydraulicChoke1WashoutCoef= MIN( 0.5 , data%State%Choke%HydraulicChoke1WashoutCoef+ data%State%CHOOKE(1)%WashoutMalf*(0.5/(60.0/data%State%AirPumpLine%DeltaT_Choke)) ) ! 0.5=maximum washout coef , 60.0 sec= 1min duration time
  355. data%State%Choke%HydraulicChoke2WashoutCoef= data%State%Choke%HydraulicChoke2WashoutCoef * data%State%CHOOKE(2)%WashoutMalf
  356. data%State%Choke%HydraulicChoke2WashoutCoef= MIN( 0.5 , data%State%Choke%HydraulicChoke2WashoutCoef+ data%State%CHOOKE(2)%WashoutMalf*(0.5/(60.0/data%State%AirPumpLine%DeltaT_Choke)) ) ! 0.5=maximum washout coef , 60.0 sec= 1min duration time
  357. !write(*,*) 'HydraulicChoke1WashoutCoef=' , HydraulicChoke1WashoutCoef
  358. IF (data%State%CHOOKE(1)%PlugMalf == 1) THEN
  359. data%State%Choke%Present_HydraulicChoke1Plug= data%State%Choke%Present_HydraulicChoke1Plug * data%State%CHOOKE(1)%PlugMalf
  360. ! integer: HydraulicChoke1PluggedPercent,HydraulicChoke1PluggedPercent_Old,PlugTimeCounter,ChokePlugTimeDelay
  361. ! real: Present_HydraulicChoke1Plug,DeltaPlug1Percent
  362. !write(*,*) 'HydraulicChoke1PluggedPercent=' , HydraulicChoke1PluggedPercent
  363. if ( (data%problems%ChokeProblems%HydraulicChoke1PluggedPercent - data%State%Choke%HydraulicChoke1PluggedPercent_Old) /= 0) then
  364. data%State%Choke%DeltaPlug1Percent = (REAL(data%problems%ChokeProblems%HydraulicChoke1PluggedPercent)/100.) - data%State%Choke%Present_HydraulicChoke1Plug
  365. data%State%Choke%Plug1TimeCounter = 0
  366. !write(*,*) 'DeltaPlug1Percent, Present_HydraulicChoke1Plug = ' ,DeltaPlug1Percent , Present_HydraulicChoke1Plug
  367. endif
  368. data%State%Choke%Plug1TimeCounter= data%State%Choke%Plug1TimeCounter + 1
  369. data%State%Choke%HydraulicChoke1PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke1PluggedPercent
  370. if (data%State%Choke%Plug1TimeCounter <= data%State%Choke%ChokePlugTimeDelay) then !ChokePlugTimeDelay=600
  371. data%State%Choke%Present_HydraulicChoke1Plug = data%State%Choke%Present_HydraulicChoke1Plug + data%State%CHOOKE(1)%PlugMalf* ((data%State%Choke%DeltaPlug1Percent / real(data%State%Choke%ChokePlugTimeDelay))) ! real(ChokePlugTimeDelay)= 600.0
  372. endif
  373. !write(*,*) 'Present_HydraulicChoke1Plug=' , Present_HydraulicChoke1Plug
  374. ENDIF
  375. IF (data%State%CHOOKE(2)%PlugMalf == 1) THEN
  376. data%State%Choke%Present_HydraulicChoke2Plug= data%State%Choke%Present_HydraulicChoke2Plug * data%State%CHOOKE(2)%PlugMalf
  377. ! integer: HydraulicChoke2PluggedPercent,HydraulicChoke2PluggedPercent_Old,PlugTimeCounter,ChokePlugTimeDelay
  378. ! real: Present_HydraulicChoke2Plug,DeltaPlug2Percent
  379. if ( (data%problems%ChokeProblems%HydraulicChoke2PluggedPercent - data%State%Choke%HydraulicChoke2PluggedPercent_Old) /= 0 ) then
  380. data%State%Choke%DeltaPlug2Percent = (REAL(data%problems%ChokeProblems%HydraulicChoke2PluggedPercent)/100.) - data%State%Choke%Present_HydraulicChoke2Plug
  381. data%State%Choke%Plug2TimeCounter = 0
  382. endif
  383. data%State%Choke%Plug2TimeCounter= data%State%Choke%Plug2TimeCounter + 1
  384. data%State%Choke%HydraulicChoke2PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke2PluggedPercent
  385. if (data%State%Choke%Plug2TimeCounter <= data%State%Choke%ChokePlugTimeDelay) then !ChokePlugTimeDelay=600
  386. data%State%Choke%Present_HydraulicChoke2Plug = data%State%Choke%Present_HydraulicChoke2Plug + data%State%CHOOKE(2)%PlugMalf *((data%State%Choke%DeltaPlug2Percent / real(data%State%Choke%ChokePlugTimeDelay))) ! real(ChokePlugTimeDelay)= 600.0
  387. endif
  388. ENDIF
  389. ! fully open area is 123/64 in^2 = 0.01334635 ft^2
  390. data%State%CHOOKE(1)%AreaChoke=data%State%CHOOKE(1)%AreaChoke+(data%State%CHOOKE(1)%WashoutMalf*data%State%Choke%HydraulicChoke1WashoutCoef*data%State%Choke%ChokeAreaFullyOpen/144.0) ! Initialised in Choke Startup
  391. !write(*,*) 'data%State%CHOOKE(1)%WashoutMalf , data%State%CHOOKE(1)%AreaChoke=' ,data%State%CHOOKE(1)%WashoutMalf , data%State%CHOOKE(1)%AreaChoke
  392. data%State%CHOOKE(1)%AreaChoke=data%State%CHOOKE(1)%AreaChoke-(data%State%CHOOKE(1)%PlugMalf* data%State%Choke%Present_HydraulicChoke1Plug *data%State%CHOOKE(1)%AreaChoke) ! Initialised in Choke Startup
  393. data%State%CHOOKE(2)%AreaChoke=data%State%CHOOKE(2)%AreaChoke+(data%State%CHOOKE(2)%WashoutMalf*data%State%Choke%HydraulicChoke2WashoutCoef*data%State%Choke%ChokeAreaFullyOpen/144.0) ! Initialised in Choke Startup
  394. data%State%CHOOKE(2)%AreaChoke=data%State%CHOOKE(2)%AreaChoke-(data%State%CHOOKE(2)%PlugMalf* data%State%Choke%Present_HydraulicChoke2Plug *data%State%CHOOKE(2)%AreaChoke) ! Initialised in Choke Startup
  395. !write(*,*) 'data%State%CHOOKE(2)%WashoutMalf , data%State%CHOOKE(2)%AreaChoke=' ,data%State%CHOOKE(2)%WashoutMalf , data%State%CHOOKE(2)%AreaChoke
  396. data%State%CHOOKE(1)%AreaChokeFinal= data%State%CHOOKE(1)%AreaChoke
  397. data%State%CHOOKE(2)%AreaChokeFinal= data%State%CHOOKE(2)%AreaChoke
  398. ! 144: ft^2 to in^2
  399. CALL SetHydraulicChock1(100 - nint((data%State%CHOOKE(1)%AreaChokeFinal/(data%State%Choke%ChokeAreaFullyOpen/144.))*100)) ! for manifold valve
  400. CALL SetHydraulicChock2(100 - nint((data%State%CHOOKE(2)%AreaChokeFinal/(data%State%Choke%ChokeAreaFullyOpen/144.))*100)) ! for manifold valve
  401. !write(*,*) 'data%State%CHOOKE(1)%PercentClose=' , data%State%CHOOKE(1)%PercentClose ! close percent 0 to 100
  402. !write(*,*) 'ChokePosition=' , ChokePosition ! close position 0 to 10 for display
  403. !write(*,*) 'data%State%CHOOKE(1)%AreaChokeFinal=' , data%State%CHOOKE(1)%AreaChokeFinal ! Open Area (in^2) with clearance
  404. !write(*,*) '(ChokeAreaFullyOpen/144.)=' , (ChokeAreaFullyOpen/144.)
  405. !write(*,*) 'valve value=' , 100 - nint((data%State%CHOOKE(1)%AreaChokeFinal/(ChokeAreaFullyOpen/144.))*100) ! percent close 0 to 100 with clearance
  406. !write(*,*) 'Valve(33)%Status=' , Valve(33)%Status ! T : open , F: close
  407. ! =================== calculating Area
  408. !write(*,*) 'data%State%CHOOKE(1)%AreaChoke= ' , data%State%CHOOKE(1)%AreaChoke
  409. !WRITE(150,50) alpha_timeair,alpha_Qair,alpha_pairp, &
  410. !alpha_Pdownstrem,alpha_diffpair,alpha_lossesair,data%State%CHOOKE(CHNUMBER)%PassedCourse
  411. !50 FORMAT(7(f15.5))
  412. !========================================================================================
  413. !========================================================================================
  414. ! write(*,*) PassedCourse
  415. end
  416. end module ChokeControlMain