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

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