Simulation Core
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

3319 wiersze
162 KiB

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