Simulation Core
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

3317 lines
174 KiB

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