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

413 wiersze
19 KiB

  1. subroutine PlotFinalMudElements ! is called in subroutine CirculationCodeSelect
  2. Use GeoElements_FluidModule
  3. USE CMudPropertiesVariables
  4. USE MudSystemVARIABLES
  5. USE Pump_VARIABLES
  6. Use TD_StringConnectionData
  7. !USE CHOKEVARIABLES
  8. !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure
  9. !use CManifolds
  10. use CDrillWatchVariables
  11. !use CHOKEVARIABLES
  12. !use CChokeManifoldVariables
  13. use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity
  14. USE sROP_Other_Variables
  15. USE sROP_Variables
  16. Use KickVariables
  17. USE CKellyConnectionEnumVariables
  18. USE UTUBEVARS
  19. use CLog1
  20. Use CError
  21. Use , intrinsic :: IEEE_Arithmetic
  22. implicit none
  23. integer jelement, jmud, jsection,ielement,i
  24. integer jopelement,jopmud,jopsection
  25. character(len=120) :: temp1, temp2
  26. if (ChokePanelStrokeResetSwitch == 1) then
  27. write(*,*) 'well cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
  28. DeltaWellCap= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) - WellCapOld
  29. WellCapOld= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
  30. write(*,*) 'cap_reset,DeltaWellCap=' , DeltaWellCap
  31. endif
  32. !========================ANNULUS END=================
  33. if ((Ann_Mud_Forehead_X%Last() - AboveAnnularHeight) > 0.8 .or. Ann_Density%Last()==0.0) then ! for Line (BellNippleToWell-NonFullWell)
  34. WellisNOTFull= .true.
  35. else
  36. WellisNOTFull= .false.
  37. endif
  38. !WRITE(*,*) 'Ann_Mud_Forehead_X%Last() , KillHeight', Ann_Mud_Forehead_X%Last() , KillHeight
  39. if ((Ann_Mud_Forehead_X%Last() - KillHeight)>0.8 .or. Ann_Density%Last()==0.0) then ! for Line j4 , WellToChokeManifold(Through 26)
  40. ChokeLineNOTFull= .true.
  41. else
  42. ChokeLineNOTFull= .false.
  43. endif
  44. !=========================================================
  45. jmud= 1
  46. jsection= 1
  47. jelement= 0 ! number of final mud elements
  48. call Xend_MudElement%Empty()
  49. call TVDend_MudElement%Empty()
  50. call Density_MudElement%Empty()
  51. call MudGeoType%Empty()
  52. call PipeID_MudElement%Empty()
  53. call PipeOD_MudElement%Empty()
  54. !call Angle_MudElement%Empty()
  55. call MudType_MudElement%Empty()
  56. DO WHILE(jmud <= Hz_Mud_Forehead_X%Length() .and. jsection<=1)
  57. jelement= jelement+1
  58. TrueMinValue= min(Hz_Mud_Forehead_X%Array(jmud), Xend_PipeSection(jsection))
  59. call Xend_MudElement%Add(TrueMinValue)
  60. call TVD_Calculator(TrueMinValue,MudCircVerticalDepth)
  61. call TVDend_MudElement%Add(MudCircVerticalDepth)
  62. call Density_MudElement%Add(Hz_Density%Array(jmud))
  63. call PipeID_MudElement%Add(ID_PipeSectionInch(jsection))
  64. call PipeOD_MudElement%Add(OD_PipeSectionInch(jsection))
  65. !call Angle_MudElement%Add(Angle_PipeSection(jsection))
  66. call MudType_MudElement%Add(Hz_MudOrKick%Array(jmud))
  67. if (Xend_MudElement%Array(jelement)== Hz_Mud_Forehead_X%Array(jmud)) then
  68. jmud= jmud+1
  69. else
  70. jsection= jsection+1
  71. endif
  72. ENDDO
  73. NoHorizontalMudElements= jelement
  74. jmud= 1
  75. jsection= 2
  76. DO WHILE(jmud <= St_Mud_Forehead_X%Length() .and. jsection<=F_StringIntervalCounts)
  77. jelement= jelement+1
  78. TrueMinValue= min(St_Mud_Forehead_X%Array(jmud), Xend_PipeSection(jsection))
  79. call Xend_MudElement%Add(TrueMinValue)
  80. call TVD_Calculator(TrueMinValue,MudCircVerticalDepth)
  81. call TVDend_MudElement%Add(MudCircVerticalDepth)
  82. call Density_MudElement%Add(St_Density%Array(jmud))
  83. call PipeID_MudElement%Add(ID_PipeSectionInch(jsection))
  84. call PipeOD_MudElement%Add(OD_PipeSectionInch(jsection))
  85. !call Angle_MudElement%Add(Angle_PipeSection(jsection))
  86. call MudType_MudElement%Add(St_MudOrKick%Array(jmud))
  87. if (Xend_MudElement%Array(jelement)== St_Mud_Forehead_X%Array(jmud)) then
  88. jmud= jmud+1
  89. else
  90. jsection= jsection+1
  91. endif
  92. ENDDO
  93. NoStringMudElements= jelement- NoHorizontalMudElements
  94. jmud= 1
  95. jsection= F_StringIntervalCounts+1
  96. DO WHILE(jmud<= Ann_Mud_Forehead_X%Length() .and. jsection<=NoPipeSections)
  97. jelement= jelement+1
  98. TrueMinValue= max(Ann_Mud_Forehead_X%Array(jmud), Xend_PipeSection(jsection))
  99. call Xend_MudElement%Add(TrueMinValue)
  100. call TVD_Calculator(TrueMinValue,MudCircVerticalDepth)
  101. call TVDend_MudElement%Add(MudCircVerticalDepth)
  102. call Density_MudElement%Add(Ann_Density%Array(jmud))
  103. call PipeID_MudElement%Add(ID_PipeSectionInch(jsection))
  104. call PipeOD_MudElement%Add(OD_PipeSectionInch(jsection))
  105. !call Angle_MudElement%Add(Angle_PipeSection(jsection))
  106. call MudType_MudElement%Add(Ann_MudOrKick%Array(jmud))
  107. if (Xend_MudElement%Array(jelement)== Ann_Mud_Forehead_X%Array(jmud)) then
  108. jmud= jmud+1
  109. else
  110. jsection= jsection+1
  111. endif
  112. ENDDO
  113. do i= 2, Xend_MudElement%Length()
  114. if ( i== NoHorizontalMudElements+NoStringMudElements+1) then
  115. call Xstart_MudElement%Add (Ann_Mud_Backhead_X%Array(1)) ! start of annulus
  116. call TVD_Calculator(Ann_Mud_Backhead_X%Array(1),MudCircVerticalDepth)
  117. call TVDstart_MudElement%Add(MudCircVerticalDepth)
  118. elseif ( i== NoHorizontalMudElements+1 ) then
  119. call Xstart_MudElement%Add (St_Mud_Backhead_X%Array(1)) ! start of stirng
  120. call TVD_Calculator(St_Mud_Backhead_X%Array(1),MudCircVerticalDepth)
  121. call TVDstart_MudElement%Add(MudCircVerticalDepth)
  122. else
  123. call Xstart_MudElement%Add(Xend_MudElement%Array(i-1)) ! normal calculation
  124. call TVDstart_MudElement%Add(TVDend_MudElement%Array(i-1)) ! normal calculation
  125. endif
  126. enddo
  127. NoCasingMudElements = jelement- NoStringMudElements- NoHorizontalMudElements
  128. !=========================For Torque and Drag========================
  129. if (allocated(TDXstart_MudElementArray)) deallocate(TDXstart_MudElementArray)
  130. allocate(TDXstart_MudElementArray(NoHorizontalMudElements+NoStringMudElements+NoCasingMudElements))
  131. if (allocated(TDXend_MudElementArray)) deallocate(TDXend_MudElementArray)
  132. allocate(TDXend_MudElementArray(NoHorizontalMudElements+NoStringMudElements+NoCasingMudElements))
  133. if (allocated(TDDensity_MudElementArray)) deallocate(TDDensity_MudElementArray)
  134. allocate(TDDensity_MudElementArray(NoHorizontalMudElements+NoStringMudElements+NoCasingMudElements))
  135. TDNoHorizontalMudElements= NoHorizontalMudElements
  136. TDNoStringMudElements= NoStringMudElements
  137. TDNoCasingMudElements= NoCasingMudElements
  138. TDXstart_MudElementArray(:) = Xstart_MudElement%Array(:)
  139. TDXend_MudElementArray(:) = Xend_MudElement%Array(:)
  140. TDDensity_MudElementArray(:) = Density_MudElement%Array(:)
  141. !=====================================================================
  142. !do i=NoHorizontalMudElements+1, NoHorizontalMudElements+NoStringMudElements ! 2-string elements
  143. ! write(*,333) 'STRING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'Density=' , Density_MudElement%Array(i), 'MudType=' , MudType_MudElement%Array(i)
  144. !enddo
  145. !================================================================
  146. ! Open Hole Mud Elements
  147. jopmud= 1
  148. jopsection= 1
  149. jopelement= 0 ! number of final mud elements
  150. call Xend_OpMudElement%Empty()
  151. call TVDend_OpMudElement%Empty()
  152. call Density_OpMudElement%Empty()
  153. call PipeID_OpMudElement%Empty()
  154. call PipeOD_OpMudElement%Empty()
  155. !call Angle_OpMudElement%Empty()
  156. call MudTypeOp_MudElement%Empty()
  157. DO WHILE(jopmud<= Op_Mud_Forehead_X%Length() .and. jopsection<=F_BottomHoleIntervalCounts)
  158. jopelement= jopelement+1
  159. TrueMinValue= max(Op_Mud_Forehead_X%Array(jopmud), Xend_OpSection(jopsection))
  160. call Xend_OpMudElement%Add(TrueMinValue)
  161. call TVD_Calculator(TrueMinValue,MudCircVerticalDepth)
  162. call TVDend_OpMudElement%Add(MudCircVerticalDepth)
  163. call Density_OpMudElement%Add(Op_Density%Array(jopmud))
  164. call PipeID_OpMudElement%Add(ID_OpSectionInch(jopsection))
  165. call PipeOD_OpMudElement%Add(OD_OpSectionInch(jopsection))
  166. !call Angle_MudElement%Add(Angle_PipeSection(jopsection))
  167. call MudTypeOp_MudElement%Add(Op_MudOrKick%Array(jopmud))
  168. if (Xend_OpMudElement%Array(jopelement)== Op_Mud_Forehead_X%Array(jopmud)) then
  169. jopmud= jopmud+1
  170. else
  171. jopsection= jopsection+1
  172. endif
  173. ENDDO
  174. do i= 2, Xend_OpMudElement%Length()
  175. call Xstart_OpMudElement%Add(Xend_OpMudElement%Array(i-1))
  176. call TVDstart_OpMudElement%Add(TVDend_OpMudElement%Array(i-1))
  177. enddo
  178. NoBottomHoleMudElements = jopelement
  179. !================================================================
  180. if(allocated(StringMudElement)) deallocate(StringMudElement)
  181. allocate(StringMudElement(NoStringMudElements))
  182. if(allocated(CasingMudElement)) deallocate(CasingMudElement)
  183. allocate(CasingMudElement(NoCasingMudElements+NoBottomHoleMudElements))
  184. istring=0
  185. icasing=0
  186. BitMudDensity= Density_MudElement%Array(NoHorizontalMudElements+NoStringMudElements) ! (for ROP module)
  187. !================================================================
  188. !============================ UTUBE =============================
  189. !IF (UtubePossibility== .true. .and. Get_KellyConnection() /= KELLY_CONNECTION_STRING .and. WellHeadIsOpen) THEN
  190. IF (UtubePossibility== .true. .and. TD_FluidStringConnectionMode==0 .and. WellHeadIsOpen .AND. NoGasPocket == 0) THEN
  191. CALL WellPressureDataTransfer
  192. !WRITE (*,*) ' U-Tube Done 1'
  193. CALL Utube
  194. !WRITE (*,*) ' U-Tube Done 2'
  195. if (QUtubeInput> 0.0) call Utube1_and_TripIn
  196. if (QUtubeOutput> 0.0) call Utube2_and_TripIn
  197. END IF
  198. !========================== UTUBE- end =========================
  199. ! do imud=1, st_MudDischarged_Volume%Length()
  200. ! write(*,*) 'st-plot:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)
  201. !enddo
  202. !==================== Display ========================
  203. !do i=1, St_MudOrKick%Length()
  204. ! write(*,555) i,'St_Volume(i), type=' ,St_MudDischarged_Volume%Array(i),St_MudOrKick%Array(i)
  205. !
  206. ! IF (IEEE_Is_NaN(St_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in St Volume-Plot')
  207. ! IF (St_MudDischarged_Volume%Array(i)<0.) call ErrorStop('St Volume <0' , St_MudDischarged_Volume%Array(i))
  208. !enddo
  209. IF (ANY(IEEE_Is_NaN(Op_MudDischarged_Volume%Array(:))) .OR. ANY(Op_MudDischarged_Volume%Array(:) <= 0.0)) THEN
  210. do i = 1 , Op_MudOrKick%Length()
  211. write(*,555) i,'Op_Volume(i), type=' ,Op_MudDischarged_Volume%Array(i) , Op_MudOrKick%Array(i) , Op_Density%Array(i)
  212. end do
  213. call ErrorStop('NaN in Op Volume-Plot or Op Volume <=0')
  214. END IF
  215. IF (ANY(IEEE_Is_NaN(Ann_MudDischarged_Volume%Array(:))) .OR. ANY(Ann_MudDischarged_Volume%Array(:) <= 0.0)) THEN
  216. do i = 1 , Ann_MudOrKick%Length()
  217. write(*,555) i,'Ann_Volume(i), type=' ,Ann_MudDischarged_Volume%Array(i) , Ann_MudOrKick%Array(i) , Ann_Density%Array(i)
  218. end do
  219. call ErrorStop('NaN in Ann Volume-Plot or Ann Volume <=0')
  220. END IF
  221. !do i=1, Ann_MudOrKick%Length()
  222. ! !write(*,555) i,'Ann_Volume(i), type=' ,Ann_MudDischarged_Volume%Array(i),Ann_MudOrKick%Array(i),Ann_Density%Array(i)
  223. !
  224. ! IF (IEEE_Is_NaN(Ann_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in Ann Volume-Plot')
  225. ! IF (Ann_MudDischarged_Volume%Array(i)<=0.) call ErrorStop('Ann Volume <=0' , Ann_MudDischarged_Volume%Array(i))
  226. !enddo
  227. 555 FORMAT(I3,5X,A42,(f12.5),5X,I3,5X,(f12.5))
  228. NoStringMudElementsForPlot= NoStringMudElements
  229. ! 1-Horizontal Mud Elements are not shown
  230. !write(*,333) 'Horiz:', 1,'Xstart\=', Xstart_MudElement%Array(1), 'Xend=' , Xend_MudElement%Array(1), 'Density=' , Density_MudElement%Array(1), 'MudType=' , MudType_MudElement%Array(1)
  231. do i=NoHorizontalMudElements+1, NoHorizontalMudElements+NoStringMudElements ! 2-string elements
  232. if (Xend_MudElement%Array(i) <= 0.0) then
  233. NoStringMudElementsForPlot= NoStringMudElementsForPlot-1
  234. cycle
  235. endif
  236. istring= istring+1
  237. StringMudElement(istring)%StartMd = Xstart_MudElement%Array(i)
  238. StringMudElement(istring)%EndMd = Xend_MudElement%Array(i)
  239. !StringMudElement(istring)%Id = PipeID_MudElement%Array(i)
  240. !StringMudElement(istring)%Od = PipeOD_MudElement%Array(i)
  241. StringMudElement(istring)%Density = Density_MudElement%Array(i)
  242. if (MudType_MudElement%Array(i) == 104) then
  243. MudType_MudElement%Array(i)= 4 ! air
  244. elseif (MudType_MudElement%Array(i) > 0 .and. MudType_MudElement%Array(i) < 100) then ! all kicks
  245. MudType_MudElement%Array(i)= 1 ! gas kick
  246. endif
  247. StringMudElement(istring)%MudType = MudType_MudElement%Array(i)
  248. !write(*,333) 'STRING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'Density=' , Density_MudElement%Array(i), 'MudType=' , MudType_MudElement%Array(i)
  249. enddo
  250. do i=Xend_MudElement%Length(), NoHorizontalMudElements+NoStringMudElements+1 , -1 ! 3-casing elements
  251. icasing= icasing+1
  252. CasingMudElement(icasing)%StartMd = Xend_MudElement%Array(i)
  253. CasingMudElement(icasing)%EndMd = Xstart_MudElement%Array(i)
  254. !CasingMudElement(icasing)%Id = PipeID_MudElement%Array(i)
  255. !CasingMudElement(icasing)%Od = PipeOD_MudElement%Array(i)
  256. !write(*,333) 'CASING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'Density=' , Density_MudElement%Array(i), 'MudType=' , MudType_MudElement%Array(i)
  257. !call Log_1(temp1)
  258. !write(*,444) 'CASING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'PipeID_MudElement%Array(i)=' , PipeID_MudElement%Array(i), 'PipeOD_MudElement%Array(i)=' , PipeOD_MudElement%Array(i)
  259. CasingMudElement(icasing)%Density = Density_MudElement%Array(i)
  260. if (MudType_MudElement%Array(i) == 104) then
  261. MudType_MudElement%Array(i)= 4 ! air
  262. elseif (MudType_MudElement%Array(i) > 0 .and. MudType_MudElement%Array(i) < 100) then
  263. MudType_MudElement%Array(i)= 1 ! gas kick
  264. endif
  265. CasingMudElement(icasing)%MudType = MudType_MudElement%Array(i)
  266. enddo
  267. do i= NoBottomHoleMudElements, 1 , -1 ! 4-open hole elements
  268. icasing= icasing+1
  269. CasingMudElement(icasing)%StartMd = Xend_OpMudElement%Array(i)
  270. CasingMudElement(icasing)%EndMd = Xstart_OpMudElement%Array(i)
  271. !CasingMudElement(icasing)%Id = PipeID_OpMudElement%Array(i)
  272. !CasingMudElement(icasing)%Od = PipeOD_OpMudElement%Array(i)
  273. !write(*,333) 'OpenHole:',i,'Xstart\=', Xstart_OpMudElement%Array(i), 'Xend=' , Xend_OpMudElement%Array(i), 'Density=' , Density_OpMudElement%Array(i), 'MudType=' , MudTypeOp_MudElement%Array(i)
  274. !call Log_1(temp2)
  275. !write(*,444) 'OpenHole:',i,'Xstart\=', Xstart_OpMudElement%Array(i), 'Xend=' , Xend_OpMudElement%Array(i), 'PipeID_MudElement%Array(i)=' , PipeID_MudElement%Array(i), 'PipeOD_MudElement%Array(i)=' , PipeOD_MudElement%Array(i)
  276. CasingMudElement(icasing)%Density = Density_OpMudElement%Array(i)
  277. if (MudTypeOp_MudElement%Array(i) == 104) then
  278. MudTypeOp_MudElement%Array(i)= 4 ! air
  279. elseif (MudTypeOp_MudElement%Array(i) > 0 .and. MudTypeOp_MudElement%Array(i) < 100) then
  280. MudTypeOp_MudElement%Array(i)= 1 ! gas kick
  281. endif
  282. CasingMudElement(icasing)%MudType = MudTypeOp_MudElement%Array(i)
  283. enddo
  284. 333 FORMAT(A10,I3,5X,A8,(f12.5),5X,A8,(f12.5),5X,A8,(f12.5),5X,A8,I3)
  285. 444 FORMAT(A10,I2,5X,A8,(f12.3),5X,A8,(f12.3),5X,A8,(f12.3),5X,A8,(f12.3))
  286. ! shomare gozari be tartib HZ mud, ST mud, Casing
  287. ! shomare gzari OpenHole jodagane ast az 1
  288. call SetStringFluids(NoStringMudElementsForPlot, StringMudElement) !for data display in string
  289. call SetAnnalusFluids(NoCasingMudElements+NoBottomHoleMudElements, CasingMudElement) !for data display in casing
  290. !===========================================================================================================================
  291. !===========================================================================================================================
  292. end subroutine PlotFinalMudElements