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.

Elements_Creation.f90 14 KiB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. subroutine ElementsCreation ! is called in subroutine Fluid_Flow_Solver
  2. Use GeoElements_FluidModule
  3. USE CMudPropertiesVariables
  4. USE MudSystemVARIABLES
  5. USE Pump_VARIABLES
  6. !USE CHOKEVARIABLES
  7. !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure
  8. !use CManifolds
  9. use CDrillWatchVariables
  10. !use CHOKEVARIABLES
  11. !use CChokeManifoldVariables
  12. use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity
  13. USE sROP_Other_Variables
  14. USE sROP_Variables
  15. Use KickVariables
  16. implicit none
  17. integer jelement, jmud, jsection,ielement,i
  18. integer jopelement,jopmud,jopsection
  19. !===========================================================WELL============================================================
  20. !===========================================================WELL============================================================
  21. if(allocated(Xstart_PipeSection)) deallocate(Xstart_PipeSection)
  22. if(allocated(Xend_PipeSection)) deallocate(Xend_PipeSection)
  23. if(allocated(PipeSection_VolumeCapacity)) deallocate(PipeSection_VolumeCapacity)
  24. if(allocated(Area_PipeSectionFt)) deallocate(Area_PipeSectionFt)
  25. if(allocated(GeoType)) deallocate(GeoType)
  26. if(allocated(OD_PipeSectionInch)) deallocate(OD_PipeSectionInch)
  27. if(allocated(ID_PipeSectionInch)) deallocate(ID_PipeSectionInch)
  28. if(allocated(Angle_PipeSection)) deallocate(Angle_PipeSection)
  29. if(allocated(Xstart_OpSection)) deallocate(Xstart_OpSection)
  30. if(allocated(Xend_OpSection)) deallocate(Xend_OpSection)
  31. if(allocated(OpSection_VolumeCapacity)) deallocate(OpSection_VolumeCapacity)
  32. if(allocated(Area_OpSectionFt)) deallocate(Area_OpSectionFt)
  33. if(allocated(GeoTypeOp)) deallocate(GeoTypeOp)
  34. if(allocated(OD_OpSectionInch)) deallocate(OD_OpSectionInch)
  35. if(allocated(ID_OpSectionInch)) deallocate(ID_OpSectionInch)
  36. if(allocated(Angle_OpSection)) deallocate(Angle_OpSection)
  37. ALLOCATE (Xstart_PipeSection(F_StringIntervalCounts+F_AnnulusIntervalCounts),Xend_PipeSection(F_StringIntervalCounts+F_AnnulusIntervalCounts) &
  38. ,PipeSection_VolumeCapacity(F_StringIntervalCounts+F_AnnulusIntervalCounts),Area_PipeSectionFt(F_StringIntervalCounts+F_AnnulusIntervalCounts), &
  39. GeoType(F_StringIntervalCounts+F_AnnulusIntervalCounts),OD_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts),ID_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts))
  40. ALLOCATE (Xstart_OpSection(F_BottomHoleIntervalCounts),Xend_OpSection(F_BottomHoleIntervalCounts) &
  41. ,OpSection_VolumeCapacity(F_BottomHoleIntervalCounts),Area_OpSectionFt(F_BottomHoleIntervalCounts), &
  42. GeoTypeOp(F_BottomHoleIntervalCounts),OD_OpSectionInch(F_BottomHoleIntervalCounts),ID_OpSectionInch(F_BottomHoleIntervalCounts))
  43. OpSection=0
  44. isection=0
  45. DO iisection=1, F_IntervalsTotalCounts
  46. IF (F_Interval(iisection)%GeoType == 1) THEN
  47. OpSection= OpSection+1
  48. Xstart_OpSection(OpSection)= (F_Interval(iisection)%StartDepth)
  49. Xend_OpSection(OpSection)= (F_Interval(iisection)%EndDepth)
  50. Area_OpSectionFt(OpSection)= PII*((F_Interval(iisection)%OD/12.0d0)**2-(F_Interval(iisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2)
  51. OD_OpSectionInch(OpSection)= (F_Interval(iisection)%OD)
  52. ID_OpSectionInch(OpSection)= (F_Interval(iisection)%ID) !REAL(F_Interval(iisection)%Volume)
  53. GeoTypeOp(OpSection)= F_Interval(iisection)%GeoType ! niaz nist ehtemalan
  54. !Angle_OpSection(OpSection)= F_Interval(iisection)%Angle
  55. !write(*,*) 'iisection=' , iisection
  56. !write(*,*) 'StartDepth=' , F_Interval(iisection)%StartDepth
  57. !write(*,*) 'EndDepth=' , F_Interval(iisection)%EndDepth
  58. !write(*,*) 'OD=' , F_Interval(iisection)%OD
  59. !write(*,*) 'ID=' , F_Interval(iisection)%ID
  60. ELSE
  61. isection= isection+1
  62. Xstart_PipeSection(isection)= (F_Interval(iisection)%StartDepth)
  63. !write(*,*) 'F_Interval(iisection)%StartDepth=' , F_Interval(iisection)%StartDepth
  64. Xend_PipeSection(isection)= (F_Interval(iisection)%EndDepth)
  65. !write(*,*) 'F_Interval(iisection)%EndDepth=' , F_Interval(iisection)%EndDepth
  66. OD_PipeSectionInch(isection)= (F_Interval(iisection)%OD)
  67. Area_PipeSectionFt(isection)= PII*((F_Interval(iisection)%OD/12.0d0)**2-(F_Interval(iisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2)
  68. ID_PipeSectionInch(isection)= (F_Interval(iisection)%ID)
  69. !PipeSection_VolumeCapacity(isection)= Area_PipeSectionFt(isection)* ABS(Xend_PipeSection(isection)-Xstart_PipeSection(isection))* 7.48051948 !REAL(F_Interval(iisection)%Volume) ! (gal)
  70. GeoType(isection)= F_Interval(iisection)%GeoType
  71. !Angle_PipeSection(isection)= F_Interval(iisection)%Angle
  72. ENDIF
  73. ENDDO
  74. call Xstart_MudElement%Empty()
  75. call Xstart_MudElement%Add(Xstart_PipeSection(1))
  76. call Xstart_OpMudElement%Empty()
  77. call Xstart_OpMudElement%Add(Xstart_OpSection(1))
  78. call TVDstart_MudElement%Empty()
  79. call TVD_Calculator(Xstart_PipeSection(1),MudCircVerticalDepth)
  80. call TVDstart_MudElement%Add(MudCircVerticalDepth)
  81. call TVDstart_OPMudElement%Empty()
  82. call TVD_Calculator(Xstart_OpSection(1),MudCircVerticalDepth)
  83. call TVDstart_OPMudElement%Add(MudCircVerticalDepth)
  84. NoPipeSections= isection ! sections in string and annulus(GeoType 0 & 2)
  85. DO OpSection= 1,F_BottomHoleIntervalCounts
  86. OpSection_VolumeCapacity(OpSection)= Area_OpSectionFt(OpSection)* ABS(Xend_OpSection(OpSection)-Xstart_OpSection(OpSection))* 7.48051948d0 !REAL(F_Interval(iisection)%Volume)
  87. ENDDO
  88. DO isection= 1,NoPipeSections
  89. PipeSection_VolumeCapacity(isection)= Area_PipeSectionFt(isection)* ABS(Xend_PipeSection(isection)-Xstart_PipeSection(isection))* 7.48051948d0 !REAL(F_Interval(iisection)%Volume) ! (gal)
  90. ENDDO
  91. !types: Mud= 0 Kick=1
  92. !===========================================
  93. if (FirstMudSet==0) then
  94. call Hz_MudDischarged_Volume%AddToFirst(PipeSection_VolumeCapacity(1)) !startup initial
  95. call Hz_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1))
  96. call Hz_Mud_Backhead_section%AddToFirst (1)
  97. call Hz_Mud_Forehead_X%AddToFirst (Xend_PipeSection(1))
  98. call Hz_Mud_Forehead_section%AddToFirst (1)
  99. call Hz_Density%AddToFirst (ActiveDensity) ! initial(ppg)
  100. call Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  101. call Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  102. call Hz_MudOrKick%AddToFirst (0)
  103. call St_MudDischarged_Volume%AddToFirst(sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts))) !startup initial
  104. call St_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(2))
  105. call St_Mud_Backhead_section%AddToFirst (2)
  106. call St_Mud_Forehead_X%AddToFirst (Xend_PipeSection(F_StringIntervalCounts))
  107. call St_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts)
  108. call St_Density%AddToFirst (ActiveDensity) ! initial(ppg)
  109. call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  110. call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  111. call St_MudOrKick%AddToFirst (0)
  112. call Ann_MudDischarged_Volume%AddToFirst(sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)))
  113. call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1))
  114. call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
  115. call Ann_Mud_Forehead_X%AddToFirst (Xend_PipeSection(NoPipeSections))
  116. call Ann_Mud_Forehead_section%AddToFirst (NoPipeSections)
  117. call Ann_Density%AddToFirst (ActiveDensity) ! initial(ppg)
  118. call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  119. call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  120. call Ann_MudOrKick%AddToFirst (0)
  121. call Ann_CuttingMud%AddToFirst (0)
  122. OldPosition= Xend_PipeSection(F_StringIntervalCounts)
  123. OldAnnulusCapacity= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
  124. call ChokeLine_MudDischarged_Volume%AddToFirst(ChokeLine_VolumeCapacity)
  125. call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  126. call ChokeLine_Mud_Backhead_section%AddToFirst (1)
  127. call ChokeLine_Mud_Forehead_X%AddToFirst (ChokeLineLength)
  128. call ChokeLine_Mud_Forehead_section%AddToFirst (1)
  129. call ChokeLine_Density%AddToFirst (ActiveDensity) ! initial(ppg)
  130. call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  131. call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  132. call ChokeLine_MudOrKick%AddToFirst (0)
  133. call Op_MudDischarged_Volume%AddToFirst (sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)))
  134. call Op_Mud_Backhead_X%AddToFirst (Xstart_OpSection(1))
  135. call Op_Mud_Backhead_section%AddToFirst (1)
  136. call Op_Mud_Forehead_X%AddToFirst (Xend_OpSection(F_BottomHoleIntervalCounts))
  137. call Op_Mud_Forehead_section%AddToFirst (F_BottomHoleIntervalCounts)
  138. call Op_Density%AddToFirst (ActiveDensity)
  139. call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  140. call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  141. call Op_MudOrKick%AddToFirst (0)
  142. !F_StringIntervalCountsOld= F_StringIntervalCounts ! is used for adding new pipe to string
  143. F_StringIntervalCounts_Old= F_StringIntervalCounts ! is used for adding new pipe to string
  144. FirstMudSet= 1
  145. endif
  146. !===================== Trip Detection ================
  147. !DeltaVolumeOp > 0 : Trip in
  148. !DeltaVolumeOp < 0 : Trip out
  149. DeltaVolumeOp= ((Xend_PipeSection(F_StringIntervalCounts)-OldPosition)*PII*((OD_PipeSectionInch(F_StringIntervalCounts+1)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal ! D(in)
  150. DeltaVolumeOp = INT(DeltaVolumeOp * 100000.d0) / 100000.d0
  151. DeltaVolumePipe= ((Xend_PipeSection(F_StringIntervalCounts)-OldPosition)*PII*((ID_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal
  152. DeltaVolumePipe = INT(DeltaVolumePipe * 100000.d0) / 100000.d0
  153. !DeltaVolumeAnnulusCapacity= ((Xend_PipeSection(F_StringIntervalCounts)-OldPosition))*Area_PipeSectionFt(NoPipeSections)* 7.48051948d0! ft^3 to gal
  154. DrillStringSpeed = (Xend_PipeSection(F_StringIntervalCounts)-OldPosition) / 0.1
  155. DeltaVolumeAnnulusCapacity= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) - OldAnnulusCapacity
  156. !write(*,*) 'DeltaVolumeAnnulusCapacity= ' , DeltaVolumeAnnulusCapacity
  157. !write(*,*) 'DeltaVolumePipe=' , DeltaVolumePipe
  158. !write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
  159. !
  160. !
  161. !write(*,*) 'Bit here=' , Xend_PipeSection(F_StringIntervalCounts)
  162. OldAnnulusCapacity= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
  163. OldPosition= Xend_PipeSection(F_StringIntervalCounts)
  164. ! Needed for trip in or out:
  165. if (Hz_Mud_Backhead_X%Length() == 0) then
  166. CALL ErrorStop('Hz_Mud_Backhead_X Length is 0')
  167. endif
  168. Hz_Mud_Backhead_X%Array(1)= Xstart_PipeSection(1)
  169. Hz_Mud_Backhead_section%Array(1)= 1
  170. AddedElementsToString = F_StringIntervalCounts - F_StringIntervalCounts_Old
  171. St_Mud_Backhead_X%Array(1)= Xstart_PipeSection(2)
  172. St_Mud_Backhead_section%Array(1)= 2
  173. Ann_Mud_Backhead_X%Array(1)= Xstart_PipeSection(F_StringIntervalCounts+1)
  174. Ann_Mud_Backhead_section%Array(1)= F_StringIntervalCounts+1
  175. Op_Mud_Backhead_X%Array(1)= Xstart_OpSection(1)
  176. Op_Mud_Backhead_section%Array(1)= 1
  177. ChokeLine_Mud_Backhead_X%Array(1)= 0.
  178. ChokeLine_Mud_Backhead_section%Array(1)= 1
  179. F_StringIntervalCounts_Old= F_StringIntervalCounts
  180. !write(*,*) 'Xstart_PipeSection(2)' , Xstart_PipeSection(2)
  181. !write(*,*) 'Xend_PipeSection(1)' , Xend_PipeSection(1)
  182. !===================================================
  183. !
  184. !DeltaWellCap= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) - WellCapOld
  185. !WellCapOld= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
  186. !write(*,*) 'DeltaWellCap=' , DeltaWellCap
  187. !
  188. !
  189. !
  190. !DeltaAnnCap= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) - AnnCapOld
  191. !AnnCapOld= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
  192. !write(*,*) 'DeltaAnnCap=' , DeltaAnnCap
  193. end subroutine ElementsCreation