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.
 
 
 
 
 
 

275 lines
14 KiB

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