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.
 
 
 
 
 
 

282 lines
20 KiB

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