Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

238 lines
11 KiB

  1. # 1 "/home/admin/SimulationCore2/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90"
  2. subroutine Kick_Expansion ! is called in subroutine CirculationCodeSelect
  3. Use GeoElements_FluidModule
  4. USE CMudPropertiesVariables
  5. USE MudSystemVARIABLES
  6. use SimulationVariables !@@@
  7. use SimulationVariables
  8. use SimulationVariables !@
  9. !use CTanks !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity
  10. USE sROP_Other_Variables
  11. USE sROP_Variables
  12. USE CReservoirVariables
  13. use KickVARIABLESModule
  14. implicit none
  15. real(8) ExpansionVolume
  16. !write(*,*) 'Kick Expansion'
  17. ExpansionVolume= GasPocketDeltaVol%Array(data%State%MudSystem%NewInfluxNumber - data%State%MudSystem%KickNumber + 1) * 7.48
  18. IF ( data%State%MudSystem%Kickexpansion_DueToMudLost ) ExpansionVolume = ((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline)
  19. !============================== kick zire mate bashad ==============================
  20. if (data%State%MudSystem%Op_KickLoc > 0 .and. data%State%MudSystem%Ann_KickLoc==0) then ! .and. Op_KickLoc /= Op_MudOrKick%Length ()) then
  21. !write(*,*) 'expansion (1)'
  22. data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc)+ ExpansionVolume
  23. !if (data%State%MUD(4)%Q > 0.) then
  24. !
  25. ! if (abs(ChokeLine_Density%Array(1)-Ann_Density%Last())< DensityMixTol) then
  26. ! ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1) + ExpansionVolume
  27. ! else
  28. ! call ChokeLine_Density%AddToFirst (Ann_Density%Last())
  29. ! call ChokeLine_MudDischarged_Volume%AddToFirst (ExpansionVolume) ! farz kardam ke hameye hajm ro ba yek density ezafe konim
  30. ! call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  31. ! call ChokeLine_Mud_Forehead_section%AddToFirst (1)
  32. ! call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  33. ! call ChokeLine_Mud_Backhead_section%AddToFirst (1)
  34. ! call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  35. ! call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  36. ! call ChokeLine_MudOrKick%AddToFirst (Ann_MudOrKick%Last())
  37. ! endif
  38. !
  39. !endif
  40. endif
  41. !========================================================================================
  42. !============================= foreheade dar fazaye annulus bashad ===========================
  43. ! agar kick be entehaye annulus reside bashe, expansion ra emaal nemikonim
  44. if (data%State%MudSystem%Ann_KickLoc > 0) then ! .and. Ann_KickLoc /= Ann_MudOrKick%Length ()) then
  45. !write(*,*) 'expansion (2)'
  46. !if ( sum(Ann_MudDischarged_Volume%Array(1:Ann_KickLoc)) + ExpansionVolume > sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) ) then ! agar khast az mate rad kone
  47. ! ExpansionVolume= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) - sum(Ann_MudDischarged_Volume%Array(1:Ann_KickLoc))
  48. !endif
  49. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc)+ ExpansionVolume
  50. !if (data%State%MUD(4)%Q > 0.) then
  51. !
  52. !
  53. ! if (abs(ChokeLine_Density%Array(1)-Ann_Density%Last())< DensityMixTol) then
  54. ! ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1) + ExpansionVolume
  55. ! else
  56. ! call ChokeLine_Density%AddToFirst (Ann_Density%Last())
  57. ! call ChokeLine_MudDischarged_Volume%AddToFirst (ExpansionVolume) ! farz kardam ke hameye hajm ro ba yek density ezafe konim
  58. ! call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  59. ! call ChokeLine_Mud_Forehead_section%AddToFirst (1)
  60. ! call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  61. ! call ChokeLine_Mud_Backhead_section%AddToFirst (1)
  62. ! call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  63. ! call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  64. ! call ChokeLine_MudOrKick%AddToFirst (Ann_MudOrKick%Last())
  65. ! endif
  66. !
  67. !endif
  68. endif
  69. !========================================================================================
  70. !=============================== foreheade dar choke line bashad =============================
  71. if (data%State%MudSystem%ChokeLine_KickLoc > 0 .and. data%State%MudSystem%Ann_KickLoc==0) then
  72. data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(data%State%MudSystem%ChokeLine_KickLoc)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(data%State%MudSystem%ChokeLine_KickLoc)+ ExpansionVolume
  73. endif
  74. !========================================================================================
  75. !write(*,*) 'Expansion======0'
  76. ! !do imud=1, Ann_MudDischarged_Volume%Length()
  77. ! ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  78. ! !enddo
  79. !
  80. ! do imud=1, Op_MudDischarged_Volume%Length()
  81. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  82. ! enddo
  83. !write(*,*) '0======expansion'
  84. end subroutine Kick_Expansion
  85. subroutine Kick_Contraction ! is called in subroutine CirculationCodeSelect
  86. Use GeoElements_FluidModule
  87. USE CMudPropertiesVariables
  88. USE MudSystemVARIABLES
  89. use SimulationVariables !@@@
  90. use SimulationVariables
  91. use SimulationVariables !@
  92. !use CTanks !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity
  93. USE sROP_Other_Variables
  94. USE sROP_Variables
  95. USE CReservoirVariables
  96. use KickVARIABLESModule
  97. USE CError
  98. implicit none
  99. integer jelement, jmud, jsection,ielement,i
  100. integer jopelement,jopmud,jopsection
  101. real(8) ContractionVolume
  102. !*********************************************************
  103. ! contraction is always with pump flow
  104. !*********************************************************
  105. !write(*,*) 'Kick Contraction'
  106. !data%State%MUD(2)%Q= data%Equipments%MPumps%Total_Pump_GPM
  107. data%State%MudSystem%StringFlowRate= data%State%MUD(2)%Q
  108. data%State%MudSystem%AnnulusFlowRate= data%State%MUD(2)%Q
  109. if (data%State%MudSystem%NewPipeFilling == 0) then
  110. data%State%MudSystem%StringFlowRate= 0.
  111. data%State%MudSystem%AnnulusFlowRate= 0.
  112. endif
  113. !if (WellHeadIsOpen) then
  114. ContractionVolume= - GasPocketDeltaVol%Array(data%State%MudSystem%NewInfluxNumber - data%State%MudSystem%KickNumber + 1) * 7.48
  115. !else
  116. !ContractionVolume = (data%State%MudSystem%StringFlowRate/60.0d0)*DeltaT_Mudline + DeltaVolumePipe
  117. if (data%State%MudSystem%KickNumber == 1 .and. data%State%MudSystem%WellHeadIsOpen==.false.) ContractionVolume = ContractionVolume + (data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline + data%State%MudSystem%DeltaVolumePipe
  118. !endif
  119. !**************************************************************************************************************************************************************************
  120. ! pump mud is added in "pump&TripIn" code
  121. IF (data%State%MudSystem%Op_KickLoc > 0 .and. data%State%MudSystem%Ann_KickLoc == 0) then ! All of kick is under bit (iloc == 1)
  122. data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc) - ( ContractionVolume )
  123. ELSE IF (data%State%MudSystem%Op_KickLoc == 0 .AND. data%State%MudSystem%Ann_KickLoc > 0 .AND. data%State%MudSystem%ChokeLine_KickLoc == 0) THEN ! All of kick is an Annulus (iloc == 1)
  124. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc) - ( ContractionVolume )
  125. ELSE IF (data%State%MudSystem%Ann_KickLoc == 0 .AND. data%State%MudSystem%ChokeLine_KickLoc > 0) THEN ! kick is in chokeline only
  126. data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(data%State%MudSystem%ChokeLine_KickLoc)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(data%State%MudSystem%ChokeLine_KickLoc) - ( ContractionVolume )
  127. ELSE IF (data%State%MudSystem%Op_KickLoc > 0 .AND. data%State%MudSystem%Ann_KickLoc > 0) THEN ! Kick is around bit (iloc==2)
  128. if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) > ContractionVolume ) then
  129. data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) - ( ContractionVolume )
  130. elseif (data%State%MudSystem%Op_MudDischarged_Volume%Last() > ContractionVolume ) then
  131. data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_MudDischarged_Volume%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_MudDischarged_Volume%Length()) - ( ContractionVolume )
  132. else
  133. Call ErrorStop ('kick contraction error 1')
  134. endif
  135. ELSE IF (data%State%MudSystem%Ann_KickLoc > 0 .AND. data%State%MudSystem%ChokeLine_KickLoc > 0) THEN
  136. if (data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1) > ContractionVolume ) then
  137. data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1) = data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1) - ( ContractionVolume )
  138. elseif (data%State%MudSystem%Ann_MudDischarged_Volume%Last() > ContractionVolume ) then
  139. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length())= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length()) - ( ContractionVolume )
  140. else
  141. Call ErrorStop ('kick contraction error 2')
  142. endif
  143. endif
  144. ! write(*,*) 'contract======0'
  145. !! !do imud=1, Ann_MudDischarged_Volume%Length()
  146. !! ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  147. !! !enddo
  148. !!
  149. ! do imud=1, Op_MudDischarged_Volume%Length()
  150. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  151. ! enddo
  152. !write(*,*) '0======contract'
  153. end subroutine Kick_Contraction