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.
 
 
 
 
 
 

280 lines
13 KiB

  1. # 1 "/home/admin/SimulationCore2/CSharp/DownHole/DownHole.f90"
  2. module DownHoleModule
  3. use SimulationVariables
  4. contains
  5. subroutine DownHoleToJson(parent)
  6. type(json_value),pointer :: parent
  7. type(json_core) :: json
  8. type(json_value),pointer :: p,jsonarray,pitem
  9. integer::i
  10. ! 1. create new node
  11. call json%create_object(p,'DownHole')
  12. ! 2. add member of data type to new node
  13. call json%add(p,"DrillPipePressure",data%Equipments%DownHole%DrillPipePressure)
  14. call json%add(p,"CasingPressure",data%Equipments%DownHole%CasingPressure)
  15. call json%add(p,"ShoePressure",data%Equipments%DownHole%ShoePressure)
  16. call json%add(p,"BottomHolePressure",data%Equipments%DownHole%BottomHolePressure)
  17. call json%add(p,"FormationPressure",data%Equipments%DownHole%FormationPressure)
  18. call json%add(p,"InfluxRate",data%Equipments%DownHole%InfluxRate)
  19. call json%add(p,"KickVolume",data%Equipments%DownHole%KickVolume)
  20. call json%add(p,"SecondKickVolume",data%Equipments%DownHole%SecondKickVolume)
  21. call json%add(p,"PermeabilityExposedHeight",data%Equipments%DownHole%PermeabilityExposedHeight)
  22. call json%create_array(jsonarray, 'String')
  23. do i = 1, data%Equipments%DownHole%StringCount
  24. call json%create_object(pitem,'')
  25. call json%add(pitem,'StartMd', data%Equipments%DownHole%String(i)%StartMd)
  26. call json%add(pitem,'EndMd', data%Equipments%DownHole%String(i)%EndMd)
  27. call json%add(pitem,'ComponentType', data%Equipments%DownHole%String(i)%ComponentType)
  28. call json%add(jsonarray,pitem)
  29. nullify(pitem)
  30. enddo
  31. call json%add(p,jsonarray)
  32. nullify(jsonarray)
  33. call json%create_array(jsonarray, 'StringFluids')
  34. do i = 1, data%Equipments%DownHole%StringCount
  35. call json%create_object(pitem,'')
  36. call json%add(pitem,'StartMd', data%Equipments%DownHole%StringFluids(i)%StartMd)
  37. call json%add(pitem,'EndMd', data%Equipments%DownHole%StringFluids(i)%EndMd)
  38. call json%add(pitem,'Density', data%Equipments%DownHole%StringFluids(i)%Density)
  39. call json%add(pitem,'MudType', data%Equipments%DownHole%StringFluids(i)%MudType)
  40. call json%add(jsonarray,pitem)
  41. nullify(pitem)
  42. enddo
  43. call json%add(p,jsonarray)
  44. nullify(jsonarray)
  45. ! call json%create_array(jsonarray, 'AnnalusFluids')
  46. ! do i = 1, data%Equipments%DownHole%AnnalusFluidsCount
  47. ! call json%create_object(pitem,'')
  48. ! call json%add(pitem,'StartMd', data%Equipments%DownHole%AnnalusFluids(i)%StartMd)
  49. ! call json%add(pitem,'EndMd', data%Equipments%DownHole%AnnalusFluids(i)%EndMd)
  50. ! call json%add(pitem,'Density', data%Equipments%DownHole%AnnalusFluids(i)%Density)
  51. ! call json%add(pitem,'MudType', data%Equipments%DownHole%AnnalusFluids(i)%MudType)
  52. ! call json%add(jsonarray,pitem)
  53. ! nullify(pitem)
  54. ! enddo
  55. ! call json%add(p,jsonarray)
  56. nullify(jsonarray)
  57. call json%create_array(jsonarray, 'BOPElements')
  58. do i = 1, 4
  59. call json%create_object(pitem,'')
  60. call json%add(pitem,'ElementType', data%Equipments%DownHole%BOPElements(i)%ElementType)
  61. call json%add(pitem,'ElementStart', data%Equipments%DownHole%BOPElements(i)%ElementStart)
  62. call json%add(pitem,'ElementEnd', data%Equipments%DownHole%BOPElements(i)%ElementEnd)
  63. call json%add(jsonarray,pitem)
  64. nullify(pitem)
  65. enddo
  66. call json%add(p,jsonarray)
  67. nullify(jsonarray)
  68. ! 3. add new node to parent
  69. call json%add(parent,p)
  70. end subroutine
  71. subroutine SetAnnalusFluids(count, array)
  72. implicit none
  73. integer, intent(in) :: count
  74. integer :: i, offset
  75. type(CFluid), intent(inout), target :: array(count)
  76. type(CFluid), pointer :: item
  77. ! data%Equipments%DownHole%AnnalusFluidsCount = count
  78. ! if(print_log) print*, 'AnnalusFluidsCount = ', count
  79. if(size(data%Equipments%DownHole%AnnalusFluids) > 0) then
  80. deallocate(data%Equipments%DownHole%AnnalusFluids)
  81. end if
  82. if(count > 0) then
  83. offset = 0;
  84. item => array(1)
  85. if(item%StartMd > 0) then
  86. data%Equipments%DownHole%AnnalusFluidsCount = data%Equipments%DownHole%AnnalusFluidsCount + 1
  87. offset = 1;
  88. allocate(data%Equipments%DownHole%AnnalusFluids(data%Equipments%DownHole%AnnalusFluidsCount))
  89. data%Equipments%DownHole%AnnalusFluids(1)%StartMd = 0
  90. data%Equipments%DownHole%AnnalusFluids(1)%EndMd = item%StartMd
  91. data%Equipments%DownHole%AnnalusFluids(1)%Density = 0
  92. data%Equipments%DownHole%AnnalusFluids(1)%MudType = FLUID_NO_MUD
  93. endif
  94. !if(associated(AnnalusMudCountPtr)) then
  95. ! call AnnalusMudCountPtr(AnnalusFluidsCount)
  96. !end if
  97. if(.not.allocated(data%Equipments%DownHole%AnnalusFluids))allocate(data%Equipments%DownHole%AnnalusFluids(data%Equipments%DownHole%AnnalusFluidsCount))
  98. !if(print_log) print*, '============START-AN============'
  99. if(item%StartMd < 0) data%Equipments%DownHole%AnnalusFluids(1)%StartMd = 0
  100. do i = 1, count
  101. item => array(i)
  102. data%Equipments%DownHole%AnnalusFluids(i + offset)%StartMd = item%StartMd
  103. if(i==1) data%Equipments%DownHole%AnnalusFluids(i)%StartMd = 0
  104. !if(print_log) print*, 'AnnalusFluids(',i,')%StartMd=', AnnalusFluids(i)%StartMd
  105. data%Equipments%DownHole%AnnalusFluids(i + offset)%EndMd = item%EndMd
  106. !if(print_log) print*, 'AnnalusFluids(',i,')%EndMd=', AnnalusFluids(i)%EndMd
  107. data%Equipments%DownHole%AnnalusFluids(i + offset)%Density = item%Density
  108. !if(print_log) print*, 'AnnalusFluids(',i,')%Density=', AnnalusFluids(i)%Density
  109. data%Equipments%DownHole%AnnalusFluids(i + offset)%MudType = item%MudType
  110. !if(print_log) print*, 'AnnalusFluids(',i,')%MudType=', AnnalusFluids(i)%MudType
  111. !if(print_log) print*, '----------------------------'
  112. end do
  113. !if(print_log) print*, '============END-AN============'
  114. !if(associated(AnnalusMudArrayPtr)) then
  115. ! !AnnalusFluidsPtr => AnnalusFluids
  116. ! call AnnalusMudArrayPtr(AnnalusFluids)
  117. !end if
  118. end if
  119. end subroutine SetAnnalusFluids
  120. subroutine SetStringFluids(count, array)
  121. implicit none
  122. integer, intent(in) :: count
  123. integer :: i, offset !, startArr
  124. type(CFluid), intent(inout), target :: array(count)
  125. type(CFluid), pointer :: item
  126. data%Equipments%DownHole%StringFluidsCount = count
  127. ! if(print_log) print*, 'StringFluidsCount = ', count
  128. if(size(data%Equipments%DownHole%StringFluids) > 0) then
  129. deallocate(data%Equipments%DownHole%StringFluids)
  130. end if
  131. !startArr = 1
  132. if(count > 0) then
  133. offset = 0;
  134. item => array(1)
  135. !
  136. !if(item%StartMd <= 0 .and. item%EndMd <= 0) then
  137. ! StringFluidsCount = StringFluidsCount - 1
  138. ! count = count - 1
  139. ! offset = offset + 1
  140. ! startArr = startArr + 1
  141. !endif
  142. !
  143. !if(count <= 0) return
  144. if(item%StartMd > 0) then
  145. data%Equipments%DownHole%StringFluidsCount = data%Equipments%DownHole%StringFluidsCount + 1
  146. offset = offset + 1
  147. allocate(data%Equipments%DownHole%StringFluids(data%Equipments%DownHole%StringFluidsCount))
  148. data%Equipments%DownHole%StringFluids(1)%StartMd = 0
  149. data%Equipments%DownHole%StringFluids(1)%EndMd = item%StartMd
  150. data%Equipments%DownHole%StringFluids(1)%Density = 0
  151. data%Equipments%DownHole%StringFluids(1)%MudType = FLUID_NO_MUD
  152. endif
  153. !if(associated(StringMudCountPtr)) then
  154. ! call StringMudCountPtr(count)
  155. !end if
  156. if(.not.allocated(data%Equipments%DownHole%StringFluids))allocate(data%Equipments%DownHole%StringFluids(data%Equipments%DownHole%StringFluidsCount))
  157. !if(print_log) print*, '============START-ST============'
  158. !if(print_log) print*, 'count=', count
  159. do i = 1, count
  160. item => array(i)
  161. data%Equipments%DownHole%StringFluids(i + offset)%StartMd = item%StartMd
  162. if(i==1) data%Equipments%DownHole%StringFluids(i)%StartMd = 0
  163. !if(print_log) print*, 'StringFluids(i)%StartMd=', StringFluids(i)%StartMd
  164. data%Equipments%DownHole%StringFluids(i + offset)%EndMd = item%EndMd
  165. !if(print_log) print*, 'StringFluids(i)%EndMd=', StringFluids(i)%EndMd
  166. data%Equipments%DownHole%StringFluids(i + offset)%Density = item%Density
  167. data%Equipments%DownHole%StringFluids(i + offset)%MudType = item%MudType
  168. !if(print_log) print*, '----------------------------'
  169. end do
  170. !!if(item%StartMd < 0) StringFluids(1)%StartMd = 0
  171. !!if(print_log) print*, '============END-ST============'
  172. !if(associated(StringMudArrayPtr)) then
  173. ! call StringMudArrayPtr(StringFluids)
  174. !end if
  175. end if
  176. end subroutine SetStringFluids
  177. subroutine SetString(count, array)
  178. use CLog3
  179. implicit none
  180. integer, intent(in) :: count
  181. integer :: i !, j
  182. type(CStringComponents), intent(inout), target :: array(count)
  183. type(CStringComponents), pointer :: item
  184. data%Equipments%DownHole%StringCount = count
  185. if(size(data%Equipments%DownHole%String) > 0) then
  186. deallocate(data%Equipments%DownHole%String)
  187. end if
  188. if(count > 0) then
  189. !if(associated(StringComponentCountPtr)) then
  190. ! call StringComponentCountPtr(count)
  191. !end if
  192. allocate(data%Equipments%DownHole%String(count))
  193. !j = 0
  194. !if(print_log) print*, '============CMP-ST============'
  195. !call Log_3( '============CMP-ST============')
  196. !do i = count, 1, -1
  197. do i = 1, count
  198. item => array(i)
  199. !String(i)%Length = item%Length
  200. !String(i)%TopDepth = item%TopDepth
  201. !String(i)%DownDepth = item%DownDepth
  202. !String(i)%Od = item%Od
  203. !String(i)%Id = item%Id
  204. data%Equipments%DownHole%String(i)%ComponentType= item%ComponentType
  205. !j = j + 1
  206. data%Equipments%DownHole%String(i)%StartMd = item%TopDepth
  207. data%Equipments%DownHole%String(i)%EndMd = item%DownDepth
  208. data%Equipments%DownHole%String(i)%ComponentType=0
  209. !if(item%ComponentType > 4 ) then
  210. ! String(i)%ComponentType=0
  211. ! String(i)%StartMd = 0
  212. !endif
  213. if(item%ComponentType == 3) data%Equipments%DownHole%String(i)%ComponentType=0
  214. if(item%ComponentType == 4) data%Equipments%DownHole%String(i)%ComponentType=1
  215. if(item%ComponentType == 2) data%Equipments%DownHole%String(i)%ComponentType=2
  216. if(item%ComponentType == 1) data%Equipments%DownHole%String(i)%ComponentType=3
  217. !if(print_log) print*, 'item%ComponentType=', item%ComponentType
  218. !if(print_log) print*, 'String(i)%ComponentType=', String(i)%ComponentType
  219. !if(print_log) print*, 'String(i)%StartMd=', String(i)%StartMd
  220. !if(print_log) print*, 'String(i)%EndMd=', String(i)%EndMd
  221. !if(print_log) print*, '----------------------------'
  222. !call Log_3( 'item%ComponentType=', item%ComponentType)
  223. !call Log_3( 'String(i)%ComponentType=', String(i)%ComponentType)
  224. !call Log_3( 'String(i)%StartMd=', String(i)%StartMd)
  225. !call Log_3( 'String(i)%EndMd=', String(i)%EndMd)
  226. !call Log_3( '----------------------------')
  227. end do
  228. !!if(print_log) print*, '============CMP-ST============'
  229. !!call Log_3( '============CMP-ST============')
  230. !if(associated(StringComponentArrayPtr)) then
  231. ! call StringComponentArrayPtr(String)
  232. !end if
  233. end if
  234. end subroutine SetString
  235. subroutine SetBopElements(array)
  236. use CLog4
  237. implicit none
  238. integer, parameter :: count = 4
  239. integer :: i = 1 !, j
  240. type(CBopElement), intent(inout), target :: array(count)
  241. type(CBopElement), pointer :: item
  242. if(size(data%Equipments%DownHole%BopElements) > 0) deallocate(data%Equipments%DownHole%BopElements)
  243. allocate(data%Equipments%DownHole%BopElements(count))
  244. do i = 1, count
  245. item => array(i)
  246. !call Log_4('item%ElementStart', item%ElementStart)
  247. !call Log_4('item%ElementEnd', item%ElementEnd)
  248. !call Log_4('item%ElementType', item%ElementType)
  249. !call Log_4('=====================================================')
  250. data%Equipments%DownHole%BopElements(i)%ElementStart = item%ElementStart
  251. data%Equipments%DownHole%BopElements(i)%ElementEnd = item%ElementEnd
  252. data%Equipments%DownHole%BopElements(i)%ElementType = item%ElementType
  253. end do
  254. !if(associated(BopElementsPtr)) call BopElementsPtr(BopElements)
  255. end subroutine SetBopElements
  256. end module DownHoleModule