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.
 
 
 
 
 
 

518 lines
24 KiB

  1. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/TorqueDrag/TD_DrillingSubs/MeshGeneration_FluidModule.f90"
  2. subroutine MeshGeneration_FluidModule
  3. Use TD_DrillStemComponents
  4. use SimulationVariables !@
  5. use SimulationVariables !@
  6. Use TD_StringConnectionData
  7. Use GeoElements_FluidModule
  8. use CPumpsVariables
  9. use CPumps
  10. Use CStringConfigurationVariables
  11. Use CBopStackVariables
  12. !use ConfigurationVariables !@ , only: Drawworks
  13. implicit none
  14. Integer :: ii , jj , semijj , kk , k , m , s
  15. Integer :: ElementsCount , StringConfigCount
  16. REAL(8) :: mm , nn , dl , StartAngle , EndAngle
  17. REAL(8) :: A(30) !?????????10
  18. REAL(8) :: TD_ElementLength
  19. A = 0.d0
  20. A(1) = data%Configuration%BopStack%AboveAnnularHeight ! WellHead[ft]
  21. jj = 1
  22. !====================================================
  23. ! Mesh Generation of DrillStem Components
  24. !====================================================
  25. !data%State%TD_String%StringConfigurationCount = StringConfigurationCount !???????????
  26. StringConfigCount = data%State%TD_String%StringConfigurationCount
  27. if (allocated(data%State%F_String)) Deallocate(data%State%F_String)
  28. if (data%State%TD_DrillStem(1)%ComponentType==0) then
  29. Allocate (data%State%F_String(StringConfigCount-1))
  30. else
  31. Allocate (data%State%F_String(StringConfigCount))
  32. end if
  33. if (data%State%TD_DrillStem(1)%ComponentType==0) then
  34. ElementsCount = 1
  35. Do ii=1,(StringConfigCount-1)
  36. data%State%F_String(ii)%ID = data%State%TD_DrillStem(ii+1)%Id*12.d0 ![inch]
  37. data%State%F_String(ii)%OD = data%State%TD_DrillStem(ii+1)%Od*12.d0 ![inch]
  38. data%State%F_String(ii)%FirstElement = ElementsCount+1
  39. data%State%F_String(ii)%LastElement = data%State%F_String(ii)%FirstElement+(data%State%TD_DrillStem(ii+1)%Numbs-1)
  40. data%State%F_String(ii)%ElType = data%State%TD_DrillStem(ii+1)%ComponentType
  41. ElementsCount = data%State%F_String(ii)%LastElement
  42. End Do
  43. StringConfigCount = StringConfigCount-1
  44. else
  45. ElementsCount = 0
  46. Do ii=1,StringConfigCount
  47. data%State%F_String(ii)%ID = data%State%TD_DrillStem(ii)%Id*12.d0 ![inch]
  48. data%State%F_String(ii)%OD = data%State%TD_DrillStem(ii)%Od*12.d0 ![inch]
  49. data%State%F_String(ii)%FirstElement = ElementsCount+1
  50. data%State%F_String(ii)%LastElement = data%State%F_String(ii)%FirstElement+(data%State%TD_DrillStem(ii)%Numbs-1)
  51. data%State%F_String(ii)%ElType = data%State%TD_DrillStem(ii)%ComponentType
  52. ElementsCount = data%State%F_String(ii)%LastElement
  53. End Do
  54. end if
  55. Do ii=1,StringConfigCount
  56. data%State%F_String(ii)%TopDepth = data%State%TD_DrillStems(data%State%F_String(ii)%LastElement)%TopDepthIni ![ft]
  57. data%State%F_String(ii)%DownDepth = data%State%TD_DrillStems(data%State%F_String(ii)%FirstElement)%DownDepthIni ![ft]
  58. if (data%State%F_String(ii)%DownDepth>A(1)) then
  59. jj = jj+1
  60. A(jj) = data%State%F_String(ii)%DownDepth
  61. end if
  62. End Do
  63. !=========> Removed Volume Calculation in DrillStem
  64. TD_ElementLength = data%State%F_String(StringConfigCount)%DownDepth-data%State%F_String(StringConfigCount)%TopDepth
  65. if ( StringConfigCount==data%State%TD_Vol%PreCount ) then
  66. if ( data%State%TD_Vol%PreElementLength>TD_ElementLength ) then
  67. data%State%TD_Vol%RemoveVolume = (data%State%TD_Vol%PreElementLength-TD_ElementLength)*((pi*((data%State%F_String(StringConfigCount)%ID/12.d0)**2))/4.d0) ![ft^3]
  68. else
  69. data%State%TD_Vol%RemoveVolume = 0.d0
  70. end if
  71. else if ( StringConfigCount<data%State%TD_Vol%PreCount ) then
  72. data%State%TD_Vol%RemoveVolume = data%State%TD_Vol%PreElementVolume
  73. else
  74. data%State%TD_Vol%RemoveVolume = 0.d0
  75. end if
  76. data%State%TD_Vol%PreCount = StringConfigCount
  77. data%State%TD_Vol%PreElementVolume = TD_ElementLength*(((pi*((data%State%F_String(StringConfigCount)%ID/12.d0)**2))/4.d0)) ![ft^3]
  78. data%State%TD_Vol%PreElementLength = TD_ElementLength
  79. !print*, 'data%State%TD_Vol%RemoveVolume=' , data%State%TD_Vol%RemoveVolume
  80. !====================================================
  81. ! Mesh Generation of Annulus Components
  82. !====================================================
  83. if (data%State%TD_Casing(1)%Length>0.) then
  84. jj = jj+1
  85. A(jj) = data%State%TD_Casing(1)%DownDepth
  86. data%State%OD_Annulus(4)%StartMD = data%State%TD_Casing(1)%DownDepth ![ft]
  87. data%State%OD_Annulus(4)%EndMD = data%State%TD_Casing(1)%TopDepth ![ft]
  88. data%State%OD_Annulus(4)%ODValue = data%State%TD_Casing(1)%Id*12.d0 ![inch]
  89. !else
  90. ! data%State%OD_Annulus(4)%StartMD = 0. !????????????????????
  91. ! data%State%OD_Annulus(4)%EndMD = data%State%OD_Annulus(4)%StartMD !????????????????????
  92. ! data%State%OD_Annulus(4)%ODValue = data%State%TD_Casing(1)%Id !????????????????????
  93. end if
  94. if (data%State%TD_Liner(1)%Length>0.) then
  95. jj = jj+1
  96. A(jj) = data%State%TD_Liner(1)%DownDepth
  97. data%State%OD_Annulus(3)%StartMD = data%State%TD_Liner(1)%DownDepth ![ft]
  98. data%State%OD_Annulus(3)%EndMD = data%State%TD_Liner(1)%TopDepth ![ft]
  99. data%State%OD_Annulus(3)%ODValue = data%State%TD_Liner(1)%Id*12.d0 ![inch]
  100. else
  101. data%State%OD_Annulus(3)%StartMD = data%State%TD_Casing(1)%DownDepth !????????????????????
  102. data%State%OD_Annulus(3)%EndMD = data%State%OD_Annulus(3)%StartMD !????????????????????
  103. data%State%OD_Annulus(3)%ODValue = data%State%OD_Annulus(4)%ODValue !????????????????????
  104. end if
  105. if (data%State%TD_OpenHole(1)%Length>0.) then
  106. !jj = jj+1
  107. !A(jj) = data%State%TD_OpenHole(1)%DownDepth
  108. data%State%OD_Annulus(2)%StartMD = data%State%TD_OpenHole(1)%DownDepth ![ft]
  109. data%State%OD_Annulus(2)%EndMD = data%State%TD_OpenHole(1)%TopDepth ![ft]
  110. data%State%OD_Annulus(2)%ODValue = data%State%TD_OpenHole(1)%Id*12.d0 ![inch]
  111. do ii = 1,data%State%TD_WellGeneral%WellIntervalsCount-1
  112. if ( data%State%TD_WellGeo(ii)%DownDepth>data%State%TD_OpenHole(1)%TopDepth ) then
  113. jj = jj+1
  114. A(jj) = data%State%TD_WellGeo(ii)%DownDepth
  115. end if
  116. end do
  117. else
  118. data%State%OD_Annulus(2)%StartMD = data%State%TD_Liner(1)%DownDepth !??????????????
  119. data%State%OD_Annulus(2)%EndMD = data%State%OD_Annulus(2)%StartMD !??????????????
  120. data%State%OD_Annulus(2)%ODValue = data%State%OD_Annulus(3)%ODValue !??????????????
  121. end if
  122. if (data%State%TD_ROPHole(1)%Length>0.) then
  123. jj = jj+1
  124. A(jj) = data%State%TD_ROPHole(1)%DownDepth
  125. data%State%OD_Annulus(1)%StartMD = data%State%TD_ROPHole(1)%DownDepth ![ft]
  126. data%State%OD_Annulus(1)%EndMD = data%State%TD_ROPHole(1)%TopDepth ![ft]
  127. data%State%OD_Annulus(1)%ODValue = data%State%TD_ROPHole(1)%Id*12.d0 ![inch]
  128. else
  129. data%State%OD_Annulus(1)%StartMD = data%State%TD_OpenHole(1)%DownDepth !??????????????
  130. data%State%OD_Annulus(1)%EndMD = data%State%OD_Annulus(1)%StartMD !??????????????
  131. data%State%OD_Annulus(1)%ODValue = data%State%OD_Annulus(2)%ODValue !??????????????
  132. end if
  133. !print*, 'A(jj)2=' , A
  134. !====================================================
  135. ! Mesh Generation of Well
  136. !====================================================
  137. !Do ii=2,data%State%TD_WellGeneral%WellIntervalsCount-1
  138. ! jj = jj+1
  139. ! A(jj) = data%State%TD_WellGeo(ii)%TopDepth
  140. !End Do
  141. !print*, 'A(jj)3=' , A
  142. !print*, 'A=' , A
  143. !print*, 'jj=' , jj
  144. semijj = jj
  145. !print*, 'semijj=' , semijj
  146. Do ii=1,jj
  147. do kk = 1,jj
  148. if ( A(ii)==A(KK) .and. ii/=kk .and. A(KK)/=0. ) then !A(KK)/=0. ?????????????????
  149. !print*, 'indoA=' , semijj , ii , kk , A(KK) , A(ii)
  150. A(kk) = 0.d0
  151. semijj = semijj-1
  152. !print*, 'indoA2=' , semijj , ii , kk , A(KK) , A(ii)
  153. end if
  154. end do
  155. End Do
  156. !print*, 'semijj2=' , semijj
  157. jj = semijj
  158. !print*, 'jj2=' , jj
  159. !print*, 'AA=' , A
  160. if (allocated(data%State%TDGeo%MD)) Deallocate(data%State%TDGeo%MD)
  161. Allocate (data%State%TDGeo%MD(jj))
  162. data%State%TDGeo%MD = 0.0d0
  163. Do ii=1,jj
  164. data%State%TDGeo%MD(ii)=A(1)
  165. do kk = 2,jj
  166. if (A(KK)>data%State%TDGeo%MD(ii)) then
  167. data%State%TDGeo%MD(ii) = A(kk)
  168. k=kk
  169. end if
  170. end do
  171. !!data%State%TDGeo%MD(ii) = MAXVAL(A)
  172. !!kk = MAXLOC(A)
  173. !!A(kk) = 0.0d0
  174. A(k) = 0.0d0
  175. End Do
  176. !====================================================
  177. ! Geometrical Intervals Configuration (for fluid module)
  178. !====================================================
  179. if (allocated(data%State%F_Interval)) Deallocate(data%State%F_Interval)
  180. Allocate (data%State%F_Interval(jj-1+StringConfigCount+1))
  181. !data%State%F_Interval = 0.0d0
  182. data%State%F_Counts%IntervalsTotalCounts = jj-1+StringConfigCount+1
  183. !=========> String Intervals Configuration
  184. ! pump output
  185. ii = 1
  186. data%State%F_Interval(ii)%Number = ii
  187. data%State%F_Interval(ii)%GeoType = 0
  188. data%State%F_Interval(ii)%EndDepth = data%State%F_String(StringConfigCount)%TopDepth
  189. data%State%F_Interval(ii)%StartDepth = data%State%F_String(StringConfigCount)%TopDepth-265.d0
  190. data%State%F_Interval(ii)%ID = 0.0d0
  191. data%State%F_Interval(ii)%OD = dmax1(data%Configuration%Pumps%MudPump1Output,data%Configuration%Pumps%MudPump2Output) !???????????
  192. data%State%F_Interval(ii)%HydDiameter = data%State%F_Interval(ii)%OD ![inch]
  193. data%State%F_Interval(ii)%Volume = ((pi*((data%State%F_Interval(ii)%OD/12.d0)**2))/4.d0) &
  194. *(data%State%F_Interval(ii)%EndDepth-data%State%F_Interval(ii)%StartDepth)*7.48051948d0 ![gal-us]
  195. Do ii=2,StringConfigCount+1
  196. data%State%F_Interval(ii)%Number = ii
  197. data%State%F_Interval(ii)%GeoType = 0
  198. data%State%F_Interval(ii)%EndDepth = data%State%F_String(StringConfigCount+1-ii+1)%DownDepth
  199. data%State%F_Interval(ii)%StartDepth = data%State%F_String(StringConfigCount+1-ii+1)%TopDepth
  200. data%State%F_Interval(ii)%ID = 0.0d0
  201. data%State%F_Interval(ii)%OD = data%State%F_String(StringConfigCount+1-ii+1)%ID
  202. data%State%F_Interval(ii)%HydDiameter = data%State%F_Interval(ii)%OD
  203. data%State%F_Interval(ii)%Volume = ((pi*((data%State%F_Interval(ii)%OD/12.d0)**2))/4.d0) &
  204. *(data%State%F_Interval(ii)%EndDepth-data%State%F_Interval(ii)%StartDepth)*7.48051948d0 ![gal-us]
  205. End Do
  206. data%State%F_Counts%StringIntervalCounts = StringConfigCount+1
  207. !if (data%State%F_String(1)%ElType==0) then !bit
  208. ! !data%State%F_Interval(StringConfigCount)%Number = ii
  209. ! data%State%F_Interval(StringConfigCount)%EndDepth = data%State%F_String(1)%DownDepth
  210. ! data%State%F_Interval(StringConfigCount)%StartDepth = data%State%F_String(1)%TopDepth
  211. ! data%State%F_Interval(StringConfigCount)%ID = 0.0d0
  212. ! data%State%F_Interval(StringConfigCount)%OD = data%State%F_String(1)%OD
  213. ! data%State%F_Interval(StringConfigCount)%HydDiameter = data%State%F_Interval(StringConfigCount)%OD
  214. ! data%State%F_Interval(StringConfigCount)%Volume = ((pi*((data%State%F_Interval(StringConfigCount)%OD/12.)**2))/4.)*(data%State%F_Interval(StringConfigCount)%EndDepth-data%State%F_Interval(StringConfigCount)%StartDepth)*7.48051948
  215. !end if
  216. !=========> Annulus Intervals Configuration
  217. data%State%F_Counts%BottomHoleIntervalCounts = 0
  218. data%State%F_Counts%AnnulusIntervalCounts = 0
  219. Do ii=(StringConfigCount+2),(jj-1+StringConfigCount+1)
  220. data%State%F_Interval(ii)%Number = ii
  221. data%State%F_Interval(ii)%StartDepth = data%State%TDGeo%MD(ii-StringConfigCount-1)
  222. data%State%F_Interval(ii)%EndDepth = data%State%TDGeo%MD(ii+1-StringConfigCount-1)
  223. if (data%State%F_Interval(ii)%EndDepth>=data%State%F_Interval(StringConfigCount+1)%EndDepth) then
  224. data%State%F_Interval(ii)%GeoType = 1
  225. data%State%F_Counts%BottomHoleIntervalCounts = data%State%F_Counts%BottomHoleIntervalCounts+1
  226. else
  227. data%State%F_Interval(ii)%GeoType = 2
  228. data%State%F_Counts%AnnulusIntervalCounts = data%State%F_Counts%AnnulusIntervalCounts+1
  229. end if
  230. End Do
  231. !====================================================
  232. ! Diameter Calculation of Annulus Intervals
  233. !====================================================
  234. !=========> OD
  235. m = 1
  236. Do ii = (StringConfigCount+2),data%State%F_Counts%IntervalsTotalCounts
  237. do kk = m,4
  238. if (data%State%F_Interval(ii)%StartDepth<=data%State%OD_Annulus(kk)%StartMD .and. data%State%F_Interval(ii)%EndDepth>=data%State%OD_Annulus(kk)%EndMD) then
  239. data%State%F_Interval(ii)%OD = data%State%OD_Annulus(kk)%ODValue
  240. m = kk
  241. exit
  242. end if
  243. end do
  244. End Do
  245. !=========> ID
  246. m = 1
  247. Do ii = (StringConfigCount+2),data%State%F_Counts%IntervalsTotalCounts
  248. do kk = m,StringConfigCount
  249. if (data%State%F_Interval(ii)%StartDepth<=data%State%F_String(kk)%DownDepth .and. data%State%F_Interval(ii)%EndDepth>=data%State%F_String(kk)%TopDepth) then
  250. data%State%F_Interval(ii)%ID = data%State%F_String(kk)%OD
  251. m = kk
  252. exit
  253. else
  254. data%State%F_Interval(ii)%ID = 0.0d0
  255. end if
  256. end do
  257. data%State%F_Interval(ii)%HydDiameter = data%State%F_Interval(ii)%OD-data%State%F_Interval(ii)%ID
  258. data%State%F_Interval(ii)%Volume = ((pi*(((data%State%F_Interval(ii)%OD/12.d0)**2)-((data%State%F_Interval(ii)%ID/12.d0)**2)))/4.d0) &
  259. *abs(data%State%F_Interval(ii)%EndDepth-data%State%F_Interval(ii)%StartDepth)*7.48051948d0 ![gal-us]
  260. End Do
  261. !print*, 'StringConfigCount=' , StringConfigCount
  262. !print*, 'data%State%F_Counts%IntervalsTotalCounts=' , data%State%F_Counts%IntervalsTotalCounts
  263. !print*, 'data%State%F_Counts%StringIntervalCounts=' , data%State%F_Counts%StringIntervalCounts
  264. !print*, 'data%State%F_Counts%BottomHoleIntervalCounts=' , data%State%F_Counts%BottomHoleIntervalCounts
  265. !print*, 'data%State%F_Counts%AnnulusIntervalCounts=' , data%State%F_Counts%AnnulusIntervalCounts
  266. !Do ii=1,(data%State%F_Counts%IntervalsTotalCounts)
  267. ! print*, 'Number/' , 'StartDepth/' , 'EndDepth/'
  268. ! print*, 'ID/' , 'OD/' , 'GeoType/'
  269. ! print*, 'HydDiameter/' , 'Volume/'
  270. ! print*, data%State%F_Interval(ii)%Number , data%State%F_Interval(ii)%StartDepth , data%State%F_Interval(ii)%EndDepth
  271. ! print*, data%State%F_Interval(ii)%ID , data%State%F_Interval(ii)%OD , data%State%F_Interval(ii)%GeoType
  272. ! print*, data%State%F_Interval(ii)%HydDiameter , data%State%F_Interval(ii)%Volume
  273. !End Do
  274. !====================================================
  275. ! TVD Calculation of Geo Intervals
  276. !====================================================
  277. !=========> Out of Well Intervals
  278. data%State%F_Interval(1)%StartTVD = 0.0d0 !??????????????
  279. data%State%F_Interval(1)%EndTVD = -data%State%TD_StConn%ConnectionHeight
  280. data%State%F_Interval(1)%StartAngle = 0.d0 !???????????????????????
  281. data%State%F_Interval(1)%EndAngle = 0.d0 !???????????????????????
  282. data%State%F_Counts%OutOfWellIntervalCounts = 1
  283. Do ii= 2 , StringConfigCount+1
  284. if ( data%State%F_Interval(ii)%StartDepth<=0.d0 ) then
  285. data%State%F_Interval(ii)%StartTVD = data%State%F_Interval(ii)%StartDepth
  286. data%State%F_Interval(ii)%StartAngle = 0.0d0
  287. end if
  288. if ( data%State%F_Interval(ii)%EndDepth<=0.d0 ) then
  289. data%State%F_Interval(ii)%EndTVD = data%State%F_Interval(ii)%EndDepth
  290. data%State%F_Interval(ii)%EndAngle = 0.0d0
  291. data%State%F_Counts%OutOfWellIntervalCounts = data%State%F_Counts%OutOfWellIntervalCounts+1
  292. end if
  293. End Do
  294. !=========>
  295. if (allocated(data%State%TDGeo%TVD)) Deallocate(data%State%TDGeo%TVD)
  296. Allocate (data%State%TDGeo%TVD(jj))
  297. if (allocated(data%State%TDGeo%Angle)) Deallocate(data%State%TDGeo%Angle)
  298. Allocate (data%State%TDGeo%Angle(jj))
  299. data%State%TDGeo%TVD(1) = data%State%TD_WellGeneral%WellTotalVerticalLength !?????
  300. !print*, 'data%State%TD_WellGeneral%WellTotalVerticalLength=' ,data%State%TD_WellGeneral%WellTotalVerticalLength
  301. data%State%TDGeo%TVD(jj) = data%Configuration%BopStack%AboveAnnularHeight ! WellHead[ft] !0.d0 ????????????????
  302. k = 1
  303. mm = 0.d0
  304. nn = 0.d0
  305. EndAngle = data%State%TD_WellGeo(1)%StartAngle !???????????????
  306. data%State%TDGeo%Angle(jj) = EndAngle
  307. Do ii = jj-1,1,-1 !???1or2
  308. do kk = k, data%State%TD_WellGeneral%WellIntervalsCount
  309. StartAngle = EndAngle
  310. if ( data%State%TDGeo%MD(ii)>data%State%TD_WellGeo(kk)%TopDepth ) then
  311. if ( data%State%TDGeo%MD(ii)>data%State%TD_WellGeo(kk)%DownDepth ) then
  312. dl = data%State%TD_WellGeo(kk)%DownDepth-nn ![ft]
  313. nn = data%State%TD_WellGeo(kk)%DownDepth
  314. if ( data%State%TD_WellGeo(kk)%HoleType==0 ) then
  315. EndAngle = StartAngle
  316. !print*, 'StartAngle1=' ,ii , kk, StartAngle
  317. !print*, 'EndAngle1=' ,ii , kk, EndAngle
  318. data%State%TDGeo%TVD(ii) = mm+(dl*cos(data%State%TD_WellGeo(kk)%StartAngle)) ![ft]
  319. data%State%TDGeo%Angle(ii) = EndAngle
  320. !print*, 'data%State%TDGeo%TVD(ii)1=' ,ii , kk, data%State%TDGeo%TVD(ii)
  321. else if ( data%State%TD_WellGeo(kk)%HoleType==1 ) then
  322. EndAngle = StartAngle+(dl/data%State%TD_WellGeo(kk)%RCurvature) !?????????????????
  323. !print*, 'StartAngle2=' ,ii , kk, StartAngle
  324. !print*, 'EndAngle2=' ,ii , kk, EndAngle
  325. data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle))*cos(abs(StartAngle)))-(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(EndAngle)-abs(StartAngle)))*sin(abs(StartAngle)))
  326. !data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle)))
  327. data%State%TDGeo%Angle(ii) = EndAngle
  328. !print*, 'data%State%TDGeo%TVD(ii)2=' , ii , kk, data%State%TDGeo%TVD(ii)
  329. else if ( data%State%TD_WellGeo(kk)%HoleType==2 ) then
  330. EndAngle = StartAngle-(dl/data%State%TD_WellGeo(kk)%RCurvature) !?????????????????
  331. !print*, 'StartAngle22=' ,ii , kk, StartAngle
  332. !print*, 'EndAngle22=' ,ii , kk, EndAngle
  333. data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(abs(EndAngle)-abs(StartAngle)))*cos(abs(StartAngle)))+(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(abs(EndAngle)-abs(StartAngle))))*sin(abs(StartAngle)))
  334. !data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle)))
  335. data%State%TDGeo%Angle(ii) = EndAngle
  336. !print*, 'data%State%TDGeo%TVD(ii)22=' , ii , kk, data%State%TDGeo%TVD(ii)
  337. end if
  338. mm = data%State%TDGeo%TVD(ii)
  339. else
  340. dl = data%State%TDGeo%MD(ii)-nn
  341. nn = data%State%TDGeo%MD(ii)
  342. if ( data%State%TD_WellGeo(kk)%HoleType==0 ) then
  343. EndAngle = StartAngle
  344. !print*, 'StartAngle3=' ,ii , kk, StartAngle
  345. !print*, 'EndAngle3=' ,ii , kk, EndAngle
  346. data%State%TDGeo%TVD(ii) = mm+(dl*cos(data%State%TD_WellGeo(kk)%StartAngle))
  347. data%State%TDGeo%Angle(ii) = EndAngle
  348. !print*, 'data%State%TDGeo%TVD(ii)3=' ,ii , kk, data%State%TDGeo%TVD(ii)
  349. else if ( data%State%TD_WellGeo(kk)%HoleType==1 ) then
  350. EndAngle = StartAngle+(dl/data%State%TD_WellGeo(kk)%RCurvature) !???????????????????
  351. !print*, 'StartAngle4=' ,ii , kk, StartAngle
  352. !print*, 'EndAngle4=' ,ii , kk, EndAngle
  353. data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle))*cos(abs(StartAngle)))-(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(EndAngle)-abs(StartAngle)))*sin(abs(StartAngle)))
  354. data%State%TDGeo%Angle(ii) = EndAngle
  355. !data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle)))
  356. !print*, 'mm=' ,mm
  357. !print*, 'data%State%TDGeo%TVD(ii)4=' ,ii , kk, data%State%TDGeo%TVD(ii)
  358. else if ( data%State%TD_WellGeo(kk)%HoleType==2 ) then
  359. EndAngle = StartAngle-(dl/data%State%TD_WellGeo(kk)%RCurvature) !???????????????????
  360. !print*, 'StartAngle44=' ,ii , kk, StartAngle
  361. !print*, 'EndAngle44=' ,ii , kk, EndAngle
  362. data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(abs(EndAngle)-abs(StartAngle)))*cos(abs(StartAngle)))+(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(abs(EndAngle)-abs(StartAngle))))*sin(abs(StartAngle)))
  363. data%State%TDGeo%Angle(ii) = EndAngle
  364. !data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle)))
  365. !print*, 'mm=' ,mm , (data%State%TD_WellGeo(kk)%RCurvature*sin(abs(abs(EndAngle)-abs(StartAngle)))*cos(abs(StartAngle)))+(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(abs(EndAngle)-abs(StartAngle))))*sin(abs(StartAngle)))
  366. !print*, 'data%State%TDGeo%TVD(ii)44=' ,ii , kk, data%State%TDGeo%TVD(ii)
  367. end if
  368. mm = data%State%TDGeo%TVD(ii)
  369. k = kk
  370. exit
  371. end if
  372. end if
  373. end do
  374. End Do
  375. !if (data%State%F_Counts%OutOfWellIntervalCounts==1) then
  376. ! s = 2
  377. !else
  378. ! s = data%State%F_Counts%OutOfWellIntervalCounts
  379. !end if
  380. !
  381. Do ii = (data%State%F_Counts%OutOfWellIntervalCounts+1),data%State%F_Counts%IntervalsTotalCounts
  382. do kk = jj,1,-1
  383. if ( data%State%F_Interval(ii)%StartDepth==data%State%TDGeo%MD(kk) ) then
  384. data%State%F_Interval(ii)%StartTVD = data%State%TDGeo%TVD(kk) ![ft]
  385. data%State%F_Interval(ii)%StartAngle = data%State%TDGeo%Angle(kk) ![rad]
  386. end if
  387. if ( data%State%F_Interval(ii)%EndDepth==data%State%TDGeo%MD(kk) ) then
  388. data%State%F_Interval(ii)%EndTVD = data%State%TDGeo%TVD(kk) ![ft]
  389. data%State%F_Interval(ii)%EndAngle = data%State%TDGeo%Angle(kk) ![rad]
  390. end if
  391. end do
  392. End Do
  393. !Do ii=1,(data%State%F_Counts%IntervalsTotalCounts)
  394. ! print*, 'data%State%F_Interval(ii)%StartTVD=' , ii , data%State%F_Interval(ii)%StartTVD
  395. ! print*, 'data%State%F_Interval(ii)%EndTVD=' , ii , data%State%F_Interval(ii)%EndTVD
  396. ! print*, 'data%State%F_Interval(ii)%StartAngle=' , ii , data%State%F_Interval(ii)%StartAngle
  397. ! print*, 'data%State%F_Interval(ii)%EndAngle=' , ii , data%State%F_Interval(ii)%EndAngle
  398. !end do
  399. !
  400. !
  401. !Do ii=1,data%State%TD_WellGeneral%WellIntervalsCount
  402. ! print*, 'data%State%TD_WellGeo(kk)%TopDepth=' , ii , data%State%TD_WellGeo(ii)%TopDepth
  403. ! print*, 'data%State%TD_WellGeo(kk)%DownDepth=' , ii , data%State%TD_WellGeo(ii)%DownDepth
  404. ! print*, 'data%State%TD_WellGeo(kk)%HoleType=' , ii , data%State%TD_WellGeo(ii)%HoleType
  405. ! print*, 'data%State%TD_WellGeo(kk)%RCurvature=' , ii , data%State%TD_WellGeo(ii)%RCurvature
  406. ! print*, 'data%State%TD_WellGeo(kk)%EndAngle=' , ii , data%State%TD_WellGeo(ii)%EndAngle
  407. ! print*, 'data%State%TD_WellGeo(kk)%StartAngle=' , ii , data%State%TD_WellGeo(ii)%StartAngle
  408. !end do
  409. end subroutine