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.
 
 
 
 
 
 

281 lines
20 KiB

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