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
16 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(MudSystemDotXstart_PipeSection)) deallocate(MudSystemDotXstart_PipeSection)
  23. if(allocated(MudSystemDotXend_PipeSection)) deallocate(MudSystemDotXend_PipeSection)
  24. if(allocated(MudSystemDotPipeSection_VolumeCapacity)) deallocate(MudSystemDotPipeSection_VolumeCapacity)
  25. if(allocated(MudSystemDotArea_PipeSectionFt)) deallocate(MudSystemDotArea_PipeSectionFt)
  26. if(allocated(MudSystemDotGeoType)) deallocate(MudSystemDotGeoType)
  27. if(allocated(MudSystemDotOD_PipeSectionInch)) deallocate(MudSystemDotOD_PipeSectionInch)
  28. if(allocated(MudSystemDotID_PipeSectionInch)) deallocate(MudSystemDotID_PipeSectionInch)
  29. if(allocated(MudSystemDotAngle_PipeSection)) deallocate(MudSystemDotAngle_PipeSection)
  30. if(allocated(MudSystemDotXstart_OpSection)) deallocate(MudSystemDotXstart_OpSection)
  31. if(allocated(MudSystemDotXend_OpSection)) deallocate(MudSystemDotXend_OpSection)
  32. if(allocated(MudSystemDotOpSection_VolumeCapacity)) deallocate(MudSystemDotOpSection_VolumeCapacity)
  33. if(allocated(MudSystemDotArea_OpSectionFt)) deallocate(MudSystemDotArea_OpSectionFt)
  34. if(allocated(MudSystemDotGeoTypeOp)) deallocate(MudSystemDotGeoTypeOp)
  35. if(allocated(MudSystemDotOD_OpSectionInch)) deallocate(MudSystemDotOD_OpSectionInch)
  36. if(allocated(MudSystemDotID_OpSectionInch)) deallocate(MudSystemDotID_OpSectionInch)
  37. if(allocated(MudSystemDotAngle_OpSection)) deallocate(MudSystemDotAngle_OpSection)
  38. ALLOCATE (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystemDotXend_PipeSection(F_StringIntervalCounts+F_AnnulusIntervalCounts) &
  39. ,MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystemDotArea_PipeSectionFt(F_StringIntervalCounts+F_AnnulusIntervalCounts), &
  40. MudSystemDotGeoType(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystemDotOD_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystemDotID_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts))
  41. ALLOCATE (MudSystemDotXstart_OpSection(F_BottomHoleIntervalCounts),MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts) &
  42. ,MudSystemDotOpSection_VolumeCapacity(F_BottomHoleIntervalCounts),MudSystemDotArea_OpSectionFt(F_BottomHoleIntervalCounts), &
  43. MudSystemDotGeoTypeOp(F_BottomHoleIntervalCounts),MudSystemDotOD_OpSectionInch(F_BottomHoleIntervalCounts),MudSystemDotID_OpSectionInch(F_BottomHoleIntervalCounts))
  44. MudSystemDotOpSection=0
  45. MudSystemDotisection=0
  46. DO MudSystemDotiisection=1, F_IntervalsTotalCounts
  47. IF (F_Interval(MudSystemDotiisection)%GeoType == 1) THEN
  48. MudSystemDotOpSection= MudSystemDotOpSection+1
  49. MudSystemDotXstart_OpSection(MudSystemDotOpSection)= (F_Interval(MudSystemDotiisection)%StartDepth)
  50. MudSystemDotXend_OpSection(MudSystemDotOpSection)= (F_Interval(MudSystemDotiisection)%EndDepth)
  51. MudSystemDotArea_OpSectionFt(MudSystemDotOpSection)= PII*((F_Interval(MudSystemDotiisection)%OD/12.0d0)**2-(F_Interval(MudSystemDotiisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2)
  52. MudSystemDotOD_OpSectionInch(MudSystemDotOpSection)= (F_Interval(MudSystemDotiisection)%OD)
  53. MudSystemDotID_OpSectionInch(MudSystemDotOpSection)= (F_Interval(MudSystemDotiisection)%ID) !REAL(F_Interval(iisection)%Volume)
  54. MudSystemDotGeoTypeOp(MudSystemDotOpSection)= F_Interval(MudSystemDotiisection)%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. MudSystemDotisection= MudSystemDotisection+1
  63. MudSystemDotXstart_PipeSection(MudSystemDotisection)= (F_Interval(MudSystemDotiisection)%StartDepth)
  64. !write(*,*) 'F_Interval(iisection)%StartDepth=' , F_Interval(iisection)%StartDepth
  65. MudSystemDotXend_PipeSection(MudSystemDotisection)= (F_Interval(MudSystemDotiisection)%EndDepth)
  66. !write(*,*) 'F_Interval(iisection)%EndDepth=' , F_Interval(iisection)%EndDepth
  67. MudSystemDotOD_PipeSectionInch(MudSystemDotisection)= (F_Interval(MudSystemDotiisection)%OD)
  68. MudSystemDotArea_PipeSectionFt(MudSystemDotisection)= PII*((F_Interval(MudSystemDotiisection)%OD/12.0d0)**2-(F_Interval(MudSystemDotiisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2)
  69. MudSystemDotID_PipeSectionInch(MudSystemDotisection)= (F_Interval(MudSystemDotiisection)%ID)
  70. !PipeSection_VolumeCapacity(isection)= Area_PipeSectionFt(isection)* ABS(Xend_PipeSection(isection)-Xstart_PipeSection(isection))* 7.48051948 !REAL(F_Interval(iisection)%Volume) ! (gal)
  71. MudSystemDotGeoType(MudSystemDotisection)= F_Interval(MudSystemDotiisection)%GeoType
  72. !Angle_PipeSection(isection)= F_Interval(iisection)%Angle
  73. ENDIF
  74. ENDDO
  75. call Xstart_MudElement%Empty()
  76. call Xstart_MudElement%Add(MudSystemDotXstart_PipeSection(1))
  77. call Xstart_OpMudElement%Empty()
  78. call Xstart_OpMudElement%Add(MudSystemDotXstart_OpSection(1))
  79. call TVDstart_MudElement%Empty()
  80. call TVD_Calculator(MudSystemDotXstart_PipeSection(1),MudSystemDotMudCircVerticalDepth)
  81. call TVDstart_MudElement%Add(MudSystemDotMudCircVerticalDepth)
  82. call TVDstart_OPMudElement%Empty()
  83. call TVD_Calculator(MudSystemDotXstart_OpSection(1),MudSystemDotMudCircVerticalDepth)
  84. call TVDstart_OPMudElement%Add(MudSystemDotMudCircVerticalDepth)
  85. MudSystemDotNoPipeSections= MudSystemDotisection ! sections in string and annulus(GeoType 0 & 2)
  86. DO MudSystemDotOpSection= 1,F_BottomHoleIntervalCounts
  87. MudSystemDotOpSection_VolumeCapacity(MudSystemDotOpSection)= MudSystemDotArea_OpSectionFt(MudSystemDotOpSection)* ABS(MudSystemDotXend_OpSection(MudSystemDotOpSection)-MudSystemDotXstart_OpSection(MudSystemDotOpSection))* 7.48051948d0 !REAL(F_Interval(iisection)%Volume)
  88. ENDDO
  89. DO MudSystemDotisection= 1,MudSystemDotNoPipeSections
  90. MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection)= MudSystemDotArea_PipeSectionFt(MudSystemDotisection)* ABS(MudSystemDotXend_PipeSection(MudSystemDotisection)-MudSystemDotXstart_PipeSection(MudSystemDotisection))* 7.48051948d0 !REAL(F_Interval(iisection)%Volume) ! (gal)
  91. ENDDO
  92. !types: Mud= 0 Kick=1
  93. !===========================================
  94. if (MudSystemDotFirstMudSet==0) then
  95. call MudSystemDotHz_MudDischarged_Volume%AddToFirst(MudSystemDotPipeSection_VolumeCapacity(1)) !startup initial
  96. call MudSystemDotHz_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(1))
  97. call Hz_Mud_Backhead_section%AddToFirst (1)
  98. call MudSystemDotHz_Mud_Forehead_X%AddToFirst (MudSystemDotXend_PipeSection(1))
  99. call Hz_Mud_Forehead_section%AddToFirst (1)
  100. call MudSystemDotHz_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
  101. call MudSystemDotHz_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  102. call MudSystemDotHz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  103. call Hz_MudOrKick%AddToFirst (0)
  104. call MudSystemDotSt_MudDischarged_Volume%AddToFirst(sum(MudSystemDotPipeSection_VolumeCapacity(2:F_StringIntervalCounts))) !startup initial
  105. call MudSystemDotSt_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(2))
  106. call St_Mud_Backhead_section%AddToFirst (2)
  107. call MudSystemDotSt_Mud_Forehead_X%AddToFirst (MudSystemDotXend_PipeSection(F_StringIntervalCounts))
  108. call St_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts)
  109. call St_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
  110. call MudSystemDotSt_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  111. call MudSystemDotSt_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  112. call St_MudOrKick%AddToFirst (0)
  113. call MudSystemDotAnn_MudDischarged_Volume%AddToFirst(sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)))
  114. call Ann_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
  115. call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
  116. call Ann_Mud_Forehead_X%AddToFirst (MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections))
  117. call Ann_Mud_Forehead_section%AddToFirst (MudSystemDotNoPipeSections)
  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. MudSystemDotOldPosition= MudSystemDotXend_PipeSection(F_StringIntervalCounts)
  124. MudSystemDotOldAnnulusCapacity= sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections))
  125. call MudSystemDotChokeLine_MudDischarged_Volume%AddToFirst(MudSystemDotChokeLine_VolumeCapacity)
  126. call MudSystemDotChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  127. call ChokeLine_Mud_Backhead_section%AddToFirst (1)
  128. call MudSystemDotChokeLine_Mud_Forehead_X%AddToFirst (BopStackSpecification%ChokeLineLength)
  129. call ChokeLine_Mud_Forehead_section%AddToFirst (1)
  130. call MudSystemDotChokeLine_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
  131. call MudSystemDotChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  132. call MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  133. call ChokeLine_MudOrKick%AddToFirst (0)
  134. call MudSystemDotOp_MudDischarged_Volume%AddToFirst (sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)))
  135. call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_OpSection(1))
  136. call Op_Mud_Backhead_section%AddToFirst (1)
  137. call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts))
  138. call Op_Mud_Forehead_section%AddToFirst (F_BottomHoleIntervalCounts)
  139. call MudSystemDotOp_Density%AddToFirst (MudProperties%ActiveDensity)
  140. call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  141. call MudSystemDotOp_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. MudSystemDotF_StringIntervalCounts_Old= F_StringIntervalCounts ! is used for adding new pipe to string
  145. MudSystemDotFirstMudSet= 1
  146. endif
  147. !===================== Trip Detection ================
  148. !DeltaVolumeOp > 0 : Trip in
  149. !DeltaVolumeOp < 0 : Trip out
  150. MudSystemDotDeltaVolumeOp= ((MudSystemDotXend_PipeSection(F_StringIntervalCounts)-MudSystemDotOldPosition)*PII*((MudSystemDotOD_PipeSectionInch(F_StringIntervalCounts+1)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal ! D(in)
  151. MudSystemDotDeltaVolumeOp = INT(MudSystemDotDeltaVolumeOp * 100000.d0) / 100000.d0
  152. MudSystemDotDeltaVolumePipe= ((MudSystemDotXend_PipeSection(F_StringIntervalCounts)-MudSystemDotOldPosition)*PII*((MudSystemDotID_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal
  153. MudSystemDotDeltaVolumePipe = INT(MudSystemDotDeltaVolumePipe * 100000.d0) / 100000.d0
  154. !DeltaVolumeAnnulusCapacity= ((Xend_PipeSection(F_StringIntervalCounts)-OldPosition))*Area_PipeSectionFt(NoPipeSections)* 7.48051948d0! ft^3 to gal
  155. DrillStringSpeed = (MudSystemDotXend_PipeSection(F_StringIntervalCounts)-MudSystemDotOldPosition) / 0.1
  156. MudSystemDotDeltaVolumeAnnulusCapacity= sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)) - MudSystemDotOldAnnulusCapacity
  157. !write(*,*) 'DeltaVolumeAnnulusCapacity= ' , DeltaVolumeAnnulusCapacity
  158. !write(*,*) 'DeltaVolumePipe=' , DeltaVolumePipe
  159. !write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
  160. !
  161. !
  162. !write(*,*) 'Bit here=' , Xend_PipeSection(F_StringIntervalCounts)
  163. MudSystemDotOldAnnulusCapacity= sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections))
  164. MudSystemDotOldPosition= MudSystemDotXend_PipeSection(F_StringIntervalCounts)
  165. ! Needed for trip in or out:
  166. if (MudSystemDotHz_Mud_Backhead_X%Length() == 0) then
  167. CALL ErrorStop('Hz_Mud_Backhead_X Length is 0')
  168. endif
  169. MudSystemDotHz_Mud_Backhead_X%Array(1)= MudSystemDotXstart_PipeSection(1)
  170. Hz_Mud_Backhead_section%Array(1)= 1
  171. MudSystemDotAddedElementsToString = F_StringIntervalCounts - MudSystemDotF_StringIntervalCounts_Old
  172. MudSystemDotSt_Mud_Backhead_X%Array(1)= MudSystemDotXstart_PipeSection(2)
  173. St_Mud_Backhead_section%Array(1)= 2
  174. Ann_Mud_Backhead_X%Array(1)= MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1)
  175. Ann_Mud_Backhead_section%Array(1)= F_StringIntervalCounts+1
  176. MudSystemDotOp_Mud_Backhead_X%Array(1)= MudSystemDotXstart_OpSection(1)
  177. Op_Mud_Backhead_section%Array(1)= 1
  178. MudSystemDotChokeLine_Mud_Backhead_X%Array(1)= 0.
  179. ChokeLine_Mud_Backhead_section%Array(1)= 1
  180. MudSystemDotF_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