Simulation Core
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

3467 righe
160 KiB

  1. module MudSystemModule
  2. USE MudSystemVARIABLES
  3. USE PressureDisplayVARIABLES
  4. USE FricPressDropVars
  5. USE Fluid_Flow_Startup_Vars
  6. USE CMudPropertiesVariables
  7. USE CManifolds
  8. USE CPumpsVariables
  9. USE CUnityOutputs
  10. use CWarningsVariables
  11. use DynamicIntegerArray
  12. use CError
  13. use CLog1
  14. USE CDataDisplayConsoleVariables
  15. use CStudentStationVariables !, PitGainLossReset=>PitGainLossZero
  16. implicit none
  17. real j2,j12,j13,jj2,jj12,jj13
  18. real A71,A72,A73
  19. integer j3,B71,B77,B78
  20. integer j4
  21. real C71,C77,C78
  22. integer j5
  23. integer j6,D71,D80
  24. integer j7,j8,j9,j10,j11
  25. real E71,E72,E73
  26. real F71,F72,F73
  27. integer j14
  28. real G82,G83,G84
  29. integer j15
  30. real H82,H83,H84
  31. integer j16,K82,K83,K84,K79,K78
  32. integer j17,L82,L83,L84,L79,L78
  33. integer j18
  34. real M71,M77,M78, Pump1toCh,Pump2toCh,Pump3toCh,Denominator_a
  35. integer j19
  36. real N82,N83,N84
  37. integer j20
  38. integer j21
  39. real unityreturn
  40. real(8) DumpPump1,DumpPump2,DumpCementPump,Denominator
  41. real(8) Mp1Coef,Mp2Coef,CpCoef
  42. real(8) PumpPressure1,PumpPressure2,PumpPressure3
  43. integer Mp1_NoPath,Mp2_NoPath,Cp_NoPath
  44. real P1toSt,P2toSt,CptoSt
  45. real(8) MaxWorkingPressure1,MaxWorkingPressure2,MaxWorkingPressure3,MaxWorkingPressure
  46. REAL(8) DumpFromKelly, DumpFromFillupHead
  47. real(8) AddedVolumeToTank,PUMP1_Flow_Rate_Old,PUMP2_Flow_Rate_Old,PUMP3_Flow_Rate_Old
  48. real(8) VolumeToActive,VolumeToBellNipple,BellNipple_FlowCoef,ChokeLine_FlowCoef
  49. REAL RealJ2,RealJ12,RealJ13,RealJ4,RealJ18
  50. INTEGER active32,active33,active34,active35,active29
  51. logical condition1, condition2, condition3, condition4, condition5, condition6, condition7, condition8, condition9, condition10, condition11, condition12, condition13, condition14, condition15
  52. logical condition16,condition17,condition18,condition19,condition20,condition21,condition22,condition23,condition24,condition25,condition26,condition27,condition28,condition29,condition30,condition31
  53. logical condition32,condition33,condition34,condition35,condition36,condition37,condition38,condition39,condition40,condition41,condition42,condition43,condition44,condition45
  54. logical condition46,condition47,condition48,condition49,condition50,condition51,condition52,condition53,condition54,condition55,condition56,condition57,condition58
  55. logical condition59,condition60,condition61
  56. logical ac32, ac33, ac34, ac35, ac29
  57. logical ThereIsPathFrom_71_72_73_To_82, ThereIsPathFrom_71_72_73_To_83, ThereIsPathFrom_71_72_73_To_84
  58. logical DumpFromKelly_Pump1, DumpFromKelly_Pump2, DumpFromKelly_Pump3
  59. logical DumpFromTopDrive_Pump1,DumpFromTopDrive_Pump2,DumpFromTopDrive_Pump3
  60. logical DumpFromFillupHead_Pump1, DumpFromFillupHead_Pump2, DumpFromFillupHead_Pump3
  61. logical State1,State2, State3, State4
  62. type(DynamicIntegerArrayType) Pump1_Lasts,Pump2_Lasts, Pump3_Lasts
  63. REAL MP1_Q, MP2_Q, MP3_Q
  64. real TimePassed
  65. real(8) active_after, active_before, active_increase, total_active_increase,total_decrease,sys_total_injected
  66. real(8) total_annFlow,total_DeltaVPipe
  67. contains
  68. subroutine LineupAndPath()
  69. implicit none
  70. !===========================================================================
  71. ! MUDLINE CODE
  72. !===========================================================================
  73. ! Initialize
  74. j2=0
  75. jj2=0
  76. A71=0
  77. A72=0
  78. A73=0
  79. RealJ2=0.0
  80. j3=0
  81. B71=0
  82. B77=0
  83. B78=0
  84. j4=0
  85. C71=0.
  86. C77=0.
  87. C78=0.
  88. active32=0
  89. active33=0
  90. active34=0
  91. active35=0
  92. active29=0
  93. j5=0
  94. j6=0
  95. D71=0
  96. D80=0
  97. j7=0
  98. j8=0
  99. j9=0
  100. j10=0
  101. j11=0
  102. j12=0
  103. jj12=0
  104. E71=0
  105. E72=0
  106. E73=0
  107. RealJ12=0.0
  108. j13=0
  109. jj13=0
  110. F71=0
  111. F72=0
  112. F73=0
  113. RealJ13=0.0
  114. j14=0
  115. G82=0
  116. G83=0
  117. G84=0
  118. DumpPump1=0.
  119. DumpPump2=0.
  120. DumpCementPump=0.
  121. j15=0
  122. H82=0.0
  123. H83=0.0
  124. H84=0.0
  125. Mp1Coef= 0.0
  126. Mp1Coef= 0.0
  127. CpCoef= 0.0
  128. Mp1_NoPath= 0
  129. Mp2_NoPath= 0
  130. Cp_NoPath= 0
  131. j16=0
  132. K82=0
  133. K83=0
  134. K84=0
  135. K78=0
  136. K79=0
  137. j17=0
  138. L82=0
  139. L83=0
  140. L84=0
  141. L78=0
  142. L79=0
  143. j18=0
  144. M71=0.
  145. M77=0.
  146. M78=0.
  147. Pump1toCh=0.
  148. Pump2toCh=0.
  149. Pump3toCh=0.
  150. j19=0
  151. N82=0
  152. N83=0
  153. N84=0
  154. j20=0
  155. j21=0
  156. !===========================================================================
  157. !===============TanksToMudPump1=================
  158. if(condition1) then
  159. j2=j2+1
  160. A71=1
  161. jj2=1
  162. endif
  163. if(condition2) then
  164. j2=j2+1
  165. A72=1
  166. jj2=1
  167. endif
  168. if(condition3) then
  169. j2=j2+1
  170. A73=1
  171. jj2=1
  172. endif
  173. !================================================
  174. !============BellNippleToPits-FullWell==============
  175. if(MudSystem%FirstMudSet== 1 ) then !.and. WellisNOTFull== .false.) then ! Well Must Be Full !Ann_Mud_Forehead_X%Last()==AboveAnnularHeight .and. Ann_Density%Last()/=0.0)
  176. if(condition4) then
  177. j3=j3+1
  178. B71=1
  179. endif
  180. if(condition5) then
  181. j3=j3+1
  182. B77=1
  183. endif
  184. if(condition6) then
  185. j3=j3+1
  186. B78=1
  187. endif
  188. endif
  189. !================================================
  190. !============WellToChokeManifold(Through 26)==============
  191. if(condition7) then
  192. j4=j4+1
  193. C71=1.
  194. endif
  195. if(condition8) then
  196. j4=j4+1
  197. C77=1.
  198. endif
  199. if(condition45) then
  200. j4=j4+1
  201. C78=1.
  202. endif
  203. if (ac32) active32=1
  204. if (ac33) active33=1
  205. if (ac34) active34=1
  206. if (ac35) active35=1
  207. if (ac29) active29=1 !BYPASS VALVE
  208. !================================================
  209. !============ActiveTankToTripTank==============
  210. if(condition9) then
  211. j5=j5+1
  212. endif
  213. !================================================
  214. !write(*,*) 'j5====' , j5
  215. !============TripTankToActiveTank And BellNipple==============
  216. if(condition10) then
  217. j6=j6+1
  218. D71=1
  219. endif
  220. if(condition11) then
  221. j6=j6+1
  222. D80=1
  223. endif
  224. !================================================
  225. !============ActiveTankToDump==============
  226. if(condition12) then
  227. j7=j7+1
  228. endif
  229. !================================================
  230. !============TripTankToDump==============
  231. if(condition13) then
  232. j8=j8+1
  233. endif
  234. !================================================
  235. !============WellToBellNipple==============
  236. if(condition14) then
  237. j9=j9+1
  238. endif
  239. !================================================
  240. !============MudBucketToBellNipple==============
  241. if(condition15) then
  242. j10=j10+1
  243. endif
  244. !================================================
  245. !============BellNippleToWell-NonFullWell==============
  246. if(condition16 .and. MudSystem%FirstMudSet== 1 .and. MudSystem%BellNippleVolume > 0.0001 .and. MudSystem%WellisNOTFull) then
  247. write(*,*) 'MUD(7)%Q=' , MUD(7)%Q
  248. write(*,*) 'BellNippleVolume=' , MudSystem%BellNippleVolume
  249. write(*,*) 'MudSystem%MudVolume_InjectedFromAnn-WellToBellNipple=' , MudSystem%MudVolume_InjectedFromAnn
  250. write(*,*) 'int:::=' , (MudSystem%Ann_Mud_Forehead_X%Last() - BopStackSpecification%AboveAnnularHeight)
  251. write(*,*) 'Ann_Mud_Forehead_X%Last()=' , MudSystem%Ann_Mud_Forehead_X%Last()
  252. write(*,*) 'AboveAnnularHeight=' , BopStackSpecification%AboveAnnularHeight
  253. write(*,*) 'Ann_Density%Last()=' , MudSystem%Ann_Density%Last()
  254. CALL ErrorStop('error stop1')
  255. j11=j11+1
  256. endif
  257. !================================================
  258. !===============TanksToMudPump2===================
  259. if(condition17) then
  260. j12=j12+1
  261. E71=1
  262. jj12=1
  263. endif
  264. if(condition18) then
  265. j12=j12+1
  266. E72=1
  267. jj12=1
  268. endif
  269. if(condition19) then
  270. j12=j12+1
  271. E73=1
  272. jj12=1
  273. endif
  274. !================================================
  275. !===============TanksToCementPump===================
  276. if(condition20) then
  277. j13=j13+1
  278. F71=1
  279. jj13=1
  280. endif
  281. if(condition21) then
  282. j13=j13+1
  283. F72=1
  284. jj13=1
  285. endif
  286. if(condition22) then
  287. j13=j13+1
  288. F73=1
  289. jj13=1
  290. endif
  291. !================================================
  292. !===============PumpsToString===================
  293. if(condition23) then
  294. j14=j14+1
  295. G82=1
  296. endif
  297. if(condition24) then
  298. j14=j14+1
  299. G83=1
  300. endif
  301. if(condition25) then
  302. j14=j14+1
  303. G84=1
  304. endif
  305. !================================================
  306. !===============PumpsToDump===================
  307. if(condition26) then
  308. DumpPump1=1.0
  309. endif
  310. if(condition27) then
  311. DumpPump2=1.0
  312. endif
  313. if(condition28) then
  314. DumpCementPump=1.0
  315. endif
  316. !================================================
  317. !=======MudPumps1&2ToActiveTank_Through65&66==========
  318. if(condition29) then
  319. !write(*,*) 'condition 29'
  320. j15=j15+1
  321. H82=1.0
  322. endif
  323. if(condition30) then
  324. j15=j15+1
  325. H83=1.0
  326. endif
  327. !================================================
  328. !=======CementPumpToActiveTank_Through65==========
  329. if(condition31) then
  330. H84=1.0
  331. endif
  332. !================================================
  333. !write(*,*) 'condition32===' , condition32
  334. !============MudPump1HasNoPath===================
  335. if(MudSystem%condition32Final) then
  336. !write(*,*) 'MudPump1HasNoPath'
  337. Mp1_NoPath = 1
  338. endif
  339. !================================================
  340. !============MudPump2HasNoPath===================
  341. if(MudSystem%condition33Final) then
  342. !write(*,*) 'MudPump2HasNoPath'
  343. Mp2_NoPath = 1
  344. endif
  345. !================================================
  346. !============CementPumpHasNoPath===================
  347. if(MudSystem%condition34Final) then
  348. Cp_NoPath = 1
  349. endif
  350. !================================================
  351. !===============PathsToGauge75===================
  352. if(condition35) then !Pump1 to Gauge75
  353. j16=j16+1
  354. K82=1
  355. endif
  356. if(condition36) then !Pump2 to Gauge75
  357. j16=j16+1
  358. K83=1
  359. endif
  360. if(condition37) then !Pump3 to Gauge75
  361. j16=j16+1
  362. K84=1
  363. endif
  364. if(condition38) then !String to Gauge75
  365. j16=j16+1
  366. K79=1
  367. endif
  368. if(condition39) then !Dump to Gauge75
  369. j16=j16+1
  370. K78=1
  371. endif
  372. !================================================
  373. !write(*,*) '****j16=' , j16
  374. !===============PathsToGauge76===================
  375. if(condition40) then !Pump1 to Gauge76
  376. j17=j17+1
  377. L82=1
  378. endif
  379. if(condition41) then !Pump2 to Gauge76
  380. j17=j17+1
  381. L83=1
  382. endif
  383. if(condition42) then !Pump3 to Gauge76
  384. j17=j17+1
  385. L84=1
  386. endif
  387. if(condition43) then !String to Gauge76
  388. j17=j17+1
  389. L79=1
  390. endif
  391. if(condition44) then !Dump to Gauge76
  392. j17=j17+1
  393. L78=1
  394. endif
  395. !================================================
  396. !====Pump1-StandPipeManifoldToChokeManifold-Through ChokeLine====
  397. if(condition46) then
  398. j18=j18+1
  399. M71=1.
  400. Pump1toCh= 1.
  401. endif
  402. if(condition47) then
  403. j18=j18+1
  404. M77=1.
  405. Pump1toCh= 1.
  406. endif
  407. if(condition48) then
  408. j18=j18+1
  409. M78=1.
  410. Pump1toCh= 1.
  411. endif
  412. !=================================================================
  413. !====Pump2-StandPipeManifoldToChokeManifold-Through ChokeLine====
  414. if(condition49) then
  415. j18=j18+1
  416. M71=1.
  417. Pump2toCh= 1.
  418. endif
  419. if(condition50) then
  420. j18=j18+1
  421. M77=1.
  422. Pump2toCh= 1.
  423. endif
  424. if(condition51) then
  425. j18=j18+1
  426. M78=1.
  427. Pump2toCh= 1.
  428. endif
  429. !=================================================================
  430. !====Pump3-StandPipeManifoldToChokeManifold-Through ChokeLine====
  431. if(condition52) then
  432. j18=j18+1
  433. M71=1.
  434. Pump3toCh= 1.
  435. endif
  436. if(condition53) then
  437. j18=j18+1
  438. M77=1.
  439. Pump3toCh= 1.
  440. endif
  441. if(condition54) then
  442. j18=j18+1
  443. M78=1.
  444. Pump3toCh= 1.
  445. endif
  446. !=================================================================
  447. !===============PumpsToWell_KillLine============
  448. if(condition55) then
  449. j19=j19+1
  450. N82=1
  451. endif
  452. if(condition56) then
  453. j19=j19+1
  454. N83=1
  455. endif
  456. if(condition57) then
  457. j19=j19+1
  458. N84=1
  459. endif
  460. !================================================
  461. !===============WellToChokeLineGauge============
  462. if(condition58) then
  463. j20=j20+1
  464. endif
  465. if (j20>0) then
  466. MudSystem%WellToChokeLineGauge= .true.
  467. else
  468. MudSystem%WellToChokeLineGauge= .false.
  469. endif
  470. !================================================
  471. !============ChokeLineGaugeToTanks===============
  472. if(condition59) then
  473. j21=j21+1
  474. endif
  475. if(condition60) then
  476. j21=j21+1
  477. endif
  478. if(condition61) then
  479. j21=j21+1
  480. endif
  481. if (j21>0) then
  482. MudSystem%ChokeLineGaugeToTanks= .true.
  483. else
  484. MudSystem%ChokeLineGaugeToTanks= .false.
  485. endif
  486. !================================================
  487. end subroutine
  488. subroutine main
  489. Use GeoElements_FluidModule
  490. USE Pumps_VARIABLES
  491. USE CHOKEVARIABLES
  492. USE CDataDisplayConsoleVariables
  493. use CDrillWatchVariables
  494. use CHOKEVARIABLES
  495. use CChokeManifoldVariables
  496. use CTanksVariables
  497. Use KickVariables
  498. Use CHoistingVariables
  499. use CSimulationVariables
  500. implicit none
  501. Integer I
  502. MudSystem%MudSys_timeCounter = MudSystem%MudSys_timeCounter + 1
  503. if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
  504. MudSystem%MudSys_timeCounter= 0
  505. endif
  506. !WRITE (*,*) 'MudSys_timeCounter', MudSys_timeCounter
  507. if (PumpsSpecification%MudPump1ReliefValveIsSet==.false.) PumpsSpecification%MudPump1ReliefValvePressure=6000.
  508. if (PumpsSpecification%MudPump2ReliefValveIsSet==.false.) PumpsSpecification%MudPump2ReliefValvePressure=6000.
  509. if (PumpsSpecification%CementPumpReliefValveIsSet==.false.) PumpsSpecification%CementPumpReliefValvePressure=6000.
  510. !===========================================================================================================================
  511. !===========================================================================================================================
  512. ! >>> Should Be on Top of Other Codes <<<
  513. !ActiveTankVolume= ActiveMudVolumeGal ! update from student input
  514. !ActiveTankDensity= ActiveDensity ! update from student input
  515. !ReserveTankVolume= ReserveMudVolumeGal ! update from student input
  516. !ReserveTankDensity= ReserveDensity ! update from student input
  517. if (j7 > 0) then !ActiveTankToDump
  518. MudSystem%ActiveTankDensity= 0.
  519. MudSystem%ActiveTankVolume= 0.
  520. endif
  521. if (j8 > 0) then !TripTankToDump
  522. MudSystem%TripTankDensityCalc= 0.
  523. MudSystem%TripTankVolumeCalc= 0.
  524. endif
  525. !===========================================================================================================================
  526. !===========================================================================================================================
  527. if (j15 > 0) then !MudPumps1&2ToActiveTank_Through65&66
  528. !write(*,*) 'j15 is open'
  529. ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >>
  530. if (j2>0) Mp1Coef= 1.0
  531. if (j12>0) Mp2Coef= 1.0
  532. if (j2 /= 0 .or. j12/= 0) then
  533. MudSystem%ActiveTankDensity = (MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume+ Mp1Coef*MudSystem%Mp1Density*(PUMP(1)%Flow_Rate*MudSystem%DeltaT_Mudline/60.) + Mp2Coef*MudSystem%Mp2Density*(PUMP(2)%Flow_Rate*MudSystem%DeltaT_Mudline/60.))/ &
  534. (MudSystem%ActiveTankVolume+ Mp1Coef*(PUMP(1)%Flow_Rate*MudSystem%DeltaT_Mudline/60.) + Mp2Coef*(PUMP(2)%Flow_Rate*MudSystem%DeltaT_Mudline/60.))
  535. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ Mp1Coef*PUMP(1)%Flow_Rate*MudSystem%DeltaT_Mudline/60. + Mp2Coef*PUMP(2)%Flow_Rate*MudSystem%DeltaT_Mudline/60.
  536. !write(*,*) 'active by j15'
  537. endif
  538. MudSystem%ActiveTankVolume=min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal)
  539. !if ActiveTankVolume is higher, excess amount is dumped
  540. endif
  541. if (H84 > 0.0) then !CementPumpToCementTank_Through67
  542. if (j13>0) CpCoef= 1.0
  543. MudSystem%CementTankDensityCalc= (MudSystem%CementTankDensityCalc*MudSystem%CementTankVolumeCalc+ CpCoef*MudSystem%Mp3Density*(PUMP(3)%Flow_Rate*MudSystem%DeltaT_Mudline/60.) ) / &
  544. (MudSystem%CementTankVolumeCalc+CpCoef*(PUMP(3)%Flow_Rate*MudSystem%DeltaT_Mudline/60.))
  545. MudSystem%CementTankVolumeCalc= MudSystem%CementTankVolumeCalc+ CpCoef*(PUMP(3)%Flow_Rate*MudSystem%DeltaT_Mudline/60.)
  546. endif
  547. !===========================================================================================================================
  548. !===========================================================================================================================
  549. ! DUMP Path
  550. MudSystem%PumpsDumpVolume= MudSystem%PumpsDumpVolume+ (jj2*(1-H82)*DumpPump1*PUMP(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*PUMP(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*PUMP(3)%Flow_Rate) *MudSystem%DeltaT_Mudline/60.
  551. MudSystem%PumpsDumpFlowRate= jj2*(1-H82)*DumpPump1*PUMP(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*PUMP(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*PUMP(3)%Flow_Rate
  552. !write(*,*) 'PumpsDumpFlowRate=' , PumpsDumpFlowRate
  553. if (Hoisting%DriveType==1 .and. MudSystem%PumpsDumpFlowRate > 0.0 .and. (DumpFromKelly_Pump1 .or. DumpFromKelly_Pump2 .or. DumpFromKelly_Pump3)) then
  554. !write(*,*) 'Set_FlowFromKelly(.TRUE.)'
  555. call Activate_PumpWithKellyDisconnected()
  556. !write(*,*) 'PumpsDumpFlowRate=' , PumpsDumpFlowRate
  557. CALL Set_FlowFromKelly(min(MudSystem%PumpsDumpFlowRate/6.,100.)) ! .TRUE. before
  558. elseif (Hoisting%DriveType==1) then
  559. call Deactivate_PumpWithKellyDisconnected()
  560. CALL Set_FlowFromKelly(0.0) ! .FALSE. before
  561. !write(*,*) 'Set_FlowFromKelly(.FALSE.)'
  562. endif
  563. !write(*,*) 'DumpFromFillupHead_Pump1=' , DumpFromFillupHead_Pump1
  564. if (Hoisting%DriveType==0 .and. MudSystem%PumpsDumpFlowRate > 0.0 .and. (DumpFromTopDrive_Pump1 .or. DumpFromTopDrive_Pump2 .or. DumpFromTopDrive_Pump3)) then
  565. !write(*,*) 'Set_FlowFromKelly(.TRUE.)'
  566. call Activate_PumpWithTopdriveDisconnected()
  567. CALL Set_FlowFromKelly(min(MudSystem%PumpsDumpFlowRate/6.,100.)) ! .TRUE. before
  568. elseif (Hoisting%DriveType==0) then
  569. call Deactivate_PumpWithTopdriveDisconnected()
  570. CALL Set_FlowFromKelly(0.0) ! .FALSE. before
  571. !write(*,*) 'Set_FlowFromKelly(.FALSE.)'
  572. endif
  573. if (MudSystem%PumpsDumpFlowRate > 0.0 .and. (DumpFromFillupHead_Pump1 .or. DumpFromFillupHead_Pump2 .or. DumpFromFillupHead_Pump3)) then
  574. !call Activate_PumpWithKellyDisconnected()
  575. CALL Set_FlowFromFillupHead(min(MudSystem%PumpsDumpFlowRate/6.,100.)) ! .TRUE. before
  576. else
  577. !call Deactivate_PumpWithKellyDisconnected()
  578. CALL Set_FlowFromFillupHead(0.0) ! .FALSE. before
  579. endif
  580. !####C_Program -----> DriveType =
  581. ! = 0 TopDrive_DriveType
  582. ! = 1 Kelly_DriveType
  583. !===========================================================================================================================
  584. !===========================================================================================================================
  585. ! ****** Calculating Maximum Working Pressure
  586. if (PumpsSpecification%MudPump1ReliefValveIsSet) then
  587. MaxWorkingPressure1= PumpsSpecification%MudPump1ReliefValvePressure
  588. else
  589. MaxWorkingPressure1= 6000. !psi
  590. endif
  591. if (PumpsSpecification%MudPump2ReliefValveIsSet) then
  592. MaxWorkingPressure2= PumpsSpecification%MudPump2ReliefValvePressure
  593. else
  594. MaxWorkingPressure2= 6000. !psi
  595. endif
  596. if (PumpsSpecification%CementPumpReliefValveIsSet) then
  597. MaxWorkingPressure3= PumpsSpecification%CementPumpReliefValveIsSet
  598. else
  599. MaxWorkingPressure3= 6000. !psi
  600. endif
  601. if (State1) then
  602. MaxWorkingPressure= min(MaxWorkingPressure1 , MaxWorkingPressure2 , MaxWorkingPressure3)
  603. MaxWorkingPressure1= MaxWorkingPressure
  604. MaxWorkingPressure2= MaxWorkingPressure
  605. MaxWorkingPressure3= MaxWorkingPressure
  606. endif
  607. if (State2) then
  608. MaxWorkingPressure= min(MaxWorkingPressure1 , MaxWorkingPressure2)
  609. MaxWorkingPressure1= MaxWorkingPressure
  610. MaxWorkingPressure2= MaxWorkingPressure
  611. endif
  612. if (State3) then
  613. MaxWorkingPressure= min(MaxWorkingPressure1 , MaxWorkingPressure3)
  614. MaxWorkingPressure1= MaxWorkingPressure
  615. MaxWorkingPressure3= MaxWorkingPressure
  616. endif
  617. if (State4) then
  618. MaxWorkingPressure= min(MaxWorkingPressure2 , MaxWorkingPressure3)
  619. MaxWorkingPressure2= MaxWorkingPressure
  620. MaxWorkingPressure3= MaxWorkingPressure
  621. endif
  622. ! Calculating Maximum Working Pressure ******
  623. !===========================================================================================================================
  624. !===========================================================================================================================
  625. ! ****** Blown Conditions
  626. !G: PumpsToString Coefficient
  627. !jJ2,Jj12,Jj13: TanksToMudPump Coefficient
  628. !H: Pumps To Tank_Through65 or 67 Coefficient
  629. !write(*,*) 'j12=' , j12
  630. !write(*,*) 'H83=' , H83
  631. !write(*,*) 'DumpPump2=' , DumpPump2
  632. !write(*,*) 'G83=' , G83
  633. PumpPressure1= jj2*(1-H82)*(1-DumpPump1)*G82* PressureGauges(1)
  634. PumpPressure2= jj12*(1-H83)*(1-DumpPump2)*G83* PressureGauges(1)
  635. PumpPressure3= jj13*(1-H84)*(1-DumpCementPump)*G84* PressureGauges(1)
  636. !
  637. !write(*,*) 'jj2 , H82 , DumpPump1 , G82,PresCsureGauges(1)=' , jj2 , H82 , DumpPump1 , G82,PressureGauges(1)
  638. !write(*,*) '1)PumpPressure1=' , PumpPressure1
  639. !write(*,*) 'PumpPressure2=' , PumpPressure2
  640. PumpToManifoldMudVol = 3.0 * 42.0
  641. !PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP1_Q / ConvMinToSec * dt
  642. !PumpToManifoldDeltaPDueToCompressibility = PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol)
  643. IF(Mp1_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_82 .and. MP1_Q > 0.0) then
  644. PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP1_Q / ConvMinToSec * dt
  645. PumpPressure1= PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol)
  646. write(*,*) '21)PumpPressure1=' , PumpPressure1
  647. WRITE (*,*) ' valve 1 ', Manifold%Valve(1)%Status
  648. WRITE (*,*) ' valve 4 ', Manifold%Valve(4)%Status
  649. WRITE (*,*) ' valve 6 ', Manifold%Valve(6)%Status
  650. WRITE (*,*) ' valve 7 ', Manifold%Valve(7)%Status
  651. WRITE (*,*) ' valve 8 ', Manifold%Valve(8)%Status
  652. WRITE (*,*) ' valve 9 ', Manifold%Valve(9)%Status
  653. WRITE (*,*) ' valve 13 ', Manifold%Valve(13)%Status
  654. WRITE (*,*) ' valve 68 ', Manifold%Valve(68)%Status
  655. WRITE (*,*) ' valve 69 ', Manifold%Valve(69)%Status
  656. WRITE (*,*) ' valve 48 ', Manifold%Valve(48)%Status
  657. !call DisplayOpenPathsWrite()
  658. ENDIF
  659. IF(Mp2_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_83 .and. MP2_Q > 0.0 ) then
  660. PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP2_Q / ConvMinToSec * dt
  661. PumpPressure2= PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol)
  662. write(*,*) '22)PumpPressure1=' , PumpPressure2
  663. WRITE (*,*) ' -valve 1 ', Manifold%Valve(1)%Status
  664. WRITE (*,*) ' -valve 4 ', Manifold%Valve(4)%Status
  665. WRITE (*,*) ' -valve 6 ', Manifold%Valve(6)%Status
  666. WRITE (*,*) ' -valve 7 ', Manifold%Valve(7)%Status
  667. WRITE (*,*) ' -valve 8 ', Manifold%Valve(8)%Status
  668. WRITE (*,*) ' -valve 9 ', Manifold%Valve(9)%Status
  669. WRITE (*,*) ' -valve 13 ', Manifold%Valve(13)%Status
  670. WRITE (*,*) ' -valve 68 ', Manifold%Valve(68)%Status
  671. WRITE (*,*) ' -valve 69 ', Manifold%Valve(69)%Status
  672. WRITE (*,*) ' -valve 48 ', Manifold%Valve(48)%Status
  673. !call DisplayOpenPathsWrites()
  674. ENDIF
  675. IF(Cp_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_84 .AND. MP3_Q > 0.0 ) then
  676. PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP3_Q / ConvMinToSec * dt
  677. PumpPressure3= PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol)
  678. ENDIF
  679. !*****************************************************************************
  680. !if(((Mp1_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_82) .or. ( PumpPressure1 >= MaxWorkingPressure1 ) &
  681. !.or.(J14> 0 .and. j4==0 .and. j9==0 .and. NOT(ALLOCATED(GasPocketWeight%Array)))) .and. MP1_Q > 0.0 ) then
  682. !write(*,*) ' failurrrrre '
  683. if (PumpPressure1 >= MaxWorkingPressure1 .and. MP1_Q > 0.0) then
  684. write(*,*) 'mp1,if=' , PumpPressure1 , MaxWorkingPressure1 , MP1_Q
  685. MudSystem%Pump1BlownCount = MudSystem%Pump1BlownCount + 1
  686. !if (Pump1BlownStarted == .FALSE.) then
  687. ! write(*,*) 'if (Pump1BlownStarted == .FALSE. ) then'
  688. ! Pump1BlownInTimeStep = SimulationTime + BlownThresholdInSecond
  689. ! Pump1BlownStarted = .TRUE.
  690. !endif
  691. !write(*,*) 'SimulationTime===', SimulationTime, Pump1BlownInTimeStep
  692. if(PumpsSpecification%MudPump1ReliefValveIsSet .and. MudSystem%Pump1BlownCount >= BlownThreshold) then
  693. write(*,*) 'valve 65 open, BLOWN'
  694. call ChangeValve(65, .TRUE.)
  695. PumpToManifoldCompressedMudVol= 0.0
  696. MudSystem%Pump1BlownCount = 0
  697. !Pump1BlownStarted = .FALSE.
  698. !else
  699. ! write(*,*) 'PumpPressure1= 6000 psi'
  700. ! PumpPressure1= 6000. !psi
  701. endif
  702. !else
  703. !Pump1BlownInTimeStep = 0
  704. !Pump1BlownStarted = .FALSE.
  705. !write(*,*) 'Pump1BlownStarted = .FALSE.'
  706. endif
  707. !write(*,*) ' valve 65=' , Valve(65)%Status
  708. !if(((Mp2_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_83) .or. PumpPressure2 >= MaxWorkingPressure2 &
  709. !.or.(J14> 0 .and. j4==0 .and. j9==0 .and. NOT(ALLOCATED(GasPocketWeight%Array))) ) .and. MP2_Q > 0.0 ) then
  710. if(PumpPressure2 >= MaxWorkingPressure2 .and. MP2_Q > 0.0 ) then
  711. write(*,*) 'mp2,if=' , PumpPressure2 , MaxWorkingPressure2 , MP2_Q
  712. MudSystem%Pump2BlownCount = MudSystem%Pump2BlownCount + 1
  713. !if (Pump2BlownStarted == .FALSE. ) then
  714. ! Pump2BlownInTimeStep = SimulationTime + BlownThresholdInSecond
  715. ! Pump2BlownStarted = .TRUE.
  716. !endif
  717. !if (MudPump2ReliefValveIsSet .and. SimulationTime >= Pump2BlownInTimeStep .and. Pump2BlownStarted) then
  718. if (PumpsSpecification%MudPump2ReliefValveIsSet .and. MudSystem%Pump2BlownCount >= BlownThreshold) then
  719. write(*,*) 'valve 66 open, BLOWN'
  720. call ChangeValve(66, .TRUE.)
  721. PumpToManifoldCompressedMudVol= 0.0
  722. MudSystem%Pump2BlownCount = 0
  723. !Pump2BlownInTimeStep = 0
  724. !Pump2BlownStarted = .FALSE.
  725. !else
  726. ! PumpPressure2= 6000. !psi
  727. endif
  728. !else
  729. !Pump2BlownInTimeStep = 0
  730. !Pump2BlownStarted = .FALSE.
  731. endif
  732. !if(((Cp_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_84) .or. PumpPressure3 >= MaxWorkingPressure3 &
  733. !.or.(J14> 0 .and. j4==0 .and. j9==0 .and. NOT(ALLOCATED(GasPocketWeight%Array)))) .and. MP3_Q > 0.0 ) then
  734. if(PumpPressure3 >= MaxWorkingPressure3 .and. MP3_Q > 0.0 ) then
  735. MudSystem%Pump3BlownCount = MudSystem%Pump3BlownCount + 1
  736. if (PumpsSpecification%CementPumpReliefValveIsSet .and. MudSystem%Pump3BlownCount >= BlownThreshold) then
  737. !write(*,*) 'valve 67 open, BLOWN'
  738. call ChangeValve(67, .TRUE.)
  739. PumpToManifoldCompressedMudVol= 0.0
  740. MudSystem%Pump3BlownCount = 0
  741. !else
  742. ! PumpPressure3= 6000. !psi
  743. endif
  744. !else
  745. !Pump3BlownInTimeStep = 0
  746. !Pump3BlownStarted = .FALSE.
  747. endif
  748. !write(*,*) '3)PumpPressure1=' , PumpPressure1
  749. if (PumpPressure1>= 6000.) then
  750. MudSystem%Pump1BlownCount = MudSystem%Pump1BlownCount + 1
  751. if(MudSystem%Pump1BlownCount >= BlownThreshold) then
  752. call ChangeValve(65, .TRUE.)
  753. PumpToManifoldCompressedMudVol= 0.0
  754. call Activate_Pump1Failure()
  755. MudSystem%Pump1OffFailure= .true.
  756. MudSystem%Pump1BlownCount = 0
  757. endif
  758. !else
  759. !Pump1BlownInTimeStep = 0
  760. !Pump1BlownStarted = .FALSE.
  761. endif
  762. if (PumpPressure2>= 6000.) then
  763. MudSystem%Pump2BlownCount = MudSystem%Pump2BlownCount + 1
  764. if(MudSystem%Pump2BlownCount >= BlownThreshold) then
  765. call ChangeValve(66, .TRUE.)
  766. PumpToManifoldCompressedMudVol= 0.0
  767. call Activate_Pump2Failure()
  768. MudSystem%Pump2OffFailure= .true.
  769. MudSystem%Pump2BlownCount = 0
  770. endif
  771. !else
  772. !Pump2BlownInTimeStep = 0
  773. !Pump2BlownStarted = .FALSE.
  774. endif
  775. if (PumpPressure3>= 6000.) then
  776. MudSystem%Pump3BlownCount = MudSystem%Pump3BlownCount + 1
  777. if(MudSystem%Pump3BlownCount >= BlownThreshold) then
  778. call ChangeValve(67, .TRUE.)
  779. PumpToManifoldCompressedMudVol= 0.0
  780. call Activate_Pump3Failure()
  781. MudSystem%Pump3OffFailure= .true.
  782. MudSystem%Pump3BlownCount = 0
  783. endif
  784. !else
  785. !Pump3BlownInTimeStep = 0
  786. !Pump3BlownStarted = .FALSE.
  787. endif
  788. ! Blown Conditions ********
  789. !===========================================================================================================================
  790. !===========================================================================================================================
  791. if (j9 > 0 ) then !.and. WellisNOTFull== .false.) then !WellToBellNipple
  792. !write(*,*) 'j9 is open'
  793. !MUD(7)%Q= ( Ann_Saved_MudDischarged_Volume_Final+Ann_Kick_Saved_Volume_Final - ((Qlost/60.0d0)*DeltaT_Mudline) )*60.d0/DeltaT_Mudline
  794. MUD(7)%Q= ( MudSystem%MudVolume_InjectedFromAnn + MudSystem%Ann_Kick_Saved_Volume )*60.d0/MudSystem%DeltaT_Mudline !Injected is referred only to Mud
  795. if (j4 > 0) then
  796. BellNipple_FlowCoef= 13.625/(13.625+BopStackSpecification%ChokeLineId) ! 13.625= BellNipple ID (inch)
  797. MUD(7)%Q= BellNipple_FlowCoef * MUD(7)%Q
  798. endif
  799. !total_annFlow= total_annFlow+(AnnulusFlowRateFinal/600.d0)
  800. !total_DeltaVPipe= total_DeltaVPipe + DeltaVolumePipe
  801. !write(*,*) 'total_annFlow,total_DeltaVPipe' , total_annFlow,total_DeltaVPipe
  802. if (MUD(7)%Q < 0.0 ) MUD(7)%Q= 0.0 !.or. WellisNOTFull== .true.) MUD(7)%Q= 0.0
  803. !!AnnulusFlowRateFinal: flow from string mud , DeltaVolumeOp: due to trip in
  804. !write(*,*) 'MUD(7)%Q=' , MUD(7)%Q
  805. !write(*,*) 'MudSystem%MudVolume_InjectedFromAnn-WellToBellNipple=' , MudSystem%MudVolume_InjectedFromAnn
  806. !write(*,*) 'Ann_Kick_Saved_Volume=' , Ann_Kick_Saved_Volume
  807. sys_total_injected= sys_total_injected+ MudSystem%MudVolume_InjectedFromAnn
  808. if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
  809. sys_total_injected= 0.
  810. endif
  811. !write(*,*) 'sys_total_injected=' , sys_total_injected
  812. !WellOutletDensity= Ann_Density%Last() ! (ppg) <<< in CirculationCodeSelect Code
  813. if ((MudSystem%BellNippleVolume+((MUD(7)%Q/60.)*MudSystem%DeltaT_Mudline)) /= 0.0) then
  814. MudSystem%BellNippleDensity= ((MudSystem%BellNippleDensity*MudSystem%BellNippleVolume)+(MudSystem%WellOutletDensity*(MUD(7)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%BellNippleVolume+((MUD(7)%Q/60.)*MudSystem%DeltaT_Mudline))
  815. else
  816. MudSystem%BellNippleDensity= 0.0
  817. endif
  818. !IF (WellisNOTFull== .false.) THEN ! well must be full to do this order
  819. MudSystem%BellNippleVolume= MudSystem%BellNippleVolume+ ((MUD(7)%Q/60.)*MudSystem%DeltaT_Mudline)
  820. !ENDIF
  821. VolumeToBellNipple= VolumeToBellNipple + MudSystem%BellNippleVolume
  822. !write(*,*) 'VolumeToBellNipple*****=' , VolumeToBellNipple
  823. !write(*,*) 'BellNippleVolume in j9=' , BellNippleVolume , MUD(7)%Q
  824. endif
  825. if (j9 == 0 ) then !.or. WellisNOTFull== .true.) then
  826. !write(*,*) 'WellisNOTFull=' , WellisNOTFull
  827. MUD(7)%Q=0.0 ! for normal circulation input
  828. endif
  829. if (j9 > 0) then
  830. MudSystem%WellToPitsOpen= .true.
  831. else
  832. MudSystem%WellToPitsOpen= .false.
  833. endif
  834. !===========================================================================================================================
  835. !===========================================================================================================================
  836. if (j10 > 0) then !MudBucketToBellNipple
  837. !write(*,*) 'j10 is open'
  838. !MudBucketVolume= 0.
  839. !MudBucketDensity= 0.
  840. ! MudBucketVolume gets value in DisconnectingPipe subroutine
  841. MudSystem%BellNippleVolume= MudSystem%BellNippleVolume+ MudSystem%MudBucketVolume
  842. MudSystem%BellNippleDensity= MudSystem%ActiveTankDensity
  843. MudSystem%MudBucketVolume= 0.
  844. endif
  845. !===========================================================================================================================
  846. !===========================================================================================================================
  847. if (j6 > 0) then !TripTankToActiveTank And BellNipple
  848. !write(*,*) 'j6 is open'
  849. !write(*,*) 'active by j6'
  850. MUD(6)%Q= 300. ! constant flow rate(gpm)
  851. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc - ((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline)
  852. !write(*,*) 'ActiveTankVolume before=', ActiveTankVolume
  853. if (j6 == 1 .and. D71==1) then
  854. !write(*,*) 'add to active'
  855. MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%TripTankDensityCalc*(MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))
  856. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline)
  857. !write(*,*) 'ActiveTankVolume after=', ActiveTankVolume
  858. endif
  859. if (j6 == 1 .and. D80==1) then
  860. MudSystem%BellNippleDensity= ((MudSystem%BellNippleDensity*MudSystem%BellNippleVolume)+(MudSystem%TripTankDensityCalc*(MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%BellNippleVolume+((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))
  861. MudSystem%BellNippleVolume= MudSystem%BellNippleVolume+ ((MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline)
  862. endif
  863. if (j6 == 2) then
  864. MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%TripTankDensityCalc*(0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+((0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))
  865. MudSystem%BellNippleDensity= ((MudSystem%BellNippleDensity*MudSystem%BellNippleVolume)+(MudSystem%TripTankDensityCalc*(0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%BellNippleVolume+((0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline))
  866. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline)
  867. MudSystem%BellNippleVolume= MudSystem%BellNippleVolume+ ((0.5*MUD(6)%Q/60.)*MudSystem%DeltaT_Mudline)
  868. endif
  869. MudSystem%ActiveTankVolume=min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal)
  870. !if ActiveTankVolume is higher, excess amount is dumped
  871. endif
  872. if (j6 == 0) then
  873. MUD(6)%Q=0.0
  874. endif
  875. !===========================================================================================================================
  876. !===========================================================================================================================
  877. CALL Set_FlowFromReturnLine(.false.)
  878. if (j3 > 0) then !BellNippleToPits-FullWell - must be after **WellToBellNipple(j9)**
  879. !write(*,*) 'j3 is open'
  880. !write(*,*) 'active by j3'
  881. !BellNipple flow rate= sum flow rate (well+ mudbucket+ triptank)
  882. !Well to BellNipple: BellNippleVolume
  883. !MudBucket to BellNipple: BellNippleVolume
  884. !TripTnak to BellNipple: BellNippleVolume
  885. MUD(3)%Q = (MudSystem%BellNippleVolume/MudSystem%DeltaT_Mudline)*60.d0 ! (gpm)
  886. !write(*,*) 'BellNippleVolume in j3 =' , BellNippleVolume
  887. !write(*,*) 'MUD(3)%Q =' , MUD(3)%Q
  888. call Set_FlowRate(real(100.*min(MUD(3)%Q,MudSystem%PedalMeter)/MudSystem%PedalMeter, 8)) ! for unity display
  889. unityreturn = real(100.*min(MUD(3)%Q,MudSystem%PedalMeter)/MudSystem%PedalMeter, 8)
  890. !write(*,*) 'unity return=' , real(100.*min(MUD(3)%Q,PedalMeter)/PedalMeter, 8)
  891. if (MUD(3)%Q > MudSystem%PedalMeter .and. B78==0) then
  892. MudSystem%BellNippleDumpVolume= MudSystem%BellNippleDumpVolume + ((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline - (MudSystem%PedalMeter/60.)*MudSystem%DeltaT_Mudline)
  893. !BellNippleDumpRate= MUD(3)%Q - PedalMeter
  894. CALL Set_FlowFromReturnLine(.TRUE.) ! for unity display
  895. endif
  896. !VolumeToActive = VolumeToActive + BellNippleVolume
  897. !write(*,*) 'VolumeToActive*******=' , VolumeToActive
  898. active_before= MudSystem%ActiveTankVolume
  899. MudSystem%BellNippleVolume= MudSystem%BellNippleVolume- ((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline) ! to be 0.
  900. if ( MudSystem%BellNippleDensity > 1.0) then
  901. if (j3 == 1 .and. B71==1) then !(volumes in galon)
  902. MUD(3)%Q = min(MUD(3)%Q , MudSystem%PedalMeter)
  903. !write(*,*) 'MUD(3)%Q=' , MUD(3)%Q
  904. IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN
  905. MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%BellNippleDensity*(MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))
  906. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline)
  907. !write(*,*) 'active increase bell 1=' , ((MUD(3)%Q/60.)*DeltaT_Mudline)
  908. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity > MudSystem%ActiveTankDensity) THEN
  909. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((20.8d0-MudSystem%BellNippleDensity)/(20.8d0-MudSystem%ActiveTankDensity))*((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed cutting density = 20.8 ppg
  910. !write(*,*) 'active increase bell 2=' , ((20.8d0-BellNippleDensity)/(20.8d0-ActiveTankDensity))*((MUD(3)%Q/60.d0)*DeltaT_Mudline)
  911. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity < 5.0) THEN
  912. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((2.d0-MudSystem%BellNippleDensity)/(2.d0-MudSystem%ActiveTankDensity))*((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg
  913. !write(*,*) 'active increase bell 3=' , ((2.d0-BellNippleDensity)/(2.d0-ActiveTankDensity))*((MUD(3)%Q/60.d0)*DeltaT_Mudline)
  914. ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%BellNippleDensity .and. MudSystem%BellNippleDensity <= MudSystem%ActiveTankDensity) THEN
  915. !write(*,*) ' Auto true 3'
  916. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  917. !write(*,*) 'active increase bell 4=' , ((MUD(3)%Q/60.d0)*DeltaT_Mudline)
  918. ENDIF
  919. endif
  920. if (j3 == 1 .and. B77==1) then
  921. MUD(3)%Q = min(MUD(3)%Q , MudSystem%PedalMeter)
  922. IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN
  923. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%BellNippleDensity*(MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+((MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))
  924. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline
  925. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity > MudSystem%ActiveTankDensity) THEN
  926. AddedVolumeToTank= ((20.8d0-MudSystem%BellNippleDensity)/(20.8d0-MudSystem%ActiveTankDensity))*((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  927. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  928. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  929. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity < 5.0) THEN
  930. AddedVolumeToTank= ((2.d0-MudSystem%BellNippleDensity)/(2.d0-MudSystem%ActiveTankDensity))*((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg
  931. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  932. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  933. ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%BellNippleDensity .and. MudSystem%BellNippleDensity <= MudSystem%ActiveTankDensity) THEN
  934. AddedVolumeToTank= ((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  935. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  936. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  937. ENDIF
  938. endif
  939. if (j3 == 1 .and. B78==1) then
  940. MudSystem%BellNippleDumpVolume= MudSystem%BellNippleDumpVolume+ (MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline
  941. !BellNippleDumpRate= MUD(3)%Q
  942. endif
  943. if (j3 == 2) then !78 is not allowded in this position
  944. MUD(3)%Q = min(MUD(3)%Q , MudSystem%PedalMeter)
  945. IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN
  946. MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%BellNippleDensity*(0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+((0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))
  947. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%BellNippleDensity*(0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+((0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline))
  948. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline)
  949. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ ((0.5*MUD(3)%Q/60.)*MudSystem%DeltaT_Mudline)
  950. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%BellNippleDensity > MudSystem%ActiveTankDensity) THEN
  951. AddedVolumeToTank= ((20.8d0-MudSystem%BellNippleDensity)/(20.8d0-MudSystem%ActiveTankDensity))*((0.5d0*MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  952. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  953. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank
  954. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  955. ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ActiveTankDensity) THEN
  956. AddedVolumeToTank= ((2.d0-MudSystem%BellNippleDensity)/(2.d0-MudSystem%ActiveTankDensity))*((0.5d0*MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg
  957. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  958. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank
  959. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  960. ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%BellNippleDensity .and. MudSystem%BellNippleDensity <= MudSystem%ActiveTankDensity) THEN
  961. AddedVolumeToTank= ((MUD(3)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  962. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  963. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank
  964. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  965. ENDIF
  966. endif
  967. endif !( BellNippleDensity > 1.0) then
  968. active_after= MudSystem%ActiveTankVolume
  969. active_increase = active_after - active_before
  970. total_active_increase= total_active_increase + active_increase
  971. if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
  972. total_active_increase= 0.
  973. endif
  974. !write(*,*) 'total_active_increase=' , total_active_increase
  975. !write(*,*) 'ReturnFlowRate=MUD(3)%Q= after' , MUD(3)%Q
  976. MudSystem%ReturnFlowRate = MUD(3)%Q
  977. MudSystem%TripTankVolumeCalc = min(MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal
  978. !if TripTankVolumeCalc>50 BBl, excess value(TripTankVolumeCalc-50) is dumped
  979. MudSystem%ActiveTankVolume = min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal - MudProperties%ActiveSettledContentsGal)
  980. !if ActiveTankVolume is higher, excess amount is dumped
  981. !write(*,*) 'BellNippleDensity=' , BellNippleDensity
  982. !MudWeightOut2 = BellNippleDensity !for drillwatch display
  983. !write(*,*) 'MudWeightOut2=' , MudWeightOut2
  984. !write(*,*)
  985. endif
  986. if (j3 == 0) then
  987. MUD(3)%Q=0.0 ! for normal circulation input
  988. call Set_FlowRate(0d0)
  989. endif
  990. !===========================================================================================================================
  991. !===========================================================================================================================
  992. if (j11 > 0 .and. MudSystem%MudChecked== .true.) then !BellNippleToWell-NonFullWell ( FillingWell_By_BellNipple subroutine is called for this state )
  993. !write(*,*) 'j11 is open'
  994. MudSystem%MudChecked= .false. !to be sure that well is not full after arranging muds
  995. !WellToPitsOpen = .TRUE.
  996. !BellNipple flow rate= sum flow rate (well+ mudbucket+ triptank)
  997. !Well to BellNipple: BellNippleVolume
  998. !MudBucket to BellNipple: BellNippleVolume
  999. !TripTnak to BellNipple: BellNippleVolume
  1000. MUD(8)%Q = (MudSystem%BellNippleVolume/MudSystem%DeltaT_Mudline)*60.
  1001. !write(*,*) 'MUD(8)%Q=' , MUD(8)%Q
  1002. MudSystem%BellNippleVolume= MudSystem%BellNippleVolume- ((MUD(8)%Q/60.)*MudSystem%DeltaT_Mudline) ! to be 0.
  1003. !write(*,*) 'BellNippleVolume-2nd Mode=' , BellNippleVolume
  1004. !BellNippleDensity
  1005. !
  1006. !
  1007. !BellNippleDensity , MUD(8)%Q be code gel dade beshe
  1008. !shart: j11 > 0 , MUD(8)%Q > 0.0
  1009. endif
  1010. if (j11 == 0) then
  1011. MUD(8)%Q=0.0 ! for normal circulation input
  1012. !WellToPitsOpen= .false.
  1013. endif
  1014. !===========================================================================================================================
  1015. !===========================================================================================================================
  1016. !WRITE (*,*) 'choke condition', j4, ChokeLineNOTFull
  1017. if (j4 > 0 .and. MudSystem%ChokeLineNOTFull== .false.) then !WellToChokeManifold(Through 26)
  1018. !write(*,*) 'j4 is open'
  1019. !write(*,*) 'active by j4'
  1020. !MUD(4)%Q= ( Ann_Saved_MudDischarged_Volume_Final+Ann_Kick_Saved_Volume_Final - ((Qlost/60.0d0)*DeltaT_Mudline) )*60.d0/DeltaT_Mudline
  1021. MUD(4)%Q= ( MudSystem%MudVolume_InjectedFromAnn + MudSystem%Ann_Kick_Saved_Volume )*60.d0/MudSystem%DeltaT_Mudline !Injected is referred only to Mud
  1022. !if ( WellisNOTFull== .true. ) MUD(4)%Q= 0.0
  1023. if (j9 > 0) then
  1024. ChokeLine_FlowCoef= BopStackSpecification%ChokeLineId/(13.625+BopStackSpecification%ChokeLineId) ! 13.625= BellNipple ID (inch)
  1025. MUD(4)%Q= ChokeLine_FlowCoef * MUD(4)%Q
  1026. endif
  1027. !call Log_1('MUD(4)%Q=', MUD(4)%Q)
  1028. MudSystem%ChokeOutletDensity= MudSystem%ChokeLine_Density%Last() ! <<< in CirculationCodeSelect Code
  1029. !MudWeightOut2= ChokeOutletDensity !for drillwatch display
  1030. !
  1031. !AnnulusFlowRateFinal: flow from string mud , DeltaVolumeOp: due to trip in
  1032. RealJ4= real(j4)
  1033. !C71: Active Tank C77: Trip Tank C78: ChokeManifoldDump
  1034. if ( MudSystem%BellNippleDensity > 1.0) then
  1035. ! IN ALL CONDITIONS EFFECT OF 78 IS COMPUTED BY RealJ4
  1036. if (C71==1 .and. C77==0) then !(volumes in galon) RealJ4: 1 OR 2(IF 78 IS OPEN)
  1037. IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN
  1038. MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%ChokeOutletDensity*((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))
  1039. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)
  1040. !write(*,*) 'active increase choke1=' , (((1./RealJ4)*MUD(4)%Q/60.)*DeltaT_Mudline)
  1041. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)
  1042. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity > MudSystem%ActiveTankDensity) THEN
  1043. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((20.8d0-MudSystem%ChokeOutletDensity)/(20.8d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed cutting density = 20.8 ppg
  1044. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1045. !write(*,*) 'active increase choke2=' , ((20.8d0-ChokeOutletDensity)/(20.8d0-ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*DeltaT_Mudline)
  1046. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity < 5.0) THEN
  1047. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ ((2.d0-MudSystem%ChokeOutletDensity)/(2.d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg
  1048. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1049. !write(*,*) 'active increase choke3=' ,((2.d0-ChokeOutletDensity)/(2.d0-ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*DeltaT_Mudline)
  1050. ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ChokeOutletDensity .and. MudSystem%ChokeOutletDensity <= MudSystem%ActiveTankDensity) THEN
  1051. !write(*,*) ' Auto true 3'
  1052. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1053. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1054. !write(*,*) 'active increase choke4=' , (((1.d0/RealJ4)*MUD(4)%Q/60.d0)*DeltaT_Mudline)
  1055. ENDIF
  1056. endif
  1057. if (C77==1 .and. C71==0) then !RealJ4: 1 OR 2(IF 78 IS OPEN)
  1058. IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN
  1059. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ChokeOutletDensity*((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))
  1060. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)
  1061. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)
  1062. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity > MudSystem%ActiveTankDensity) THEN
  1063. AddedVolumeToTank= ((20.8d0-MudSystem%ChokeOutletDensity)/(20.8d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1064. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  1065. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  1066. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1067. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity < 5.0) THEN
  1068. AddedVolumeToTank= ((2.d0-MudSystem%ChokeOutletDensity)/(2.d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg
  1069. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  1070. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  1071. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1072. ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ChokeOutletDensity .and. MudSystem%ChokeOutletDensity <= MudSystem%ActiveTankDensity) THEN
  1073. AddedVolumeToTank= (((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1074. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  1075. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  1076. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1077. ENDIF
  1078. endif
  1079. if (C71==1 .and. C77==1) then !RealJ4: 2 OR 3(IF 78 IS OPEN)
  1080. IF (MudProperties%ActiveAutoDensity == .FALSE.) THEN
  1081. MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%ChokeOutletDensity*((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))
  1082. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ChokeOutletDensity*((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline))
  1083. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)
  1084. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)
  1085. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)
  1086. ELSEIF (MudProperties%ActiveAutoDensity .and. MudSystem%ChokeOutletDensity > MudSystem%ActiveTankDensity) THEN
  1087. AddedVolumeToTank= ((20.8d0-MudSystem%ChokeOutletDensity)/(20.8d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1088. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  1089. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank
  1090. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  1091. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1092. ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ActiveTankDensity) THEN
  1093. AddedVolumeToTank= ((2.d0-MudSystem%ChokeOutletDensity)/(2.d0-MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg
  1094. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  1095. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank
  1096. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  1097. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1098. ELSEIF (MudProperties%ActiveAutoDensity .and. 5.0 < MudSystem%ChokeOutletDensity .and. MudSystem%ChokeOutletDensity <= MudSystem%ActiveTankDensity) THEN
  1099. AddedVolumeToTank= ((1.d0/RealJ4)*MUD(4)%Q/60.d0)
  1100. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*AddedVolumeToTank))/(MudSystem%TripTankVolumeCalc+AddedVolumeToTank)
  1101. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ AddedVolumeToTank
  1102. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ AddedVolumeToTank
  1103. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*MUD(4)%Q/60.d0)*MudSystem%DeltaT_Mudline)
  1104. ENDIF
  1105. endif
  1106. if (C71==0 .and. C77==0 .and. C78==1) then !RealJ4: 1
  1107. ! autodensity niaz nadarad
  1108. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ (((1./RealJ4)*MUD(4)%Q/60.)*MudSystem%DeltaT_Mudline)
  1109. endif
  1110. endif ! if ( BellNippleDensity > 1.0) then
  1111. MudSystem%TripTankVolumeCalc=min(MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal
  1112. !if TripTankVolumeCalc>50 BBl, excess value(TripTankVolumeCalc-50) is dumped
  1113. MudSystem%ActiveTankVolume=min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal)
  1114. !if ActiveTankVolume is higher, excess amount is dumped
  1115. endif
  1116. if (j4 == 0 .or. MudSystem%ChokeLineNOTFull== .true.) then
  1117. !Pressure_BeforeChokes=0.0 ! for normal circulation input
  1118. MUD(4)%Q=0.0 ! for CirculationCodeSelect input.
  1119. endif
  1120. if (j4 > 0) then
  1121. MudSystem%WellToChokeManifoldOpen= .true.
  1122. else
  1123. MudSystem%WellToChokeManifoldOpen= .false.
  1124. endif
  1125. !===========================================================================================================================
  1126. !===========================================================================================================================
  1127. if (j18 > 0) then !StandPipeManifoldToChokeManifold-Through ChokeLine
  1128. !write(*,*) 'j18 is open'
  1129. !write(*,*) 'active by j18'
  1130. ! STEP 1: REDUCTION FROM PUMPS STEP 1: REDUCTION FROM PUMPS STEP 1: REDUCTION FROM PUMPS (SAME TO PumpsToString LINE)
  1131. ! (NOT NEEDED)
  1132. ! STEP 2: ADD TO TANKS STEP 2: ADD TO TANKS STEP 2: ADD TO TANKS STEP 2: ADD TO TANKS (SAME TO WellToChokeManifold LINE)
  1133. !Pump1toCh: PumpsToChokeManifold Coefficient
  1134. !Jj2,Jj12,Jj13: TanksToMudPump Coefficient
  1135. !H: Pumps To Tank_Through65 or 67 Coefficient
  1136. MUD(9)%Q= jj2*(1-H82)*(1-DumpPump1)*Pump1toCh*PUMP(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*Pump2toCh*PUMP(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*Pump3toCh*PUMP(3)%Flow_Rate
  1137. Denominator_a= (jj2*(1.-H82)*(1.-DumpPump1)*Pump1toCh*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*Pump2toCh*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*Pump3toCh*PUMP(3)%Flow_Rate)
  1138. if (Denominator_a /= 0.) then
  1139. MudSystem%Density_Ch= (jj2*(1.-H82)*(1.-DumpPump1)*Pump1toCh*MudSystem%Mp1Density*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*Pump2toCh*MudSystem%Mp2Density*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*Pump3toCh*MudSystem%Mp3Density*PUMP(3)%Flow_Rate)/ &
  1140. Denominator_a
  1141. !write(*,*) 'Density_Ch=' , Density_Ch
  1142. !
  1143. ! else
  1144. !Density_Ch= 0.0
  1145. endif
  1146. RealJ18= M71+M77+M78
  1147. !C71: Active Tank C77: Trip Tank C78: ChokeManifoldDump
  1148. ! IN ALL CONDITIONS EFFECT OF 78 IS COMPUTED BY RealJ18
  1149. if (M71==1 .and. M77==0) then !(volumes in galon) RealJ18: 1 OR 2(IF 78 IS OPEN)
  1150. ! autodensity niaz nadarad
  1151. MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%Density_Ch*((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))
  1152. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)
  1153. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)
  1154. endif
  1155. if (M77==1 .and. M71==0) then !RealJ18: 1 OR 2(IF 78 IS OPEN)
  1156. ! autodensity niaz nadarad
  1157. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%Density_Ch*((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))
  1158. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)
  1159. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)
  1160. endif
  1161. if (M71==1 .and. M77==1) then !RealJ18: 2 OR 3(IF 78 IS OPEN)
  1162. ! autodensity niaz nadarad
  1163. MudSystem%ActiveTankDensity= ((MudSystem%ActiveTankDensity*MudSystem%ActiveTankVolume)+(MudSystem%Density_Ch*((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%ActiveTankVolume+(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))
  1164. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%Density_Ch*((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline))
  1165. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)
  1166. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)
  1167. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)
  1168. endif
  1169. if (M71==0 .and. M77==0 .and. M78==1) then !RealJ18: 1
  1170. ! autodensity niaz nadarad
  1171. MudSystem%ChokeManifoldDumpVolume= MudSystem%ChokeManifoldDumpVolume+ (((1./RealJ18)*MUD(9)%Q/60.)*MudSystem%DeltaT_Mudline)
  1172. endif
  1173. MudSystem%TripTankVolumeCalc=min(MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal
  1174. !if TripTankVolumeCalc>50 BBl, excess value(TripTankVolumeCalc-50) is dumped
  1175. MudSystem%ActiveTankVolume=min(MudSystem%ActiveTankVolume , MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal)
  1176. !if ActiveTankVolume is higher, excess amount is dumped
  1177. endif
  1178. if (j18 == 0) then
  1179. MUD(9)%Q=0.0
  1180. endif
  1181. !===========================================================================================================================
  1182. !===========================================================================================================================
  1183. if (j5 > 0 .and. (MudSystem%ActiveTankVolume/MudSystem%ActiveTankFloorArea) > (MudSystem%TripTankVolumeCalc/MudSystem%TripTankFloorArea)) then !ActiveTankToTripTank
  1184. ! second condition is for Utube flow
  1185. !write(*,*) 'j5 is open'
  1186. ! ActiveTankVolume/ActiveTankFloorArea... means tank height
  1187. MUD(5)%Q= 300. ! constant flow rate(gpm)
  1188. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume - ((MUD(5)%Q/60.)*MudSystem%DeltaT_Mudline)
  1189. MudSystem%TripTankVolumeCalc= MudSystem%TripTankVolumeCalc + ((MUD(5)%Q/60.)*MudSystem%DeltaT_Mudline)
  1190. MudSystem%TripTankDensityCalc= ((MudSystem%TripTankDensityCalc*MudSystem%TripTankVolumeCalc)+(MudSystem%ActiveTankDensity*(MUD(5)%Q/60.)*MudSystem%DeltaT_Mudline))/(MudSystem%TripTankVolumeCalc+((MUD(5)%Q/60.)*MudSystem%DeltaT_Mudline))
  1191. MudSystem%TripTankVolumeCalc=min(MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal
  1192. !if TripTankVolumeCalc>50, excess value(TripTankVolumeCalc-50) is dumped
  1193. endif
  1194. if (j5 == 0) then
  1195. MUD(5)%Q=0.0
  1196. endif
  1197. !===========================================================================================================================
  1198. !===========================================================================================================================
  1199. if (j16 > 0) then !PathsToGauge75
  1200. if (K79 == 1) then
  1201. MudSystem%PressureGauge75= PressureGauges(1) !String to Gauge75
  1202. elseif (K82 == 1 .and. k83 == 0 .and. k84 == 0 .and. k78 == 0) then
  1203. MudSystem%PressureGauge75= PumpPressure1
  1204. elseif (K82 == 0 .and. k83 == 1 .and. k84 == 0 .and. k78 == 0) then
  1205. MudSystem%PressureGauge75= PumpPressure2
  1206. elseif (K82 == 0 .and. k83 == 0 .and. k84 == 1 .and. k78 == 0) then
  1207. MudSystem%PressureGauge75= PumpPressure3
  1208. elseif (K82 == 0 .and. k83 == 0 .and. k84 == 0 .and. k78 == 1) then
  1209. MudSystem%PressureGauge75= 0.
  1210. endif
  1211. !if (K82 == 1) PressureGauge75= PumpPressure1 !Pump1 to Gauge75'
  1212. !if (K83 == 1) PressureGauge75= PumpPressure2 !Pump2 to Gauge75
  1213. !if (K84 == 1) PressureGauge75= PumpPressure3 !Pump3 to Gauge75
  1214. !if (K78 == 1) PressureGauge75= 0. !Dump to Gauge75
  1215. endif
  1216. StandPipeManifold%StandPipeGauge1= (1 - MudSystem%StandPipeGauge1Malf) * MudSystem%PressureGauge75 ! for STManifold Display
  1217. !write(*,*) 'PressureGauge75=' , PressureGauge75
  1218. !P1toSt= jj2*(1-H82)*(1-DumpPump1)*G82
  1219. !P2toSt= jj12*(1-H83)*(1-DumpPump2)*G83
  1220. !CptoSt= jj13*(1-H84)*(1-DumpCementPump)*G84
  1221. !===========================================================================================================================
  1222. !===========================================================================================================================
  1223. if (j17 > 0) then !PumpsToGauge76
  1224. if (L79 == 1) then
  1225. MudSystem%PressureGauge76= PressureGauges(1) !String to Gauge76
  1226. elseif (L82 == 1 .and. L83 == 0 .and. L84 == 0 .and. L78 == 0) then
  1227. MudSystem%PressureGauge76= PumpPressure1
  1228. elseif (L82 == 0 .and. L83 == 1 .and. L84 == 0 .and. L78 == 0) then
  1229. MudSystem%PressureGauge76= PumpPressure2
  1230. elseif (L82 == 0 .and. L83 == 0 .and. L84 == 1 .and. L78 == 0) then
  1231. MudSystem%PressureGauge76= PumpPressure3
  1232. elseif (L82 == 0 .and. L83 == 0 .and. L84 == 0 .and. L78 == 1) then
  1233. MudSystem%PressureGauge76= 0.
  1234. endif
  1235. !if (L79 == 1) PressureGauge76= PressureGauges(1) !String to Gauge76
  1236. !if (L82 == 1) PressureGauge76= PumpPressure1 !Pump1 to Gauge76
  1237. !if (L83 == 1) PressureGauge76= PumpPressure2 !Pump2 to Gauge76
  1238. !if (L84 == 1) PressureGauge76= PumpPressure3 !Pump3 to Gauge76
  1239. !if (L78 == 1) PressureGauge76= 0. !Dump to Gauge76
  1240. endif
  1241. StandPipeManifold%StandPipeGauge2= (1 - MudSystem%StandPipeGauge2Malf) * MudSystem%PressureGauge76 ! for STManifold Display
  1242. !===========================================================================================================================
  1243. !===========================================================================================================================
  1244. !
  1245. !if (PressureGauge75 == PressureGauges(1)) then ! means: 75 goes to string
  1246. ! PumpPressureDW= PressureGauges(1) !for DrillWatch Display
  1247. ! CALL Set_StandPipePressure(real(PressureGauges(1) , 8)) !for Data Display Console
  1248. !endif
  1249. !
  1250. !
  1251. !if (PressureGauge76 == PressureGauges(1)) then ! means: 76 goes to string
  1252. ! PumpPressureDW= PressureGauges(1) !for DrillWatch Display
  1253. ! CALL Set_StandPipePressure(real(PressureGauges(1) , 8)) !for Data Display Console
  1254. !endif
  1255. !
  1256. !if (PressureGauge75 /= PressureGauges(1) .and. PressureGauge76 /= PressureGauges(1)) then ! means: non of gauges go to string
  1257. ! PumpPressureDW= max(PressureGauge75,PressureGauge76) !for DrillWatch Display
  1258. ! !StandPipePressureGauge= max(PressureGauge75,PressureGauge76) !for Data Display Console
  1259. ! CALL Set_StandPipePressure(real(max(PressureGauge75,PressureGauge76) , 8)) !for Data Display Console
  1260. !endif
  1261. !write(*,*) 'TapSelector=' , TapSelector
  1262. if (StudentStation%TapSelector == .false.) then
  1263. DrillingWatch%PumpPressure= MudSystem%PressureGauge75 !for DrillWatch Display
  1264. CALL Set_StandPipePressure(real((1-MudSystem%DrillPipePressureMalf)*MudSystem%PressureGauge75 , 8)) !for Data Display Console
  1265. else
  1266. DrillingWatch%PumpPressure= MudSystem%PressureGauge76 !for DrillWatch Display
  1267. CALL Set_StandPipePressure(real((1-MudSystem%DrillPipePressureMalf)*MudSystem%PressureGauge76 , 8)) !for Data Display Console
  1268. endif
  1269. !===========================================================================================================================
  1270. !===========================================================================================================================
  1271. ! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem
  1272. if (j2 > 0) then !TanksToMudPump1
  1273. !Relief= 0: deactive 1: active PUMP(1)%Flow_Rate , PUMP(2)%Flow_Rate
  1274. RealJ2= real(j2)
  1275. if (A71==1 .and. (MudSystem%ActiveTankVolume-(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then
  1276. A71= 0
  1277. RealJ2= RealJ2-1
  1278. write(*,*) 'ActiveTank Level Warning'
  1279. call Activate_ActiveTankUnderVolume()
  1280. endif
  1281. if (A72==1 .and. (MudSystem%ReserveTankVolume-(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then
  1282. A72= 0
  1283. RealJ2= RealJ2-1
  1284. write(*,*) 'ReserveTank Level Warning'
  1285. endif
  1286. if (A71==3 .and. (MudSystem%CementTankVolumeCalc-(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then
  1287. A73= 0
  1288. RealJ2= RealJ2-1
  1289. write(*,*) 'CementTank Level Warning'
  1290. endif
  1291. if(RealJ2> 0.0) then
  1292. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume- A71*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1293. MudSystem%ReserveTankVolume= MudSystem%ReserveTankVolume- A72*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1294. MudSystem%CementTankVolumeCalc= MudSystem%CementTankVolumeCalc- A73*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1295. !write(*,*) 'Active-decline=' , A71*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*DeltaT_Mudline)
  1296. total_decrease= total_decrease+ A71*(((1./RealJ2)*PUMP(1)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1297. if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
  1298. total_decrease= 0.
  1299. endif
  1300. !write(*,*) 'total_decrease=' , total_decrease
  1301. MudSystem%Mp1Density= (A71*MudSystem%ActiveTankDensity+A72*MudSystem%ReserveTankDensity+A73*MudSystem%CementTankDensityCalc)/RealJ2
  1302. else
  1303. write(*,*) 'stop'
  1304. endif
  1305. endif
  1306. !===========================================================================================================================
  1307. !===========================================================================================================================
  1308. ! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem
  1309. if (j12 > 0) then !TanksToMudPump2
  1310. !Relief= 0: deactive 1: active PUMP(1)%Flow_Rate , PUMP(2)%Flow_Rate
  1311. RealJ12= real(J12)
  1312. if (E71==1 .and. (MudSystem%ActiveTankVolume-(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then
  1313. E71= 0
  1314. RealJ12= RealJ12-1
  1315. write(*,*) 'ActiveTank Level Warning'
  1316. endif
  1317. if (E72==1 .and. (MudSystem%ReserveTankVolume-(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then
  1318. E72= 0
  1319. RealJ12= RealJ12-1
  1320. write(*,*) 'ReserveTank Level Warning'
  1321. endif
  1322. if (E71==3 .and. (MudSystem%CementTankVolumeCalc-(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then
  1323. E73= 0
  1324. RealJ12= RealJ12-1
  1325. write(*,*) 'CementTank Level Warning'
  1326. endif
  1327. if(RealJ12> 0.0) then
  1328. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume- E71*(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1329. MudSystem%ReserveTankVolume= MudSystem%ReserveTankVolume- E72*(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1330. MudSystem%CementTankVolumeCalc= MudSystem%CementTankVolumeCalc- E73*(((1/RealJ12)*PUMP(2)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1331. MudSystem%Mp2Density= (E71*MudSystem%ActiveTankDensity+E72*MudSystem%ReserveTankDensity+E73*MudSystem%CementTankDensityCalc)/RealJ12
  1332. else
  1333. write(*,*) 'stop'
  1334. endif
  1335. endif
  1336. !===========================================================================================================================
  1337. !===========================================================================================================================
  1338. ! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem
  1339. if (j13 > 0) then !TanksToCementPump
  1340. !Relief= 0: deactive 1: active PUMP(1)%Flow_Rate , PUMP(2)%Flow_Rate
  1341. RealJ13= real(J13)
  1342. if (F71==1 .and. (MudSystem%ActiveTankVolume-(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then
  1343. F71= 0
  1344. RealJ13= RealJ13-1
  1345. write(*,*) 'ActiveTank Level Warning'
  1346. endif
  1347. if (F72==1 .and. (MudSystem%ReserveTankVolume-(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then
  1348. F72= 0
  1349. RealJ13= RealJ13-1
  1350. write(*,*) 'ReserveTank Level Warning'
  1351. endif
  1352. if (F71==3 .and. (MudSystem%CementTankVolumeCalc-(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)) < 0.0) then
  1353. F73= 0
  1354. RealJ13= RealJ13-1
  1355. write(*,*) 'CementTank Level Warning'
  1356. endif
  1357. if(RealJ13> 0.0) then
  1358. MudSystem%ActiveTankVolume= MudSystem%ActiveTankVolume- F71*(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1359. MudSystem%ReserveTankVolume= MudSystem%ReserveTankVolume- F72*(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1360. MudSystem%CementTankVolumeCalc= MudSystem%CementTankVolumeCalc- F73*(((1/RealJ13)*PUMP(3)%Flow_Rate/60.)*MudSystem%DeltaT_Mudline)
  1361. MudSystem%Mp3Density= (F71*MudSystem%ActiveTankDensity+F72*MudSystem%ReserveTankDensity+F73*MudSystem%CementTankDensityCalc)/RealJ13
  1362. else
  1363. write(*,*) 'stop'
  1364. endif
  1365. endif
  1366. !===========================================================================================================================
  1367. !===========================================================================================================================
  1368. ! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem
  1369. if (j14 > 0) then !PumpsToString Suction_Density_MudSystem is used for Mud Circulation Code
  1370. !write(*,*) 'j14 is open'
  1371. !call Log_1('j14 is open')
  1372. ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >>
  1373. ! pump flow rate1 be sharti be samte string miravad ke masire j2 bar gharar bashad
  1374. ! pump flow rate2 be sharti be samte string miravad ke masire j12 bar gharar bashad
  1375. ! pump flow rate3 be sharti be samte string miravad ke masire j13 bar gharar bashad
  1376. !G: PumpsToString Coefficient
  1377. !Jj2,Jj12,Jj13: TanksToMudPump Coefficient
  1378. !H: Pumps To Tank_Through65 or 67 Coefficient
  1379. !
  1380. !write(*,*) 'jj2=' , jj2
  1381. !write(*,*) 'jj12=' , jj12
  1382. !write(*,*) 'jj13=' , jj13
  1383. !write(*,*) 'H82=' , H82
  1384. !write(*,*) 'H83=' , H83
  1385. !write(*,*) 'H84=' , H84
  1386. !write(*,*) 'DumpPump1=' , DumpPump1
  1387. !write(*,*) 'DumpPump2=' , DumpPump2
  1388. !write(*,*) 'DumpCementPump=' , DumpCementPump
  1389. !write(*,*) 'G82=' , G82
  1390. !write(*,*) 'G83=' , G83
  1391. !write(*,*) 'G84=' , G84
  1392. !write(*,*) 'Mp1Density=' , Mp1Density
  1393. !write(*,*) 'Mp2Density=' , Mp2Density
  1394. !write(*,*) 'Mp3Density=' , Mp3Density
  1395. !
  1396. !
  1397. !PumpsDumpVolume= PumpsDumpVolume+ jj2*(1-H82)*DumpPump1*PUMP(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*PUMP(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*PUMP(3)%Flow_Rate
  1398. Denominator= (jj2*(1.-H82)*(1.-DumpPump1)*G82*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*G83*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*G84*PUMP(3)%Flow_Rate)
  1399. if (Denominator /= 0.) then
  1400. MudSystem%Suction_Density_MudSystem= (jj2*(1.-H82)*(1.-DumpPump1)*G82*MudSystem%Mp1Density*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*G83*MudSystem%Mp2Density*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*G84*MudSystem%Mp3Density*PUMP(3)%Flow_Rate)/ &
  1401. Denominator
  1402. endif
  1403. MudSystem%CompressedMudDensity= MudSystem%Suction_Density_MudSystem
  1404. DrillingWatch%MudWeightIn= MudSystem%Suction_Density_MudSystem !for drillwatch display
  1405. MUD(2)%Q= jj2*(1-H82)*(1-DumpPump1)*G82*PUMP(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*G83*PUMP(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*G84*PUMP(3)%Flow_Rate
  1406. !write(*,*) 'MUD(2)%Q=' , MUD(2)%Q
  1407. !jj2*(1-H82)*(1-DumpPump1)*G82 :if ==1, Pump1 to String is open
  1408. !jj12*(1-H83)*(1-DumpPump2)*G83 :if ==1, Pump2 to String is open
  1409. !jj13*(1-H84)*(1-DumpCementPump)*G84 :if ==1, Cement to String is open
  1410. endif
  1411. if (j14 == 0) then ! for normal circulation input
  1412. MUD(2)%Q=0.0
  1413. !PumpPressure1= 0.0
  1414. !PumpPressure2= 0.0
  1415. !PumpPressure3= 0.0
  1416. endif
  1417. !===========================================================================================================================
  1418. !===========================================================================================================================
  1419. if (j19 > 0 .and. MudSystem%MudChecked== .true.) then !PumpsToWell_KillLine Suction_Density_PumpsToWell is used for Mud Circulation Code
  1420. !write(*,*) 'j19 is open'
  1421. MudSystem%MudChecked= .false. !to be sure that well is not full after arranging muds
  1422. ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >>
  1423. ! pump flow rate1 be sharti be samte well miravad ke masire j2 bar gharar bashad
  1424. ! pump flow rate2 be sharti be samte well miravad ke masire j12 bar gharar bashad
  1425. ! pump flow rate3 be sharti be samte well miravad ke masire j13 bar gharar bashad
  1426. !G: PumpsToString Coefficient
  1427. !Jj2,Jj12,Jj13: TanksToMudPump Coefficient
  1428. !H: Pumps To Tank_Through65 or 67 Coefficient
  1429. !
  1430. !write(*,*) 'jj2=' , jj2
  1431. !write(*,*) 'jj12=' , jj12
  1432. !write(*,*) 'jj13=' , jj13
  1433. !write(*,*) 'H82=' , H82
  1434. !write(*,*) 'H83=' , H83
  1435. !write(*,*) 'H84=' , H84
  1436. !write(*,*) 'DumpPump1=' , DumpPump1
  1437. !write(*,*) 'DumpPump2=' , DumpPump2
  1438. !write(*,*) 'DumpCementPump=' , DumpCementPump
  1439. !write(*,*) 'G82=' , G82
  1440. !write(*,*) 'G83=' , G83
  1441. !write(*,*) 'G84=' , G84
  1442. !write(*,*) 'Mp1Density=' , Mp1Density
  1443. !write(*,*) 'Mp2Density=' , Mp2Density
  1444. !write(*,*) 'Mp3Density=' , Mp3Density
  1445. !
  1446. !
  1447. !PumpsDumpVolume= PumpsDumpVolume+ jj2*(1-H82)*DumpPump1*PUMP(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*PUMP(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*PUMP(3)%Flow_Rate
  1448. Denominator= (jj2*(1.-H82)*(1.-DumpPump1)*N82*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*N83*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*N84*PUMP(3)%Flow_Rate)
  1449. if (Denominator /= 0.) then
  1450. MudSystem%Suction_Density_PumpsToWell= (jj2*(1.-H82)*(1.-DumpPump1)*N82*MudSystem%Mp1Density*PUMP(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*N83*MudSystem%Mp2Density*PUMP(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*N84*MudSystem%Mp3Density*PUMP(3)%Flow_Rate)/ &
  1451. Denominator
  1452. endif
  1453. MUD(10)%Q= jj2*(1-H82)*(1-DumpPump1)*N82*PUMP(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*N83*PUMP(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*N84*PUMP(3)%Flow_Rate
  1454. endif
  1455. if (j19 == 0) then ! for normal circulation input
  1456. MUD(10)%Q=0.0
  1457. !PumpPressure1= 0.0
  1458. !PumpPressure2= 0.0
  1459. !PumpPressure3= 0.0
  1460. endif
  1461. !===========================================================================================================================
  1462. !===========================================================================================================================
  1463. !AnnulusFlowRateFinal = 0.d0 ! this is a reset for calculated flow rate in UTUBES,TRIPIN,TRIPOUT codes
  1464. !!======================================================================
  1465. !! Well Head Condition Determination
  1466. !!======================================================================
  1467. if ( MudSystem%WellToChokeManifoldOpen .or. MudSystem%WellToPitsOpen) then
  1468. MudSystem%WellHeadIsOpen= .true.
  1469. else
  1470. MudSystem%WellHeadIsOpen= .false.
  1471. endif
  1472. !!======================================================================
  1473. !! WARNINGS
  1474. !!======================================================================
  1475. IF (Manifold%Valve(65)%Status == .TRUE.) call Activate_Pump1PopOffValveBlown() !Pump1PopOffValveBlown= .TRUE.
  1476. IF (Manifold%Valve(66)%Status == .TRUE.) call Activate_Pump2PopOffValveBlown() ! Pump2PopOffValveBlown= .TRUE.
  1477. IF (Manifold%Valve(67)%Status == .TRUE.) call Activate_Pump3PopOffValveBlown() !Pump2PopOffValveBlown= .TRUE.
  1478. IF (MudSystem%ActiveTankVolume >= (MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal)) THEN
  1479. MudSystem%ActiveTankVolume = (MudProperties%ActiveTotalTankCapacityGal-MudProperties%ActiveSettledContentsGal)
  1480. call Activate_ActiveTankOverflow()
  1481. ELSE
  1482. call Deactivate_ActiveTankOverflow()
  1483. ENDIF
  1484. !!======================================================================
  1485. !! UPDATING TANKS DENSITIES & Volumes FOR MUD CIRCULATION
  1486. !!======================================================================
  1487. !write(*,*) 'ReserveTankVolume=' , real(ReserveTankVolume)
  1488. call Set_ActiveMudVolume_StudentStation(real(MudSystem%ActiveTankVolume/42.,8)) ! 42: gal to bbl
  1489. call Set_ActiveDensity_StudentStation(real(MudSystem%ActiveTankDensity,8))
  1490. call Set_ReserveMudVolume_StudentStation(real(MudSystem%ReserveTankVolume/42.,8)) ! 42: gal to bbl
  1491. call Set_ReserveDensity_StudentStation(real(MudSystem%ReserveTankDensity,8))
  1492. DrillingWatch%KillMudVolume= MudSystem%ReserveTankVolume/42. ! for DrillWatch
  1493. !PitGainLose=
  1494. !!======================================================================
  1495. !! DRILLING DATA DISPLAY
  1496. !!======================================================================
  1497. IF (DataDisplayConsole%TotalStrokeCounterResetSwitch == 1) then !for drilling data display
  1498. MudSystem%TotalStrokesPump1=0.
  1499. MudSystem%TotalStrokesPump2=0.
  1500. ENDIF
  1501. MudSystem%TotalStrokesPump1=MudSystem%TotalStrokesPump1+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline !for drilling data display
  1502. MudSystem%TotalStrokesPump2=MudSystem%TotalStrokesPump2+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline !for drilling data display
  1503. MudSystem%GraphTotalStrokes=MudSystem%GraphTotalStrokes+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline
  1504. MPumps%Total_Stroke_Counter_For_Plot = MPumps%Total_Stroke_Counter_For_Plot + ((DataDisplayConsole%MP1SPMGauge + DataDisplayConsole%MP2SPMGauge) / 60.0) * MudSystem%DeltaT_Mudline
  1505. CALL SetTotalStrokes(INT(MPumps%Total_Stroke_Counter_For_Plot))
  1506. DataDisplayConsole%TotalStrokeCounter= real(nint(MudSystem%TotalStrokesPump1+MudSystem%TotalStrokesPump2)) !for drilling data display
  1507. !===========================================================================
  1508. ! MUD PUMP STROKES
  1509. ! & TOTAL STROKE- CHOKE CONTROL PANEL
  1510. !===========================================================================
  1511. !write(*,*) 'a)))' , ChokePanelStrokeResetSwitch
  1512. if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
  1513. IF (ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN
  1514. !write(*,*) '1 reset'
  1515. Choke%TotalStrokes1 =0.
  1516. elseif (ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN
  1517. !write(*,*) '2 reset'
  1518. Choke%TotalStrokes2 =0.
  1519. else
  1520. !write(*,*) 'both reset'
  1521. Choke%TotalStrokes1 =0.
  1522. Choke%TotalStrokes2 =0.
  1523. endif
  1524. endif
  1525. !write(*,*) 'b)))' , ChokePanelStrokeResetSwitch
  1526. Choke%TotalStrokes1= Choke%TotalStrokes1+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline
  1527. Choke%TotalStrokes2= Choke%TotalStrokes2+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline
  1528. IF (ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN
  1529. ChokeControlPanel%ChokePanelSPMCounter = real(nint(DataDisplayConsole%MP1SPMGauge))
  1530. ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(Choke%TotalStrokes1))
  1531. ELSEIF (ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN
  1532. ChokeControlPanel%ChokePanelSPMCounter = real(nint(DataDisplayConsole%MP2SPMGauge))
  1533. ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(Choke%TotalStrokes2))
  1534. ELSE
  1535. ChokeControlPanel%ChokePanelSPMCounter= real(nint(DataDisplayConsole%MP1SPMGauge+DataDisplayConsole%MP2SPMGauge))
  1536. ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(Choke%TotalStrokes1+Choke%TotalStrokes2))
  1537. ENDIF
  1538. ! ChokePanelStrokeResetSwitch = 0
  1539. !======================================================================
  1540. !!======================================================================
  1541. !! MUD VOLUME TOTALIZER DISPLAY VALUES
  1542. !!======================================================================
  1543. DrillingWatch%PitVolume= MudSystem%ActiveTankVolume/42.d0 !(bbl) For DrillWatch Display
  1544. !write(*,*) 'PitVolume,ActiveTankVolume=' ,PitVolume,ActiveTankVolume
  1545. MudSystem%MudTank1_vol= MudSystem%ActiveTankVolume/3. ! (gal)
  1546. MudSystem%MudTank2_vol= MudSystem%ActiveTankVolume/3. ! (gal)
  1547. MudSystem%MudTank3_vol= MudSystem%ActiveTankVolume/3. ! (gal)
  1548. MudSystem%MudTank4_vol= MudSystem%TripTankVolumeCalc
  1549. IF (DataDisplayConsole%MVTPowerSwitch==1) THEN
  1550. DataDisplayConsole%MudTanksVolumeGauge= (1 - MudSystem%MudTanksVolumeGaugeMalf) *((MudSystem%MudTank1_vol*DataDisplayConsole%MudTank1Switch)+(MudSystem%MudTank2_vol*DataDisplayConsole%MudTank2Switch)+ &
  1551. (MudSystem%MudTank3_vol*DataDisplayConsole%MudTank3Switch)+(MudSystem%MudTank4_vol*DataDisplayConsole%MudTank4Switch)+MudSystem%ActiveTankSettled) !(gal)
  1552. ELSEIF (DataDisplayConsole%MVTPowerSwitch==0) THEN
  1553. DataDisplayConsole%MudTanksVolumeGauge= (1 - MudSystem%MudTanksVolumeGaugeMalf) *0.
  1554. ENDIF
  1555. !!======================================================================
  1556. !! MUD VOLUME TOTALIZER
  1557. !!======================================================================
  1558. ! IF (DataDisplayConsole%MVTPowerSwitch==1 .and. IsPortable==.false.) THEN
  1559. ! IF (DataDisplayConsole%MVTSetAlarmSwitch==0) THEN
  1560. ! DataDisplayConsole%PitGainLossGauge= ( ((ActiveTankVolume/42.) - RefrencePitVolume)) - PitGainLossGaugeMalf*(( ((ActiveTankVolume/42.) - RefrencePitVolume))+50) !(bbl)
  1561. ! ELSEIF (DataDisplayConsole%MVTSetAlarmSwitch==-1) THEN
  1562. ! MVT_MinVol_Allowded= PitGainLossZero+ MIN(0.,(DataDisplayConsole%MVTSetAlarmLowKnob-50))-0.1
  1563. ! DataDisplayConsole%PitGainLossGauge= MVT_MinVol_Allowded - PitGainLossGaugeMalf*(MVT_MinVol_Allowded+50)
  1564. ! ! - PitGainLossGaugeMalf*(MVT_MinVol_Allowded+50) : Malf effect
  1565. ! !PitGainLose=(MVT_MinVol_Allowded) ! DrillWatch (incorrect)
  1566. ! !RefrencePitVolume= ActiveTankVolume/42. !(bbl)
  1567. ! ELSE !(MVTSetAlarmSwitch==1)
  1568. ! MVT_MaxVol_Allowded= PitGainLossZero+ MAX(0., (DataDisplayConsole%MVTSetAlarmHighKnob-50.))+0.1
  1569. ! DataDisplayConsole%PitGainLossGauge= MVT_MaxVol_Allowded - PitGainLossGaugeMalf*(MVT_MaxVol_Allowded+50)
  1570. ! ! - PitGainLossGaugeMalf*(MVT_MaxVol_Allowded+50) : Malf effect
  1571. ! !PitGainLose=(MVT_MaxVol_Allowded) ! DrillWatch (incorrect)
  1572. ! !RefrencePitVolume= ActiveTankVolume/42. !(bbl)
  1573. ! ENDIF
  1574. ! !PitGainLossZero_Old= PitGainLossZero
  1575. ! !MVTCoarseKnob_Old= MVTCoarseKnob
  1576. ! !MVTFineKnob_Old= MVTFineKnob
  1577. ! !FirstSet_Time= .false.
  1578. ! IF ( ActiveTankVolume/42. < (RefrencePitVolume-ABS(MVT_MinVol_Allowded)) .OR. ActiveTankVolume/42. > (RefrencePitVolume+ABS(MVT_MaxVol_Allowded)) ) THEN
  1579. ! DataDisplayConsole%MVTAlarmLED = 1 !(blinking)
  1580. ! IF (DataDisplayConsole%MVTHornSwitch) THEN
  1581. ! DataDisplayConsole%Buzzer2= .TRUE.
  1582. ! ELSE
  1583. ! DataDisplayConsole%Buzzer2= .FALSE.
  1584. ! ENDIF
  1585. ! ELSE
  1586. ! DataDisplayConsole%MVTAlarmLED = 0 !(OFF)
  1587. ! DataDisplayConsole%Buzzer2= .false.
  1588. ! ENDIF
  1589. ! ELSEIF (DataDisplayConsole%MVTPowerSwitch==0) THEN
  1590. ! !MudTanksVolumeGauge= 0.
  1591. ! DataDisplayConsole%PitGainLossGauge= -50
  1592. ! DataDisplayConsole%MVTAlarmLED= 0
  1593. ! DataDisplayConsole%Buzzer2= .false.
  1594. ! ENDIF
  1595. !!======================================================================
  1596. !! RETURN CALCULATIONS
  1597. !!======================================================================
  1598. DrillingWatch%PercentFlow= (MudSystem%ReturnFlowRate/MudSystem%PedalMeter) *100. !(percent) ! for DrillWatch display
  1599. if (abs(DrillingWatch%PercentFlow - unityreturn) > 1.0) then
  1600. write(*,*) 'PercentFlow,ReturnFlowRate,PedalMeter=' , DrillingWatch%PercentFlow,MudSystem%ReturnFlowRate,MudSystem%PedalMeter
  1601. write(*,*) 'unityreturn=' , unityreturn
  1602. endif
  1603. ! ReturnFlowRate=800. set in startup as initial value
  1604. MudSystem%ReturnFlowPercent= (MudSystem%ReturnFlowRate/MudSystem%PedalMeter) *100. !(percent)
  1605. !write(*,*) 'ReturnFlowPercent,ReturnFlowRate=' , ReturnFlowPercent,ReturnFlowRate
  1606. ! if ReturnFlowRate>PedalMeter, excess value(ReturnFlowRate-PedalMeter) is dumped in the code before
  1607. !!======================================================================
  1608. !! DRILL WATCH
  1609. !!======================================================================
  1610. DrillingWatch%PitGainLose= ((MudSystem%ActiveTankVolume/42.) - MudSystem%RefrencePitVolume_DrillWatch) ! DrillWatch
  1611. !write(*,*) 'PitGainLose galon' , PitGainLose*42.
  1612. ! if (IsPortable) then
  1613. ! MVT_MinVol_Allowded= DataDisplayConsole%PitAlarmLow
  1614. ! MVT_MaxVol_Allowded= DataDisplayConsole%PitAlarmHigh
  1615. ! IF ( ActiveTankVolume/42. < (RefrencePitVolume-ABS(MVT_MinVol_Allowded)) .OR. ActiveTankVolume/42. > (RefrencePitVolume+ABS(MVT_MaxVol_Allowded)) ) THEN
  1616. ! DataDisplayConsole%MVTAlarmLED = 1 !(blinking)
  1617. ! IF (DataDisplayConsole%MVTHornSwitch) THEN
  1618. ! DataDisplayConsole%Buzzer2= .TRUE.
  1619. ! ELSE
  1620. ! DataDisplayConsole%Buzzer2= .FALSE.
  1621. ! ENDIF
  1622. ! ELSE
  1623. ! DataDisplayConsole%MVTAlarmLED = 0 !(OFF)
  1624. ! DataDisplayConsole%Buzzer2= .false.
  1625. ! ENDIF
  1626. ! endif
  1627. if (StudentStation%PitGainLossZero) then
  1628. DrillingWatch%PitGainLose= 0.d0 !DrillWatch
  1629. MudSystem%RefrencePitVolume_DrillWatch= MudSystem%ActiveTankVolume/42. !(bbl) !DrillWatch
  1630. !*********************************************
  1631. DataDisplayConsole%PitGainLossGauge= 0. !MFF Indicator
  1632. MudSystem%RefrencePitVolume= MudSystem%ActiveTankVolume/42. !(bbl) !MFF Indicator
  1633. endif
  1634. !!======================================================================
  1635. !! MUD FLOW-FILL INDICATOR
  1636. !!======================================================================
  1637. IF (DataDisplayConsole%MFFIPowerSwitch==1 ) THEN !.and. IsPortable==.false.
  1638. !====================TotalStrokes Reset and Calculate======================
  1639. if (DataDisplayConsole%MFFIResetTotalStrokes == 1) then
  1640. IF (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN
  1641. MudSystem%TotalStrokes1MFFI =0.
  1642. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN
  1643. MudSystem%TotalStrokes2MFFI =0.
  1644. else
  1645. MudSystem%TotalStrokes1MFFI =0.
  1646. MudSystem%TotalStrokes2MFFI =0.
  1647. endif
  1648. endif
  1649. MudSystem%TotalStrokes1MFFI= MudSystem%TotalStrokes1MFFI+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline
  1650. MudSystem%TotalStrokes2MFFI= MudSystem%TotalStrokes2MFFI+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline
  1651. !==================FillStrokes Reset and Calculate=========================
  1652. if (DataDisplayConsole%MFFIResetFillCounter == 1) then
  1653. IF (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN
  1654. MudSystem%TotalFillStrokes1MFFI =0.
  1655. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN
  1656. MudSystem%TotalFillStrokes2MFFI =0.
  1657. else
  1658. MudSystem%TotalFillStrokes1MFFI =0.
  1659. MudSystem%TotalFillStrokes2MFFI =0.
  1660. endif
  1661. endif
  1662. MudSystem%TotalFillStrokes1MFFI= MudSystem%TotalFillStrokes1MFFI+((DataDisplayConsole%MP1SPMGauge)/60.)*MudSystem%DeltaT_Mudline
  1663. MudSystem%TotalFillStrokes2MFFI= MudSystem%TotalFillStrokes2MFFI+((DataDisplayConsole%MP2SPMGauge)/60.)*MudSystem%DeltaT_Mudline
  1664. !===================================================================
  1665. if (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then
  1666. DataDisplayConsole%MFFITotalStrokeCounter = real(nint(MudSystem%TotalStrokes1MFFI)) !TotalStroke LED
  1667. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then
  1668. DataDisplayConsole%MFFITotalStrokeCounter = real(nint(MudSystem%TotalStrokes2MFFI)) !TotalStroke LED
  1669. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then
  1670. DataDisplayConsole%MFFITotalStrokeCounter = real(nint(MudSystem%TotalStrokes1MFFI+MudSystem%TotalStrokes2MFFI)) !TotalStroke LED
  1671. endif
  1672. IF (DataDisplayConsole%MFFIFillSPMSelectorSwitch== .false.) THEN !(spm mode)
  1673. if (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then
  1674. DataDisplayConsole%FillStrokeCounter = real(nint(DataDisplayConsole%MP1SPMGauge)) !Fill or SPM LED
  1675. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then
  1676. DataDisplayConsole%FillStrokeCounter = real(nint(DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED
  1677. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then
  1678. DataDisplayConsole%FillStrokeCounter= real(nint(DataDisplayConsole%MP1SPMGauge+DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED
  1679. endif
  1680. ELSE ! (MFFIFillSPMSelectorSwitch== .true.) then !(fill mode)
  1681. if (MudSystem%ReturnFlowRate== 0) then
  1682. if (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then
  1683. DataDisplayConsole%FillStrokeCounter = real(nint(MudSystem%TotalFillStrokes1MFFI)) !Fill or SPM LED
  1684. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then
  1685. DataDisplayConsole%FillStrokeCounter = real(nint(MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED
  1686. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then
  1687. DataDisplayConsole%FillStrokeCounter= real(nint(MudSystem%TotalFillStrokes1MFFI+MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED
  1688. endif
  1689. MudSystem%TotalFilledStrokesBy1MFFI = real(nint(MudSystem%TotalFillStrokes1MFFI))! for values=fix on LED after the well filled
  1690. MudSystem%TotalFilledStrokesBy2MFFI = real(nint(MudSystem%TotalFillStrokes2MFFI))! for values=fix on LED after the well filled
  1691. MudSystem%TotalFilledStrokesBy1and2MFFI= real(nint(MudSystem%TotalFillStrokes1MFFI+MudSystem%TotalFillStrokes2MFFI))! for values=fix on LED after the well filled
  1692. else !(ReturnFlowRate>0)
  1693. ! these values=fix on LED after the well filled
  1694. if (DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then
  1695. DataDisplayConsole%FillStrokeCounter = MudSystem%TotalFilledStrokesBy1MFFI !Fill or SPM LED
  1696. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then
  1697. DataDisplayConsole%FillStrokeCounter = MudSystem%TotalFilledStrokesBy2MFFI !Fill or SPM LED
  1698. elseif (DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then
  1699. DataDisplayConsole%FillStrokeCounter= MudSystem%TotalFilledStrokesBy1and2MFFI !Fill or SPM LED
  1700. endif
  1701. endif
  1702. ENDIF
  1703. !===================================================================================
  1704. if (MudSystem%ReturnFlowRate>0) then
  1705. DataDisplayConsole%MFFIPumpLED=1 !(Returns Lamp)
  1706. else
  1707. DataDisplayConsole%MFFIPumpLED=0 !(Returns Lamp)
  1708. endif
  1709. IF (DataDisplayConsole%MFFISetAlarmSwitch==0) THEN
  1710. DataDisplayConsole%ReturnMudFlowGauge= (1 - MudSystem%ReturnMudFlowGaugeMalf)*MudSystem%ReturnFlowPercent !(percent)
  1711. ELSEIF (DataDisplayConsole%MFFISetAlarmSwitch==-1) THEN
  1712. MudSystem%MFFI_MinPercent_Allowded=DataDisplayConsole%MFFISetAlarmLowKnob
  1713. DataDisplayConsole%ReturnMudFlowGauge= (1 - MudSystem%ReturnMudFlowGaugeMalf)*MudSystem%MFFI_MinPercent_Allowded
  1714. ELSE !(MFFISetAlarmSwitch==1)
  1715. MudSystem%MFFI_MaxPercent_Allowded=DataDisplayConsole%MFFISetAlarmHighKnob
  1716. DataDisplayConsole%ReturnMudFlowGauge= (1 - MudSystem%ReturnMudFlowGaugeMalf)*MudSystem%MFFI_MaxPercent_Allowded
  1717. ENDIF
  1718. IF (MudSystem%ReturnFlowPercent<MudSystem%MFFI_MinPercent_Allowded .OR. MudSystem%ReturnFlowPercent>MudSystem%MFFI_MaxPercent_Allowded) THEN
  1719. !write(*,*) 'alarm return:' , ReturnFlowRate
  1720. DataDisplayConsole%MFFIAlarmLED = 2 !(blinking)
  1721. IF (DataDisplayConsole%MFFIHornSwitch) THEN
  1722. DataDisplayConsole%Buzzer3= .true.
  1723. ELSE
  1724. DataDisplayConsole%Buzzer3= .FALSE.
  1725. ENDIF
  1726. ELSE
  1727. DataDisplayConsole%MFFIAlarmLED = 0 !(OFF)
  1728. DataDisplayConsole%Buzzer3= .false.
  1729. ENDIF
  1730. !===================================================================================
  1731. ELSEIF (DataDisplayConsole%MFFIPowerSwitch==0) THEN
  1732. DataDisplayConsole%ReturnMudFlowGauge= 0.
  1733. DataDisplayConsole%FillStrokeCounter= 0
  1734. DataDisplayConsole%MFFITotalStrokeCounter= 0
  1735. DataDisplayConsole%MFFIAlarmLED= 0
  1736. DataDisplayConsole%Buzzer3= .false.
  1737. ENDIF
  1738. ! if ( IsPortable ) then
  1739. ! MFFI_MinPercent_Allowded=DataDisplayConsole%RetFlowAlarmLow
  1740. ! MFFI_MaxPercent_Allowded=DataDisplayConsole%RetFlowAlarmHigh
  1741. ! IF (ReturnFlowPercent<MFFI_MinPercent_Allowded .OR. ReturnFlowPercent>MFFI_MaxPercent_Allowded) THEN
  1742. ! DataDisplayConsole%MFFIAlarmLED = 1 !(blinking)
  1743. ! IF (DataDisplayConsole%MFFIHornSwitch) THEN
  1744. ! DataDisplayConsole%Buzzer3= .true.
  1745. ! ELSE
  1746. ! DataDisplayConsole%Buzzer3= .FALSE.
  1747. ! ENDIF
  1748. ! ELSE
  1749. ! DataDisplayConsole%MFFIAlarmLED = 0 !(OFF)
  1750. ! DataDisplayConsole%Buzzer3= .false.
  1751. ! ENDIF
  1752. ! endif
  1753. !!======================================================================
  1754. !! TRIP TANK PANEL DISPLAY VALUES
  1755. !!======================================================================
  1756. Tank%TripTankVolume = MudSystem%TripTankVolumeCalc/42. !(Drill Watch display)
  1757. Tank%TripTankDensity= MudSystem%TripTankDensityCalc !(display)
  1758. IF (DataDisplayConsole%TripTankPowerSwitch==1 ) THEN !.and. IsPortable==.false.
  1759. IF (DataDisplayConsole%TripTankSetAlarmSwitch==0) THEN
  1760. DataDisplayConsole%TripTankGauge= (1 - MudSystem%TripTankPressure_DataDisplayMalf) * MudSystem%TripTankVolumeCalc ! (gal)
  1761. ELSEIF (DataDisplayConsole%TripTankSetAlarmSwitch==-1) THEN
  1762. MudSystem%TripTank_MinVol_Allowded= DataDisplayConsole%TripTankSetAlarmLow/2. ! 2: because knob input is 0-100 but gauge is 0-50
  1763. DataDisplayConsole%TripTankGauge= (1 - MudSystem%TripTankPressure_DataDisplayMalf) * MudSystem%TripTank_MinVol_Allowded
  1764. ELSE !(TripTankSetAlarmSwitch==1)
  1765. MudSystem%TripTank_MaxVol_Allowded= DataDisplayConsole%TripTankSetAlarmHigh/2. ! 2: because knob input is 0-100 but gauge is 0-50
  1766. DataDisplayConsole%TripTankGauge= (1 - MudSystem%TripTankPressure_DataDisplayMalf) * MudSystem%TripTank_MaxVol_Allowded
  1767. ENDIF
  1768. IF ((MudSystem%TripTankVolumeCalc < MudSystem%TripTank_MinVol_Allowded) .OR. (MudSystem%TripTankVolumeCalc > MudSystem%TripTank_MaxVol_Allowded)) THEN
  1769. DataDisplayConsole%TripTankAlarmLED = 2 !(blinking)
  1770. IF (DataDisplayConsole%TripTankHornSwitch) THEN
  1771. DataDisplayConsole%Buzzer1= .true.
  1772. ELSE
  1773. DataDisplayConsole%Buzzer1= .false.
  1774. ENDIF
  1775. ELSE
  1776. DataDisplayConsole%TripTankAlarmLED = 0 !(OFF)
  1777. DataDisplayConsole%Buzzer1= .false.
  1778. ENDIF
  1779. DataDisplayConsole%TripTankPumpLED= DataDisplayConsole%TripTankPumpSwitch
  1780. ELSEIF (DataDisplayConsole%TripTankPowerSwitch==0) THEN
  1781. DataDisplayConsole%TripTankGauge= 0. !(gal)
  1782. DataDisplayConsole%TripTankAlarmLED= 0
  1783. DataDisplayConsole%TripTankPumpLED= 0
  1784. DataDisplayConsole%Buzzer1= .false.
  1785. ENDIF
  1786. ! if ( IsPortable ) then
  1787. ! TripTank_MinVol_Allowded= DataDisplayConsole%TripAlarmLow
  1788. ! TripTank_MaxVol_Allowded= DataDisplayConsole%TripAlarmHigh
  1789. ! IF ((TripTankVolumeCalc < TripTank_MinVol_Allowded) .OR. (TripTankVolumeCalc > TripTank_MaxVol_Allowded)) THEN
  1790. ! DataDisplayConsole%TripTankAlarmLED = 1 !(blinking)
  1791. ! IF (DataDisplayConsole%TripTankHornSwitch) THEN
  1792. ! DataDisplayConsole%Buzzer1= .true.
  1793. ! ELSE
  1794. ! DataDisplayConsole%Buzzer1= .false.
  1795. ! ENDIF
  1796. ! ELSE
  1797. ! DataDisplayConsole%TripTankAlarmLED = 0 !(OFF)
  1798. ! DataDisplayConsole%Buzzer1= .false.
  1799. ! ENDIF
  1800. ! endif
  1801. !write(*,*) '====================================================================='
  1802. ! if (IsStopped) return
  1803. end subroutine main
  1804. !===================================================================================================================
  1805. !===================================================================================================================
  1806. !===================================================================================================================
  1807. subroutine ActiveMudVolumeChanged(v)
  1808. !use CLog4
  1809. implicit none
  1810. real(8), intent (in) :: v
  1811. !call Log_4('ActiveMudVolumeChanged=', v)
  1812. MudSystem%ActiveTankVolume= MudProperties%ActiveMudVolumeGal ! update from student input
  1813. end subroutine
  1814. subroutine ActiveDensityChanged(v)
  1815. !use CLog4
  1816. implicit none
  1817. real(8), intent (in) :: v
  1818. !call Log_4('ActiveDensityChanged=', v)
  1819. MudSystem%ActiveTankDensity= MudProperties%ActiveDensity ! update from student input
  1820. end subroutine
  1821. subroutine ReserveMudVolumeChanged(v)
  1822. !use CLog4
  1823. implicit none
  1824. real(8), intent (in) :: v
  1825. !call Log_4('ReserveMudVolumeChanged=', v)
  1826. MudSystem%ReserveTankVolume= MudProperties%ReserveMudVolumeGal ! update from student input
  1827. end subroutine
  1828. subroutine ReserveDensityChanged(v)
  1829. !use CLog4
  1830. implicit none
  1831. real(8), intent (in) :: v
  1832. !call Log_4('ReserveDensityChanged=', v)
  1833. MudSystem%ReserveTankDensity= MudProperties%ReserveDensity ! update from student input
  1834. end subroutine
  1835. subroutine SetupMudSystem()
  1836. use CPathChangeEvents
  1837. use CMudPropertiesVariables
  1838. implicit none
  1839. call BeforeTraverse%Add(InitialVarsBeforePathsChanges)
  1840. call AfterTraverse%Add(AfterPathsChanges)
  1841. call OnPathOpen%Add(WhenPathOpen)
  1842. call OnActiveMudVolumeChange%Add(ActiveMudVolumeChanged)
  1843. call OnActiveDensityChange%Add(ActiveDensityChanged)
  1844. call OnReserveMudVolumeChange%Add(ReserveMudVolumeChanged)
  1845. call OnReserveDensityChange%Add(ReserveDensityChanged)
  1846. end subroutine
  1847. subroutine AfterPathsChanges()
  1848. implicit none
  1849. integer i
  1850. if(Pump1_Lasts%Length() <= 0) return
  1851. do i = 1, Pump1_Lasts%Length()
  1852. if(Pump2_Lasts%Length() <= 0) cycle
  1853. if(any(Pump2_Lasts%Array == Pump1_Lasts%Array(i))) then
  1854. State2 = .true. ! Pumps 1 & 2 have same destination
  1855. !print*, 'State2 = .true.'
  1856. endif
  1857. if(Pump3_Lasts%Length() <= 0) cycle
  1858. if(any(Pump3_Lasts%Array == Pump1_Lasts%Array(i))) then
  1859. State3 = .true. ! Pumps 1 & 3 have same destination
  1860. !print*, 'State3 = .true.'
  1861. endif
  1862. enddo
  1863. if(Pump2_Lasts%Length() <= 0) return
  1864. do i = 1, Pump2_Lasts%Length()
  1865. if(Pump3_Lasts%Length() <= 0) cycle
  1866. if(any(Pump3_Lasts%Array == Pump2_Lasts%Array(i))) then
  1867. State4 = .true. ! Pumps 2 & 3 have same destination
  1868. !print*, 'State4 = .true.'
  1869. endif
  1870. enddo
  1871. State1 = State2 .and. State3 ! Pumps 1 & 2 & 3 have same destination
  1872. !if(State1) print*, 'State1 = .true.'
  1873. end subroutine
  1874. subroutine InitialVarsBeforePathsChanges()
  1875. implicit none
  1876. condition1 = .false.
  1877. condition2 = .false.
  1878. condition3 = .false.
  1879. condition4 = .false.
  1880. condition5 = .false.
  1881. condition6 = .false.
  1882. condition7 = .false.
  1883. condition8 = .false.
  1884. condition9 = .false.
  1885. condition10 = .false.
  1886. condition11 = .false.
  1887. condition12 = .false.
  1888. condition13 = .false.
  1889. condition14 = .false.
  1890. condition15 = .false.
  1891. condition16 = .false.
  1892. condition17 = .false.
  1893. condition18 = .false.
  1894. condition19 = .false.
  1895. condition20 = .false.
  1896. condition21 = .false.
  1897. condition22 = .false.
  1898. condition23 = .false.
  1899. condition24 = .false.
  1900. condition25 = .false.
  1901. condition26 = .false.
  1902. condition27 = .false.
  1903. condition28 = .false.
  1904. condition29 = .false.
  1905. condition30 = .false.
  1906. condition31 = .false.
  1907. condition32 = .true.
  1908. condition33 = .true.
  1909. condition34 = .true.
  1910. condition35 = .false.
  1911. condition36 = .false.
  1912. condition37 = .false.
  1913. condition38 = .false.
  1914. condition39 = .false.
  1915. condition40 = .false.
  1916. condition41 = .false.
  1917. condition42 = .false.
  1918. condition43 = .false.
  1919. condition44 = .false.
  1920. condition45 = .false.
  1921. condition46 = .false.
  1922. condition47 = .false.
  1923. condition48 = .false.
  1924. condition49 = .false.
  1925. condition50 = .false.
  1926. condition51 = .false.
  1927. condition52 = .false.
  1928. condition53 = .false.
  1929. condition54 = .false.
  1930. condition55 = .false.
  1931. condition56 = .false.
  1932. condition57 = .false.
  1933. condition58 = .false.
  1934. condition59= .false.
  1935. condition60= .false.
  1936. condition61= .false.
  1937. !ThereIsPathFrom82 = .false.
  1938. !!print*, "ThereIsPathFrom82=",ThereIsPathFrom82
  1939. !ThereIsPathFrom83 = .false.
  1940. !!print*, "ThereIsPathFrom82=",ThereIsPathFrom82
  1941. !ThereIsPathFrom84 = .false.
  1942. !!print*, "ThereIsPathFrom82=",ThereIsPathFrom82
  1943. ThereIsPathFrom_71_72_73_To_82 = .false.
  1944. !print*, "ThereIsPathFrom_71_72_73_To_82=",ThereIsPathFrom_71_72_73_To_82
  1945. ThereIsPathFrom_71_72_73_To_83 = .false.
  1946. !print*, "ThereIsPathFrom_71_72_73_To_83=",ThereIsPathFrom_71_72_73_To_83
  1947. ThereIsPathFrom_71_72_73_To_84 = .false.
  1948. !print*, "ThereIsPathFrom_71_72_73_To_84=",ThereIsPathFrom_71_72_73_To_84
  1949. DumpFromKelly_Pump1 = .false.
  1950. DumpFromFillupHead_Pump1 = .false.
  1951. DumpFromTopDrive_Pump1 = .false.
  1952. DumpFromKelly_Pump2 = .false.
  1953. DumpFromFillupHead_Pump2 = .false.
  1954. DumpFromTopDrive_Pump2 = .false.
  1955. DumpFromKelly_Pump3 = .false.
  1956. DumpFromFillupHead_Pump3 = .false.
  1957. DumpFromTopDrive_Pump3 = .false.
  1958. State1 = .false.
  1959. State2 = .false.
  1960. State3 = .false.
  1961. State4 = .false.
  1962. call Pump1_Lasts%Empty()
  1963. call Pump2_Lasts%Empty()
  1964. call Pump3_Lasts%Empty()
  1965. ac32 = .false.
  1966. ac33 = .false.
  1967. ac34 = .false.
  1968. ac35 = .false.
  1969. ac29 = .false.
  1970. end subroutine
  1971. subroutine WhenPathOpen(valves)
  1972. use Pumps_VARIABLES
  1973. implicit none
  1974. integer, allocatable, intent (in) :: valves(:)
  1975. integer :: first, last
  1976. if (.not.allocated(valves)) return
  1977. if(size(valves) <= 0) return
  1978. if ( any(valves == 32)) ac32 = .true.
  1979. if ( any(valves == 33)) ac33 = .true.
  1980. if ( any(valves == 34)) ac34 = .true.
  1981. if ( any(valves == 35)) ac35 = .true.
  1982. if ( any(valves == 29)) ac29 = .true.
  1983. first = 1
  1984. last = size(valves)
  1985. MP1_Q = PUMP(1)%Flow_Rate
  1986. MP2_Q = PUMP(2)%Flow_Rate
  1987. MP3_Q = PUMP(3)%Flow_Rate
  1988. if(valves(first) == 82) call Pump1_Lasts%Add(valves(last))
  1989. if(valves(first) == 83) call Pump2_Lasts%Add(valves(last))
  1990. if(valves(first) == 84) call Pump3_Lasts%Add(valves(last))
  1991. !print*, '=============================================='
  1992. !do i = 1, Pump1_Lasts%Length()
  1993. ! print*, 'mp1=', Pump1_Lasts%Array(i)
  1994. !enddo
  1995. !
  1996. !print*, '-------------------------------'
  1997. !
  1998. !do i = 1, Pump2_Lasts%Length()
  1999. ! print*, 'mp2=', Pump2_Lasts%Array(i)
  2000. !enddo
  2001. !
  2002. !print*, '-------------------------------'
  2003. !
  2004. !
  2005. !do i = 1, Pump3_Lasts%Length()
  2006. ! print*, 'mp3=', Pump3_Lasts%Array(i)
  2007. !enddo
  2008. !
  2009. !print*, '=============================================='
  2010. !if(valves(first)==82 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71)) then
  2011. ! ThereIsPathFrom82 = .true.
  2012. ! !print*, "ThereIsPathFrom82=",ThereIsPathFrom82
  2013. !endif
  2014. !
  2015. !if(valves(first)==83 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71)) then
  2016. ! ThereIsPathFrom83 = .true.
  2017. ! !print*, "ThereIsPathFrom83=",ThereIsPathFrom83
  2018. !endif
  2019. !
  2020. !if(valves(first)==84 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71)) then
  2021. ! ThereIsPathFrom84 = .true.
  2022. ! !print*, "ThereIsPathFrom84=",ThereIsPathFrom84
  2023. !endif
  2024. if(valves(last)==82 .and. (valves(first)==71 .or. valves(first)==72 .or. valves(first)==73)) then
  2025. ThereIsPathFrom_71_72_73_To_82 = .true.
  2026. !print*, "ThereIsPathFrom_71_72_73_To_82=",ThereIsPathFrom_71_72_73_To_82
  2027. endif
  2028. if(valves(last)==83 .and. (valves(first)==71 .or. valves(first)==72 .or. valves(first)==73)) then
  2029. ThereIsPathFrom_71_72_73_To_83 = .true.
  2030. !print*, "ThereIsPathFrom_71_72_73_To_83=",ThereIsPathFrom_71_72_73_To_83
  2031. endif
  2032. if(valves(last)==84 .and. (valves(first)==71 .or. valves(first)==72 .or. valves(first)==73)) then
  2033. ThereIsPathFrom_71_72_73_To_84 = .true.
  2034. !print*, "ThereIsPathFrom_71_72_73_To_84=",ThereIsPathFrom_71_72_73_To_84
  2035. endif
  2036. !if (.not.allocated(OpenPaths)) exit
  2037. !===============TanksToMudPump1===================
  2038. if(valves(last)==82) then
  2039. if(valves(first)==71) then
  2040. !j2=j2+1
  2041. !A71=1
  2042. condition1 = .true.
  2043. endif
  2044. if(valves(first)==72) then
  2045. !j2=j2+1
  2046. !A72=1
  2047. condition2 = .true.
  2048. endif
  2049. if(valves(first)==73) then
  2050. !j2=j2+1
  2051. !A73=1
  2052. condition3 = .true.
  2053. endif
  2054. endif
  2055. !================================================
  2056. !============BellNippleToPits-FullWell(MLnumber=3)==============
  2057. if ( Manifold%Valve(41)%Status == .false. .and. Manifold%Valve(42)%Status == .false. ) then
  2058. call ChangeValve(60, .TRUE.)
  2059. else
  2060. call ChangeValve(60, .FALSE.)
  2061. endif
  2062. if(valves(first)==80 .and. valves(last)==71 .and. any(valves == 42)) condition4 = .true.
  2063. if(valves(first)==80 .and. valves(last)==77 .and. any(valves == 41)) condition5 = .true.
  2064. if(valves(first)==80 .and. valves(last)==78) condition6 = .true.
  2065. !================================================
  2066. !============WellToChokeManifold(Through 26)==============
  2067. if(valves(first)==79 .and. any(valves == 26)) then
  2068. if(valves(last)==71) then
  2069. !j4=j4+1
  2070. !C71=1.
  2071. condition7 = .true.
  2072. endif
  2073. if(valves(last)==77) then
  2074. !j4=j4+1
  2075. !C77=1.
  2076. condition8 = .true.
  2077. endif
  2078. if(valves(last)==78) then
  2079. !j4=j4+1
  2080. !C78=1.
  2081. condition45 = .true.
  2082. endif
  2083. endif
  2084. !================================================
  2085. !============ActiveTankToTripTank==============
  2086. if(valves(first)==71 .and. valves(last)==77) then
  2087. !j5=j5+1
  2088. condition9 = .true.
  2089. endif
  2090. !================================================
  2091. !============TripTankToActiveTank And BellNipple==============
  2092. if(valves(first)==77) then
  2093. if(valves(last)==71) then
  2094. !j6=j6+1
  2095. !D71=1
  2096. condition10 = .true.
  2097. endif
  2098. if(valves(last)==80) then
  2099. !j6=j6+1
  2100. !D80=1
  2101. condition11 = .true.
  2102. endif
  2103. endif
  2104. !================================================
  2105. !============ActiveTankToDump==============
  2106. if(valves(first)==71 .and. valves(last)==78) then
  2107. !j7=j7+1
  2108. condition12 = .true.
  2109. endif
  2110. !================================================
  2111. !============TripTankToDump==============
  2112. if(valves(first)==77 .and. valves(last)==78) then
  2113. !j8=j8+1
  2114. condition13 = .true.
  2115. endif
  2116. !================================================
  2117. !============WellToBellNipple==============
  2118. if(valves(first)==79 .and. valves(last)==80) then
  2119. !j9=j9+1
  2120. condition14 = .true.
  2121. endif
  2122. !================================================
  2123. !============MudBucketToBellNipple==============
  2124. if(valves(first)==81 .and. valves(last)==80) then
  2125. !j10=j10+1
  2126. condition15 = .true.
  2127. endif
  2128. !================================================
  2129. !============BellNippleToWell-NonFullWell==============
  2130. if(valves(first)==80 .and. valves(last)==79) then ! Well is NOT Full
  2131. !j11=j11+1
  2132. condition16 = .true.
  2133. endif
  2134. !================================================
  2135. !===============TanksToMudPump2===================
  2136. if(valves(last)==83) then
  2137. if(valves(first)==71) then
  2138. !j12=j12+1
  2139. !E71=1
  2140. condition17 = .true.
  2141. endif
  2142. if(valves(first)==72) then
  2143. !j12=j12+1
  2144. !E72=1
  2145. condition18 = .true.
  2146. endif
  2147. if(valves(first)==73) then
  2148. !j12=j12+1
  2149. !E73=1
  2150. condition19 = .true.
  2151. endif
  2152. endif
  2153. !================================================
  2154. !===============TanksToCementPump===================
  2155. if(valves(last)==84) then
  2156. if(valves(first)==71) then
  2157. !j13=j13+1
  2158. !F71=1
  2159. condition20 = .true.
  2160. endif
  2161. if(valves(first)==72) then
  2162. !j13=j13+1
  2163. !F72=1
  2164. condition21 = .true.
  2165. endif
  2166. if(valves(first)==73) then
  2167. !j13=j13+1
  2168. !F73=1
  2169. condition22 = .true.
  2170. endif
  2171. endif
  2172. !================================================
  2173. !===============PumpsToString===================
  2174. if(valves(last)==79) then
  2175. if(valves(first)==82) then
  2176. !j14=j14+1
  2177. !G82=1
  2178. condition23 = .true.
  2179. endif
  2180. if(valves(first)==83) then
  2181. !j14=j14+1
  2182. !G83=1
  2183. condition24 = .true.
  2184. endif
  2185. if(valves(first)==84) then
  2186. !j14=j14+1
  2187. !G84=1
  2188. condition25 = .true.
  2189. endif
  2190. endif
  2191. !================================================
  2192. !============MudPump1HasPath===================
  2193. if(ThereIsPathFrom_71_72_73_To_82 .and. (valves(first)==82 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71))) then
  2194. !Mp1_NoPath= 0
  2195. condition32 = .false.
  2196. endif
  2197. MudSystem%condition32Final = condition32
  2198. !================================================
  2199. !============MudPump2HasPath===================
  2200. if(ThereIsPathFrom_71_72_73_To_83 .and. (valves(first)==83 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71))) then
  2201. !write(*,*) 'condition33 ******'
  2202. !Mp2_NoPath= 0
  2203. condition33 = .false.
  2204. endif
  2205. MudSystem%condition33Final= condition33
  2206. !================================================
  2207. !============CementPumpHasNoPath===================
  2208. if(ThereIsPathFrom_71_72_73_To_84 .and. (valves(first)==84 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71))) then
  2209. !Cp_NoPath= 1
  2210. condition34 = .false.
  2211. endif
  2212. MudSystem%condition34Final = condition34
  2213. !================================================
  2214. !===============PumpsToDump===================
  2215. !DumpFromKelly = 0.0
  2216. !DumpFromFillupHead= 0.0
  2217. if(valves(last)==78) then
  2218. if(valves(first)==82) then
  2219. !DumpPump1=1
  2220. condition26 = .true.
  2221. IF(any(valves == 56)) DumpFromKelly_Pump1 = .true.
  2222. IF(any(valves == 14)) DumpFromFillupHead_Pump1 = .true.
  2223. IF(any(valves == 70)) DumpFromTopDrive_Pump1 = .true.
  2224. endif
  2225. if(valves(first)==83) then
  2226. !DumpPump2=1
  2227. print*, "THERE IS DUMP"
  2228. condition27 = .true.
  2229. IF(any(valves == 56)) DumpFromKelly_Pump2 = .true.
  2230. IF(any(valves == 14)) DumpFromFillupHead_Pump2 = .true.
  2231. IF(any(valves == 70)) DumpFromTopDrive_Pump2 = .true.
  2232. endif
  2233. if(valves(first)==84) then
  2234. !DumpCementPump=1
  2235. condition28 = .true.
  2236. IF(any(valves == 56)) DumpFromKelly_Pump3 = .true.
  2237. IF(any(valves == 14)) DumpFromFillupHead_Pump3 = .true.
  2238. IF(any(valves == 70)) DumpFromTopDrive_Pump3 = .true.
  2239. endif
  2240. ! DumpFromKelly
  2241. !if (DumpFromKelly_Pump1 .or. DumpFromKelly_Pump2 .or. DumpFromKelly_Pump3) then
  2242. ! DumpFromKelly = 1.0
  2243. !else
  2244. ! DumpFromKelly = 0.0
  2245. !endif
  2246. ! DumpFromFillupHead
  2247. if (DumpFromFillupHead_Pump1 .or. DumpFromFillupHead_Pump2 .or. DumpFromFillupHead_Pump3) then
  2248. DumpFromFillupHead = 1.0
  2249. else
  2250. DumpFromFillupHead = 0.0
  2251. endif
  2252. endif
  2253. !================================================
  2254. !=======MudPumps1&2ToActiveTank_Through65&66==========
  2255. ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >>
  2256. if(valves(last)==71) then
  2257. if(valves(first)==82 .and. any(valves == 65)) then
  2258. !j15=j15+1
  2259. !H82=1.0
  2260. condition29 = .true.
  2261. endif
  2262. if(valves(first)==83 .and. any(valves == 66)) then
  2263. !j15=j15+1
  2264. !H83=1.0
  2265. condition30 = .true.
  2266. endif
  2267. endif
  2268. !================================================
  2269. !=======CementPumpToCementTank_Through67==========
  2270. ! << if H82 or H83 or H4 are open, no flow goes to other parts of system >>
  2271. if(valves(last)==73 .and. valves(first)==84 .and. any(valves == 67)) then
  2272. !H84=1.0
  2273. condition31 = .true.
  2274. endif
  2275. !================================================
  2276. !===============PathsToGauge75===================
  2277. if(valves(last)==75) then
  2278. if(valves(first)==82) then !Pump1 to Gauge75
  2279. !j16=j16+1
  2280. !K82=1
  2281. condition35 = .true.
  2282. endif
  2283. if(valves(first)==83) then !Pump2 to Gauge75
  2284. !j16=j16+1
  2285. !K83=1
  2286. condition36 = .true.
  2287. endif
  2288. if(valves(first)==84) then !Pump3 to Gauge75
  2289. !j16=j16+1
  2290. !K84=1
  2291. condition37 = .true.
  2292. endif
  2293. if(valves(first)==79) then !String to Gauge75
  2294. !j16=j16+1
  2295. !K79=1
  2296. condition38 = .true.
  2297. endif
  2298. if(valves(first)==78) then !Dump to Gauge75
  2299. !j16=j16+1
  2300. !K78=1
  2301. condition39 = .true.
  2302. endif
  2303. endif
  2304. !================================================
  2305. !===============PathsToGauge76===================
  2306. if(valves(last)==76) then
  2307. if(valves(first)==82) then !Pump1 to Gauge76
  2308. !j17=j17+1
  2309. !L82=1
  2310. condition40 = .true.
  2311. endif
  2312. if(valves(first)==83) then !Pump2 to Gauge76
  2313. !j17=j17+1
  2314. !L83=1
  2315. condition41 = .true.
  2316. endif
  2317. if(valves(first)==84) then !Pump3 to Gauge76
  2318. !j17=j17+1
  2319. !L84=1
  2320. condition42 = .true.
  2321. endif
  2322. if(valves(first)==79) then !String to Gauge76
  2323. !j17=j17+1
  2324. !L79=1
  2325. condition43 = .true.
  2326. endif
  2327. if(valves(first)==78) then !Dump to Gauge76
  2328. !j17=j17+1
  2329. !L78=1
  2330. condition44 = .true.
  2331. endif
  2332. endif
  2333. !================================================
  2334. !====Pump1-StandPipeManifoldToChokeManifold-Through ChokeLine====
  2335. if(valves(first)==82 .and. any(valves == 2)) then
  2336. if(valves(last)==71) then
  2337. !j18=j18+1
  2338. !M71=1.
  2339. !Pump1toCh= 1.
  2340. condition46 = .true.
  2341. endif
  2342. if(valves(last)==77) then
  2343. !j18=j18+1
  2344. !M77=1.
  2345. !Pump1toCh= 1.
  2346. condition47 = .true.
  2347. endif
  2348. if(valves(last)==78) then
  2349. !j18=j18+1
  2350. !M78=1.
  2351. !Pump1toCh= 1.
  2352. condition48 = .true.
  2353. endif
  2354. endif
  2355. !=================================================================
  2356. !====Pump2-StandPipeManifoldToChokeManifold-Through ChokeLine====
  2357. if(valves(first)==83 .and. any(valves == 2)) then
  2358. if(valves(last)==71) then
  2359. !j18=j18+1
  2360. !M71=1.
  2361. !Pump2toCh= 1.
  2362. condition49 = .true.
  2363. endif
  2364. if(valves(last)==77) then
  2365. !j18=j18+1
  2366. !M77=1.
  2367. !Pump2toCh= 1.
  2368. condition50 = .true.
  2369. endif
  2370. if(valves(last)==78) then
  2371. !j18=j18+1
  2372. !M78=1.
  2373. !Pump2toCh= 1.
  2374. condition51 = .true.
  2375. endif
  2376. endif
  2377. !=================================================================
  2378. !====Pump3-StandPipeManifoldToChokeManifold-Through ChokeLine====
  2379. if(valves(first)==84 .and. any(valves == 2)) then
  2380. if(valves(last)==71) then
  2381. !j18=j18+1
  2382. !M71=1.
  2383. !Pump3toCh= 1.
  2384. condition52 = .true.
  2385. endif
  2386. if(valves(last)==77) then
  2387. !j18=j18+1
  2388. !M77=1.
  2389. !Pump3toCh= 1.
  2390. condition53 = .true.
  2391. endif
  2392. if(valves(last)==78) then
  2393. !j18=j18+1
  2394. !M78=1.
  2395. !Pump3toCh= 1.
  2396. condition54 = .true.
  2397. endif
  2398. endif
  2399. !=================================================================
  2400. !===============PumpsToWell_KillLine============
  2401. if(valves(last)==79) then
  2402. if(valves(first)==82) then
  2403. !j19=j19+1
  2404. !N82=1
  2405. condition55 = .true.
  2406. endif
  2407. if(valves(first)==83) then
  2408. !j19=j19+1
  2409. !N83=1
  2410. condition56 = .true.
  2411. endif
  2412. if(valves(first)==84) then
  2413. !j19=j19+1
  2414. !N84=1
  2415. condition57 = .true.
  2416. endif
  2417. endif
  2418. !================================================
  2419. !===============WellToChokeLineGauge============
  2420. if(valves(first)==79 .and. valves(last)==85) then
  2421. !j20=j20+1
  2422. condition58 = .true.
  2423. endif
  2424. !================================================
  2425. !============ChokeLineGaugeToTanks===============
  2426. if(valves(first)==85) then
  2427. if(valves(last)==71) then
  2428. !j21=j21+1
  2429. condition59 = .true.
  2430. endif
  2431. if(valves(last)==77) then
  2432. !j21=j21+1
  2433. condition60 = .true.
  2434. endif
  2435. if(valves(last)==78) then
  2436. !j21=j21+1
  2437. condition61 = .true.
  2438. endif
  2439. endif
  2440. !================================================
  2441. end subroutine
  2442. end module MudSystemModule