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.

MeshGeneration_FluidModule.f90 25 KiB

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