Simulation Core
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

3320 рядки
162 KiB

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