modupdate.F90 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130
  1. !
  2. ! $Id: modupdate.F90 4779 2014-09-19 14:21:37Z rblod $
  3. !
  4. ! AGRIF (Adaptive Grid Refinement In Fortran)
  5. !
  6. ! Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
  7. ! Christophe Vouland (Christophe.Vouland@imag.fr)
  8. !
  9. ! This program is free software; you can redistribute it and/or modify
  10. ! it under the terms of the GNU General Public License as published by
  11. ! the Free Software Foundation; either version 2 of the License, or
  12. ! (at your option) any later version.
  13. !
  14. ! This program is distributed in the hope that it will be useful,
  15. ! but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ! GNU General Public License for more details.
  18. !
  19. ! You should have received a copy of the GNU General Public License
  20. ! along with this program; if not, write to the Free Software
  21. ! Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
  22. !
  23. !> Module Agrif_Update
  24. !>
  25. !> This module contains procedures to update a parent grid from its child grids.
  26. !
  27. module Agrif_Update
  28. !
  29. use Agrif_UpdateBasic
  30. use Agrif_Arrays
  31. use Agrif_CurgridFunctions
  32. use Agrif_Mask
  33. #if defined AGRIF_MPI
  34. use Agrif_Mpp
  35. #endif
  36. !
  37. implicit none
  38. !
  39. logical, private :: precomputedone(7) = .FALSE.
  40. !
  41. contains
  42. !
  43. !===================================================================================================
  44. ! subroutine Agrif_UpdateVariable
  45. !
  46. !> subroutine to set arguments for Agrif_UpdatenD
  47. !---------------------------------------------------------------------------------------------------
  48. subroutine Agrif_UpdateVariable ( parent, child, updateinf, updatesup, procname )
  49. !---------------------------------------------------------------------------------------------------
  50. type(Agrif_Variable), pointer :: parent !< Variable on the parent grid
  51. type(Agrif_Variable), pointer :: child !< Variable on the child grid
  52. integer, dimension(6), intent(in) :: updateinf !< First positions where interpolations are calculated
  53. integer, dimension(6), intent(in) :: updatesup !< Last positions where interpolations are calculated
  54. procedure() :: procname !< Data recovery procedure
  55. !---------------------------------------------------------------------------------------------------
  56. integer, dimension(6) :: nb_child ! Number of cells on the child grid
  57. integer, dimension(6) :: lb_child
  58. integer, dimension(6) :: ub_child
  59. integer, dimension(6) :: lb_parent
  60. real , dimension(6) :: s_child ! Child grid position (s_root = 0)
  61. real , dimension(6) :: s_parent ! Parent grid position (s_root = 0)
  62. real , dimension(6) :: ds_child ! Child grid dx (ds_root = 1)
  63. real , dimension(6) :: ds_parent ! Parent grid dx (ds_root = 1)
  64. logical, dimension(6) :: do_update ! Indicates if we perform update for each dimension
  65. integer, dimension(6) :: posvar ! Position of the variable on the cell (1 or 2)
  66. integer, dimension(6) :: oldparentlbound, oldparentubound
  67. integer :: n, nbdim
  68. logical :: wholeupdate
  69. type(Agrif_Variable), pointer :: root ! Variable on the root grid
  70. !
  71. root => child % root_var
  72. nbdim = root % nbdim
  73. !
  74. call PreProcessToInterpOrUpdate( parent, child, &
  75. nb_child, ub_child, &
  76. lb_child, lb_parent, &
  77. s_child, s_parent, &
  78. ds_child, ds_parent, nbdim, interp=.false. )
  79. !
  80. do_update(:) = .true.
  81. posvar(1:nbdim) = root % posvar(1:nbdim)
  82. !
  83. do n = 1,nbdim
  84. !
  85. if ( root % interptab(n) == 'N' ) then
  86. posvar(n) = 1
  87. do_update(n) = .false.
  88. oldparentlbound(n) = parent % lb(n)
  89. oldparentubound(n) = parent % ub(n)
  90. parent % lb(n) = child % lb(n)
  91. parent % ub(n) = child % ub(n)
  92. end if
  93. !
  94. enddo
  95. wholeupdate = .FALSE.
  96. !
  97. do n = 1,nbdim
  98. if ( do_update(n) ) then
  99. if ( (updateinf(n) > updatesup(n)) .OR. &
  100. ((updateinf(n) == -99) .AND. (updatesup(n) == -99)) &
  101. ) then
  102. wholeupdate = .TRUE.
  103. endif
  104. endif
  105. enddo
  106. !
  107. IF (wholeupdate) THEN
  108. call Agrif_UpdateWhole(parent, child, &
  109. updateinf(1:nbdim), updatesup(1:nbdim), &
  110. lb_child(1:nbdim), lb_parent(1:nbdim), &
  111. nb_child(1:nbdim), posvar(1:nbdim), &
  112. do_update(1:nbdim), &
  113. s_child(1:nbdim), s_parent(1:nbdim), &
  114. ds_child(1:nbdim), ds_parent(1:nbdim), nbdim, procname)
  115. ELSE
  116. call Agrif_UpdateBcnD(parent, child, &
  117. updateinf(1:nbdim), updatesup(1:nbdim), &
  118. lb_child(1:nbdim), lb_parent(1:nbdim), &
  119. nb_child(1:nbdim), posvar(1:nbdim), &
  120. do_update(1:nbdim), &
  121. s_child(1:nbdim), s_parent(1:nbdim), &
  122. ds_child(1:nbdim), ds_parent(1:nbdim), nbdim, procname)
  123. ENDIF
  124. !
  125. do n = 1,nbdim
  126. !
  127. if ( root % interptab(n) == 'N' ) then ! No space DIMENSION
  128. parent % lb(n) = oldparentlbound(n)
  129. parent % ub(n) = oldparentubound(n)
  130. end if
  131. !
  132. enddo
  133. !---------------------------------------------------------------------------------------------------
  134. end subroutine Agrif_UpdateVariable
  135. !===================================================================================================
  136. !
  137. !===================================================================================================
  138. ! subroutine Agrif_UpdateWhole
  139. !---------------------------------------------------------------------------------------------------
  140. subroutine Agrif_UpdateWhole ( parent, child, uinf, usup, &
  141. lb_child, lb_parent, &
  142. nb_child, posvar, &
  143. do_update, &
  144. s_child, s_parent, &
  145. ds_child, ds_parent, nbdim, procname )
  146. !---------------------------------------------------------------------------------------------------
  147. #if defined AGRIF_MPI
  148. include 'mpif.h'
  149. #endif
  150. !
  151. type(Agrif_Variable), pointer :: parent !< Variable on the parent grid
  152. type(Agrif_Variable), pointer :: child !< Variable on the child grid
  153. integer, dimension(nbdim), intent(in) :: uinf !< First positions where interpolations are calculated
  154. integer, dimension(nbdim), intent(in) :: usup !< Last positions where interpolations are calculated
  155. integer, intent(in) :: nbdim !< Number of dimensions of the grid variable
  156. integer, dimension(nbdim), intent(in) :: lb_child !< Index of the first point inside the domain for the parent grid variable
  157. integer, dimension(nbdim), intent(in) :: lb_parent !< Index of the first point inside the domain for the child grid variable
  158. integer, dimension(nbdim), intent(in) :: nb_child !< Number of cells of the child grid
  159. integer, dimension(nbdim), intent(in) :: posvar !< Position of the variable on the cell (1 or 2)
  160. logical, dimension(nbdim), intent(in) :: do_update !< Indicates if we update for each dimension
  161. real, dimension(nbdim), intent(in) :: s_child !< Positions of the child grid
  162. real, dimension(nbdim), intent(in) :: s_parent !< Positions of the parent grid
  163. real, dimension(nbdim), intent(in) :: ds_child !< Space steps of the child grid
  164. real, dimension(nbdim), intent(in) :: ds_parent !< Space steps of the parent grid
  165. procedure() :: procname !< Data recovery procedure
  166. !
  167. integer, dimension(nbdim) :: type_update ! Type of update (copy or average)
  168. integer, dimension(nbdim,2) :: lubglob
  169. integer, dimension(nbdim,2,2) :: indtab ! limits of the child grid that will be used in the update scheme
  170. integer, dimension(nbdim,2,2) :: indtruetab ! grid variable where boundary conditions are
  171. integer :: coeffraf, i
  172. integer :: uinfloc, usuploc
  173. !
  174. type_update = child % root_var % type_update(1:nbdim)
  175. !
  176. do i = 1, nbdim
  177. !
  178. if ( do_update(i) ) then
  179. !
  180. coeffraf = nint(ds_parent(i)/ds_child(i))
  181. uinfloc = 0
  182. usuploc = nb_child(i)/coeffraf - 1
  183. IF (posvar(i) == 1) THEN
  184. usuploc = usuploc - 1
  185. ENDIF
  186. IF (uinf(i) > usup(i)) THEN
  187. uinfloc = uinf(i)
  188. usuploc = usuploc - uinf(i)
  189. ENDIF
  190. indtab(i,1,1) = lb_child(i) + (uinfloc + 1) * coeffraf
  191. indtab(i,1,2) = lb_child(i) + (usuploc + 1) * coeffraf
  192. IF ( posvar(i) == 1 ) THEN
  193. IF ( type_update(i) == Agrif_Update_Full_Weighting ) THEN
  194. indtab(i,1,1) = indtab(i,1,1) - (coeffraf - 1)
  195. indtab(i,1,2) = indtab(i,1,2) + (coeffraf - 1)
  196. ELSE IF ( type_update(i) /= Agrif_Update_Copy ) THEN
  197. indtab(i,1,1) = indtab(i,1,1) - coeffraf / 2
  198. indtab(i,1,2) = indtab(i,1,2) + coeffraf / 2
  199. ENDIF
  200. ELSE
  201. indtab(i,1,1) = indtab(i,1,1) - coeffraf
  202. indtab(i,1,2) = indtab(i,1,2) - 1
  203. ! at this point, indices are OK for an average
  204. IF ( type_update(i) == Agrif_Update_Full_Weighting ) THEN
  205. indtab(i,1,1) = indtab(i,1,1) - coeffraf / 2
  206. indtab(i,1,2) = indtab(i,1,2) + coeffraf / 2
  207. ENDIF
  208. ENDIF
  209. !
  210. else ! IF ( .not.do_update(i) ) THEN
  211. !
  212. if ( posvar(i) == 1 ) then
  213. indtab(i,1,1) = lb_child(i)
  214. indtab(i,1,2) = lb_child(i) + nb_child(i)
  215. else
  216. indtab(i,1,1) = lb_child(i)
  217. indtab(i,1,2) = lb_child(i) + nb_child(i) - 1
  218. endif
  219. !
  220. endif
  221. enddo
  222. ! lubglob contains the global lbound and ubound of the child array
  223. ! lubglob(:,1) : global lbound for each dimension
  224. ! lubglob(:,2) : global lbound for each dimension
  225. !
  226. call Agrif_get_var_global_bounds(child, lubglob, nbdim)
  227. !
  228. indtruetab(1:nbdim,1,1) = max(indtab(1:nbdim,1,1), lubglob(1:nbdim,1))
  229. indtruetab(1:nbdim,1,2) = min(indtab(1:nbdim,1,2), lubglob(1:nbdim,2))
  230. !
  231. call Agrif_UpdatenD(type_update, parent, child, &
  232. indtruetab(1:nbdim,1,1), indtruetab(1:nbdim,1,2), &
  233. lb_child(1:nbdim), lb_parent(1:nbdim), &
  234. s_child(1:nbdim), s_parent(1:nbdim), &
  235. ds_child(1:nbdim), ds_parent(1:nbdim), &
  236. #if defined AGRIF_MPI
  237. posvar, do_update, &
  238. #endif
  239. nbdim, procname)
  240. !---------------------------------------------------------------------------------------------------
  241. end subroutine Agrif_UpdateWhole
  242. !===================================================================================================
  243. !
  244. !===================================================================================================
  245. ! subroutine Agrif_UpdateBcnd
  246. !---------------------------------------------------------------------------------------------------
  247. subroutine Agrif_UpdateBcnd ( parent, child, uinf, usup, &
  248. lb_child, lb_parent, &
  249. nb_child, posvar, &
  250. do_update, &
  251. s_child, s_parent, &
  252. ds_child, ds_parent, nbdim, procname )
  253. !---------------------------------------------------------------------------------------------------
  254. #if defined AGRIF_MPI
  255. include 'mpif.h'
  256. #endif
  257. !
  258. type(Agrif_Variable), pointer :: parent !< Variable on the parent grid
  259. type(Agrif_Variable), pointer :: child !< Variable on the child grid
  260. integer, dimension(nbdim), intent(in) :: uinf !< First positions where interpolations are calculated
  261. integer, dimension(nbdim), intent(in) :: usup !< Last positions where interpolations are calculated
  262. integer :: nbdim !< Number of dimensions of the grid variable
  263. integer, dimension(nbdim), intent(in) :: lb_child !< Index of the first point inside the domain for
  264. !! the parent grid variable
  265. integer, dimension(nbdim), intent(in) :: lb_parent !< Index of the first point inside the domain for
  266. !! the child grid variable
  267. integer, dimension(nbdim), intent(in) :: nb_child !< Number of cells of the child grid
  268. integer, dimension(nbdim), intent(in) :: posvar !< Position of the variable on the cell (1 or 2)
  269. logical, dimension(nbdim), intent(in) :: do_update !< Indicates if we update for each dimension
  270. real, dimension(nbdim), intent(in) :: s_child !< Positions of the child grid
  271. real, dimension(nbdim), intent(in) :: s_parent !< Positions of the parent grid
  272. real, dimension(nbdim), intent(in) :: ds_child !< Space steps of the child grid
  273. real, dimension(nbdim), intent(in) :: ds_parent !< Space steps of the parent grid
  274. procedure() :: procname !< Data recovery procedure
  275. !
  276. integer,dimension(nbdim) :: type_update ! Type of update (copy or average)
  277. integer,dimension(nbdim,2) :: lubglob
  278. integer :: i
  279. integer,dimension(nbdim,2,2) :: indtab ! Arrays indicating the limits of the child
  280. integer,dimension(nbdim,2,2) :: indtruetab ! grid variable where boundary conditions are
  281. integer,dimension(nbdim,2,2,nbdim) :: ptres ! calculated
  282. integer :: nb, ndir
  283. integer :: coeffraf
  284. !
  285. type_update = child % root_var % type_update(1:nbdim)
  286. !
  287. DO i = 1, nbdim
  288. coeffraf = nint(ds_parent(i)/ds_child(i))
  289. indtab(i,1,1) = lb_child(i) + (uinf(i) + 1) * coeffraf
  290. indtab(i,1,2) = lb_child(i) + (usup(i) + 1) * coeffraf
  291. indtab(i,2,1) = lb_child(i) + nb_child(i) - (usup(i)+1) * coeffraf
  292. indtab(i,2,2) = lb_child(i) + nb_child(i) - (uinf(i)+1) * coeffraf
  293. IF (posvar(i) == 1) THEN
  294. IF (type_update(i) == Agrif_Update_Full_Weighting) THEN
  295. indtab(i,:,1) = indtab(i,:,1) - (coeffraf - 1)
  296. indtab(i,:,2) = indtab(i,:,2) + (coeffraf - 1)
  297. ELSE IF (type_update(i) /= Agrif_Update_Copy) THEN
  298. indtab(i,:,1) = indtab(i,:,1) - coeffraf / 2
  299. indtab(i,:,2) = indtab(i,:,2) + coeffraf / 2
  300. ENDIF
  301. ELSE
  302. indtab(i,1,1) = indtab(i,1,1) - coeffraf
  303. indtab(i,1,2) = indtab(i,1,2) - 1
  304. indtab(i,2,2) = indtab(i,2,2) + coeffraf - 1
  305. IF (type_update(i) == Agrif_Update_Full_Weighting) THEN
  306. indtab(i,1,1) = indtab(i,1,1) - coeffraf/2
  307. indtab(i,1,2) = indtab(i,1,2) + coeffraf/2
  308. indtab(i,2,1) = indtab(i,2,1) - coeffraf/2
  309. indtab(i,2,2) = indtab(i,2,2) + coeffraf/2
  310. ENDIF
  311. ENDIF
  312. ENDDO
  313. !
  314. call Agrif_get_var_global_bounds(child,lubglob,nbdim)
  315. !
  316. indtruetab(1:nbdim,1,1) = max(indtab(1:nbdim,1,1),lubglob(1:nbdim,1))
  317. indtruetab(1:nbdim,1,2) = max(indtab(1:nbdim,1,2),lubglob(1:nbdim,1))
  318. indtruetab(1:nbdim,2,1) = min(indtab(1:nbdim,2,1),lubglob(1:nbdim,2))
  319. indtruetab(1:nbdim,2,2) = min(indtab(1:nbdim,2,2),lubglob(1:nbdim,2))
  320. !
  321. do nb = 1,nbdim
  322. if ( do_update(nb) ) then
  323. do ndir = 1,2
  324. ptres(nb,1,ndir,nb) = indtruetab(nb,ndir,1)
  325. ptres(nb,2,ndir,nb) = indtruetab(nb,ndir,2)
  326. do i = 1,nbdim
  327. if ( i /= nb ) then
  328. if ( do_update(i) ) then
  329. ptres(i,1,ndir,nb) = indtruetab(i,1,1)
  330. ptres(i,2,ndir,nb) = indtruetab(i,2,2)
  331. else
  332. if (posvar(i) == 1) then
  333. ptres(i,1,ndir,nb) = lb_child(i)
  334. ptres(i,2,ndir,nb) = lb_child(i) + nb_child(i)
  335. else
  336. ptres(i,1,ndir,nb) = lb_child(i)
  337. ptres(i,2,ndir,nb) = lb_child(i) + nb_child(i) - 1
  338. endif
  339. endif
  340. endif
  341. enddo
  342. enddo
  343. endif
  344. enddo
  345. !
  346. do nb = 1,nbdim
  347. if ( do_update(nb) ) then
  348. do ndir = 1,2
  349. call Agrif_UpdatenD(type_update, parent, child, &
  350. ptres(1:nbdim,1,ndir,nb),ptres(1:nbdim,2,ndir,nb), &
  351. lb_child(1:nbdim),lb_parent(1:nbdim), &
  352. s_child(1:nbdim),s_parent(1:nbdim), &
  353. ds_child(1:nbdim),ds_parent(1:nbdim), &
  354. #if defined AGRIF_MPI
  355. posvar,do_update, &
  356. #endif
  357. nbdim,procname,nb,ndir)
  358. enddo
  359. endif
  360. enddo
  361. !---------------------------------------------------------------------------------------------------
  362. end subroutine Agrif_UpdateBcnd
  363. !===================================================================================================
  364. !
  365. !===================================================================================================
  366. ! subroutine Agrif_UpdatenD
  367. !
  368. !> updates a 2D grid variable on the parent grid of the current grid
  369. !---------------------------------------------------------------------------------------------------
  370. subroutine Agrif_UpdatenD ( type_update, parent, child, &
  371. pttab, petab, &
  372. lb_child, lb_parent, &
  373. s_child, s_parent, &
  374. ds_child, ds_parent, &
  375. #if defined AGRIF_MPI
  376. posvar, do_update, &
  377. #endif
  378. nbdim, procname, nb, ndir )
  379. !---------------------------------------------------------------------------------------------------
  380. #if defined AGRIF_MPI
  381. include 'mpif.h'
  382. #endif
  383. !
  384. integer, dimension(6), intent(in) :: type_update !< Type of update (copy or average)
  385. type(Agrif_Variable), pointer :: parent !< Variable of the parent grid
  386. type(Agrif_Variable), pointer :: child !< Variable of the child grid
  387. integer, intent(in) :: nbdim
  388. integer, dimension(nbdim), intent(in) :: pttab !< Index of the first point inside the domain
  389. integer, dimension(nbdim), intent(in) :: petab !< Index of the first point inside the domain
  390. integer, dimension(nbdim), intent(in) :: lb_child !< Index of the first point inside the domain for the child
  391. !! grid variable
  392. integer, dimension(nbdim), intent(in) :: lb_parent !< Index of the first point inside the domain for the parent
  393. !! grid variable
  394. real, dimension(nbdim), intent(in) :: s_child !< Positions of the child grid
  395. real, dimension(nbdim), intent(in) :: s_parent !< Positions of the parent grid
  396. real, dimension(nbdim), intent(in) :: ds_child !< Space steps of the child grid
  397. real, dimension(nbdim), intent(in) :: ds_parent !< Space steps of the parent grid
  398. procedure() :: procname !< Data recovery procedure
  399. integer, optional, intent(in) :: nb, ndir
  400. !---------------------------------------------------------------------------------------------------
  401. integer, dimension(nbdim) :: pttruetab, cetruetab
  402. #if defined AGRIF_MPI
  403. integer, dimension(nbdim) :: posvar !< Position of the variable on the cell (1 or 2)
  404. logical, dimension(nbdim) :: do_update
  405. #endif
  406. integer, dimension(nbdim) :: coords
  407. integer, dimension(nbdim) :: indmin, indmax
  408. integer, dimension(nbdim) :: indminglob, indmaxglob
  409. real , dimension(nbdim) :: s_Child_temp, s_Parent_temp
  410. integer, dimension(nbdim) :: lowerbound,upperbound
  411. integer, dimension(nbdim) :: pttruetabwhole, cetruetabwhole
  412. integer, dimension(nbdim,2,2) :: childarray
  413. integer, dimension(nbdim,2,2) :: parentarray
  414. integer,dimension(nbdim) :: type_update_temp
  415. logical :: memberin, member
  416. integer :: nbin, ndirin
  417. !
  418. #if defined AGRIF_MPI
  419. !
  420. integer,dimension(nbdim) :: indminglob2,indmaxglob2
  421. logical, dimension(0:Agrif_Nbprocs-1) :: sendtoproc1,recvfromproc1
  422. logical, dimension(0:Agrif_Nbprocs-1) :: sendtoproc2,recvfromproc2
  423. integer :: code, local_proc
  424. integer :: i,j,k
  425. integer, dimension(nbdim,4) :: tab3
  426. integer, dimension(nbdim,4,0:Agrif_Nbprocs-1) :: tab4
  427. integer, dimension(nbdim,0:Agrif_Nbprocs-1,8) :: tab4t
  428. integer, dimension(nbdim,0:Agrif_Nbprocs-1,8) :: tab5t
  429. logical :: find_list_update
  430. logical, dimension(0:Agrif_Nbprocs-1) :: memberinall, memberinall2
  431. logical, dimension(1) :: memberin1
  432. !
  433. #endif
  434. !
  435. type(Agrif_Variable), pointer, save :: tempC => NULL() ! Temporary child grid variable
  436. type(Agrif_Variable), pointer, save :: tempP => NULL() ! Temporary parent grid variable
  437. type(Agrif_Variable), pointer, save :: tempCextend => NULL() ! Temporary child
  438. type(Agrif_Variable), pointer, save :: tempPextend => NULL() ! Temporary parent
  439. type(Agrif_Variable), pointer :: tempP_indic, tempP_average
  440. type(Agrif_Variable), pointer :: tempC_indic
  441. logical :: compute_average
  442. real :: coeff_multi
  443. integer :: nb_dimensions
  444. !
  445. ! Get local lower and upper bound of the child variable
  446. call Agrif_get_var_bounds_array(child, lowerbound, upperbound, nbdim)
  447. ! here pttab and petab corresponds to the (global) indices of the points needed in the update
  448. ! pttruetab and cetruetab contains only indices that are present on the local processor
  449. !
  450. coords = child % root_var % coords
  451. !
  452. call Agrif_Childbounds( nbdim, lowerbound, upperbound, pttab, petab, Agrif_Procrank, &
  453. coords, pttruetab, cetruetab, memberin )
  454. call Agrif_Prtbounds( nbdim, indminglob, indmaxglob, s_Parent_temp, s_Child_temp, &
  455. s_child, ds_child, s_parent, ds_parent, &
  456. pttab, petab, lb_child, lb_parent &
  457. #if defined AGRIF_MPI
  458. , posvar, type_update, do_update, pttruetabwhole, cetruetabwhole &
  459. #endif
  460. )
  461. #if defined AGRIF_MPI
  462. !
  463. IF (memberin) THEN
  464. call Agrif_GlobalToLocalBounds(childarray,lowerbound,upperbound, &
  465. pttruetab,cetruetab, coords, &
  466. nbdim, Agrif_Procrank, member)
  467. ENDIF
  468. call Agrif_Prtbounds(nbdim, indmin, indmax, &
  469. s_Parent_temp, s_Child_temp, &
  470. s_child, ds_child, s_parent, ds_parent, &
  471. pttruetab, cetruetab, lb_child, lb_parent, &
  472. posvar, type_update, do_update, &
  473. pttruetabwhole, cetruetabwhole)
  474. !
  475. #else
  476. indmin = indminglob
  477. indmax = indmaxglob
  478. pttruetabwhole = pttruetab
  479. cetruetabwhole = cetruetab
  480. childarray(:,1,2) = pttruetab
  481. childarray(:,2,2) = cetruetab
  482. #endif
  483. IF (.not.present(nb)) THEN
  484. nbin=0
  485. ndirin=0
  486. ELSE
  487. nbin = nb
  488. ndirin = ndir
  489. ENDIF
  490. IF (memberin) THEN
  491. !
  492. IF ( .not.associated(tempC) ) allocate(tempC)
  493. !
  494. call Agrif_array_allocate(tempC,pttruetab,cetruetab,nbdim)
  495. call Agrif_var_set_array_tozero(tempC,nbdim)
  496. SELECT CASE (nbdim)
  497. CASE(1)
  498. CALL procname(tempC%array1, &
  499. childarray(1,1,2),childarray(1,2,2),.TRUE.,nbin,ndirin)
  500. CASE(2)
  501. CALL procname(tempC%array2, &
  502. childarray(1,1,2),childarray(1,2,2), &
  503. childarray(2,1,2),childarray(2,2,2),.TRUE.,nbin,ndirin)
  504. CASE(3)
  505. CALL procname(tempC%array3, &
  506. childarray(1,1,2),childarray(1,2,2), &
  507. childarray(2,1,2),childarray(2,2,2), &
  508. childarray(3,1,2),childarray(3,2,2),.TRUE.,nbin,ndirin)
  509. CASE(4)
  510. CALL procname(tempC%array4, &
  511. childarray(1,1,2),childarray(1,2,2), &
  512. childarray(2,1,2),childarray(2,2,2), &
  513. childarray(3,1,2),childarray(3,2,2), &
  514. childarray(4,1,2),childarray(4,2,2),.TRUE.,nbin,ndirin)
  515. CASE(5)
  516. CALL procname(tempC%array5, &
  517. childarray(1,1,2),childarray(1,2,2), &
  518. childarray(2,1,2),childarray(2,2,2), &
  519. childarray(3,1,2),childarray(3,2,2), &
  520. childarray(4,1,2),childarray(4,2,2), &
  521. childarray(5,1,2),childarray(5,2,2),.TRUE.,nbin,ndirin)
  522. CASE(6)
  523. CALL procname(tempC%array6, &
  524. childarray(1,1,2),childarray(1,2,2), &
  525. childarray(2,1,2),childarray(2,2,2), &
  526. childarray(3,1,2),childarray(3,2,2), &
  527. childarray(4,1,2),childarray(4,2,2), &
  528. childarray(5,1,2),childarray(5,2,2), &
  529. childarray(6,1,2),childarray(6,2,2),.TRUE.,nbin,ndirin)
  530. END SELECT
  531. !
  532. ENDIF
  533. !
  534. #if defined AGRIF_MPI
  535. !
  536. ! tab2 contains the necessary limits of the parent grid for each processor
  537. if (Associated(child%list_update)) then
  538. call Agrif_Find_list_update(child%list_update,pttab,petab, &
  539. lb_child,lb_parent,nbdim, &
  540. find_list_update,tab4t,tab5t,memberinall,memberinall2, &
  541. sendtoproc1,recvfromproc1,sendtoproc2,recvfromproc2)
  542. else
  543. find_list_update = .FALSE.
  544. endif
  545. if (.not.find_list_update) then
  546. tab3(:,1) = pttruetab(:)
  547. tab3(:,2) = cetruetab(:)
  548. tab3(:,3) = pttruetabwhole(:)
  549. tab3(:,4) = cetruetabwhole(:)
  550. !
  551. call MPI_ALLGATHER(tab3,4*nbdim,MPI_INTEGER,tab4,4*nbdim,MPI_INTEGER,Agrif_mpi_comm,code)
  552. if ( .not.associated(tempCextend) ) allocate(tempCextend)
  553. do k=0,Agrif_Nbprocs-1
  554. do j=1,4
  555. do i=1,nbdim
  556. tab4t(i,k,j) = tab4(i,j,k)
  557. enddo
  558. enddo
  559. enddo
  560. memberin1(1) = memberin
  561. call MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall,1,MPI_LOGICAL,Agrif_mpi_comm,code)
  562. call Get_External_Data_first(tab4t(:,:,1),tab4t(:,:,2),tab4t(:,:,3),tab4t(:,:,4), &
  563. nbdim, memberinall, coords, &
  564. sendtoproc1,recvfromproc1, &
  565. tab4t(:,:,5),tab4t(:,:,6),tab4t(:,:,7),tab4t(:,:,8))
  566. endif
  567. call ExchangeSameLevel(sendtoproc1,recvfromproc1,nbdim, &
  568. tab4t(:,:,3),tab4t(:,:,4),tab4t(:,:,5),tab4t(:,:,6), &
  569. tab4t(:,:,7),tab4t(:,:,8),memberin,tempC,tempCextend)
  570. #else
  571. tempCextend => tempC
  572. #endif
  573. !
  574. ! Update of the parent grid (tempP) from the child grid (tempC)
  575. !
  576. IF (memberin) THEN
  577. !
  578. IF ( .not.associated(tempP) ) allocate(tempP)
  579. !
  580. call Agrif_array_allocate(tempP,indmin,indmax,nbdim)
  581. !
  582. if ( nbdim == 1 ) then
  583. tempP % array1 = 0.
  584. call Agrif_Update_1D_Recursive( type_update(1), &
  585. tempP%array1, &
  586. tempCextend%array1, &
  587. indmin(1), indmax(1), &
  588. pttruetabwhole(1), cetruetabwhole(1), &
  589. s_Child_temp(1), s_Parent_temp(1), &
  590. ds_child(1), ds_parent(1) )
  591. IF (Agrif_UseSpecialValueInUpdate) THEN
  592. allocate(tempC_indic)
  593. allocate(tempP_indic)
  594. call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array1),ubound(tempCextend%array1),nbdim)
  595. call Agrif_array_allocate(tempP_indic,lbound(tempP%array1),ubound(tempP%array1),nbdim)
  596. compute_average = .FALSE.
  597. type_update_temp(1:nbdim) = type_update(1:nbdim)
  598. IF (ANY(type_update(1:nbdim) == Agrif_Update_Full_Weighting)) THEN
  599. compute_average = .TRUE.
  600. allocate(tempP_average)
  601. call Agrif_array_allocate(tempP_average,lbound(tempP%array1),ubound(tempP%array1),nbdim)
  602. WHERE (type_update(1:nbdim) == Agrif_Update_Full_Weighting)
  603. type_update_temp(1:nbdim) = Agrif_Update_Average
  604. END WHERE
  605. call Agrif_Update_1D_Recursive( type_update_temp(1), &
  606. tempP_average%array1, &
  607. tempCextend%array1, &
  608. indmin(1), indmax(1), &
  609. pttruetabwhole(1), cetruetabwhole(1), &
  610. s_Child_temp(1), s_Parent_temp(1), &
  611. ds_child(1), ds_parent(1) )
  612. coeff_multi = 1.
  613. do nb_dimensions=1,nbdim
  614. coeff_multi = coeff_multi * nint(ds_parent(nb_dimensions)/ds_child(nb_dimensions))
  615. enddo
  616. ENDIF
  617. WHERE (tempCextend%array1 == Agrif_SpecialValueFineGrid)
  618. tempC_indic%array1 = 0.
  619. ELSEWHERE
  620. tempC_indic%array1 = 1.
  621. END WHERE
  622. Agrif_UseSpecialValueInUpdate = .FALSE.
  623. Agrif_Update_Weights = .TRUE.
  624. call Agrif_Update_1D_Recursive( type_update_temp(1), &
  625. tempP_indic%array1, &
  626. tempC_indic%array1, &
  627. indmin(1), indmax(1), &
  628. pttruetabwhole(1), cetruetabwhole(1), &
  629. s_Child_temp(1), s_Parent_temp(1), &
  630. ds_child(1), ds_parent(1) )
  631. Agrif_UseSpecialValueInUpdate = .TRUE.
  632. Agrif_Update_Weights = .FALSE.
  633. IF (compute_average) THEN
  634. WHERE (tempP_indic%array1 == 0.)
  635. tempP%array1 = Agrif_SpecialValueFineGrid
  636. ELSEWHERE ((tempP_indic%array1 == coeff_multi).AND.(tempP%array1 /= Agrif_SpecialValueFineGrid))
  637. tempP%array1 = tempP%array1 /tempP_indic%array1
  638. ELSEWHERE
  639. tempP%array1 = tempP_average%array1 /tempP_indic%array1
  640. END WHERE
  641. ELSE
  642. WHERE (tempP_indic%array1 == 0.)
  643. tempP%array1 = Agrif_SpecialValueFineGrid
  644. ELSEWHERE
  645. tempP%array1 = tempP%array1 /tempP_indic%array1
  646. END WHERE
  647. ENDIF
  648. deallocate(tempP_indic%array1)
  649. deallocate(tempC_indic%array1)
  650. deallocate(tempC_indic)
  651. deallocate(tempP_indic)
  652. IF (compute_average) THEN
  653. deallocate(tempP_average%array1)
  654. deallocate(tempP_average)
  655. ENDIF
  656. ENDIF
  657. endif
  658. if ( nbdim == 2 ) then
  659. call Agrif_Update_2D_Recursive( type_update(1:2), &
  660. tempP%array2, &
  661. tempCextend%array2, &
  662. indmin(1:2), indmax(1:2), &
  663. pttruetabwhole(1:2), cetruetabwhole(1:2), &
  664. s_Child_temp(1:2), s_Parent_temp(1:2), &
  665. ds_child(1:2), ds_parent(1:2) )
  666. IF (Agrif_UseSpecialValueInUpdate) THEN
  667. allocate(tempC_indic)
  668. allocate(tempP_indic)
  669. call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array2),ubound(tempCextend%array2),nbdim)
  670. call Agrif_array_allocate(tempP_indic,lbound(tempP%array2),ubound(tempP%array2),nbdim)
  671. compute_average = .FALSE.
  672. type_update_temp(1:nbdim) = type_update(1:nbdim)
  673. IF (ANY(type_update == Agrif_Update_Full_Weighting)) THEN
  674. compute_average = .TRUE.
  675. allocate(tempP_average)
  676. call Agrif_array_allocate(tempP_average,lbound(tempP%array2),ubound(tempP%array2),nbdim)
  677. WHERE (type_update(1:nbdim) == Agrif_Update_Full_Weighting)
  678. type_update_temp(1:nbdim) = Agrif_Update_Average
  679. END WHERE
  680. call Agrif_Update_2D_Recursive( type_update_temp(1:2), &
  681. tempP_average%array2, &
  682. tempCextend%array2, &
  683. indmin(1:2), indmax(1:2), &
  684. pttruetabwhole(1:2), cetruetabwhole(1:2), &
  685. s_Child_temp(1:2), s_Parent_temp(1:2), &
  686. ds_child(1:2), ds_parent(1:2) )
  687. coeff_multi = 1.
  688. do nb_dimensions=1,nbdim
  689. coeff_multi = coeff_multi * nint(ds_parent(nb_dimensions)/ds_child(nb_dimensions))
  690. enddo
  691. ENDIF
  692. WHERE (tempCextend%array2 == Agrif_SpecialValueFineGrid)
  693. tempC_indic%array2 = 0.
  694. ELSEWHERE
  695. tempC_indic%array2 = 1.
  696. END WHERE
  697. Agrif_UseSpecialValueInUpdate = .FALSE.
  698. Agrif_Update_Weights = .TRUE.
  699. call Agrif_Update_2D_Recursive( type_update_temp(1:2), &
  700. tempP_indic%array2, &
  701. tempC_indic%array2, &
  702. indmin(1:2), indmax(1:2), &
  703. pttruetabwhole(1:2), cetruetabwhole(1:2), &
  704. s_Child_temp(1:2), s_Parent_temp(1:2), &
  705. ds_child(1:2), ds_parent(1:2) )
  706. Agrif_UseSpecialValueInUpdate = .TRUE.
  707. Agrif_Update_Weights = .FALSE.
  708. IF (compute_average) THEN
  709. WHERE (tempP_indic%array2 == 0.)
  710. tempP%array2 = Agrif_SpecialValueFineGrid
  711. ELSEWHERE ((tempP_indic%array2 == coeff_multi).AND.(tempP%array2 /= Agrif_SpecialValueFineGrid))
  712. tempP%array2 = tempP%array2 /tempP_indic%array2
  713. ELSEWHERE
  714. tempP%array2 = tempP_average%array2 /tempP_indic%array2
  715. END WHERE
  716. ELSE
  717. WHERE (tempP_indic%array2 == 0.)
  718. tempP%array2 = Agrif_SpecialValueFineGrid
  719. ELSEWHERE
  720. tempP%array2 = tempP%array2 /tempP_indic%array2
  721. END WHERE
  722. ENDIF
  723. deallocate(tempP_indic%array2)
  724. deallocate(tempC_indic%array2)
  725. deallocate(tempC_indic)
  726. deallocate(tempP_indic)
  727. IF (compute_average) THEN
  728. deallocate(tempP_average%array2)
  729. deallocate(tempP_average)
  730. ENDIF
  731. ENDIF
  732. endif
  733. if ( nbdim == 3 ) then
  734. call Agrif_Update_3D_Recursive( type_update(1:3), &
  735. tempP%array3, &
  736. tempCextend%array3, &
  737. indmin(1:3), indmax(1:3), &
  738. pttruetabwhole(1:3), cetruetabwhole(1:3), &
  739. s_Child_temp(1:3), s_Parent_temp(1:3), &
  740. ds_child(1:3), ds_parent(1:3) )
  741. IF (Agrif_UseSpecialValueInUpdate) THEN
  742. allocate(tempC_indic)
  743. allocate(tempP_indic)
  744. call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array3),ubound(tempCextend%array3),nbdim)
  745. call Agrif_array_allocate(tempP_indic,lbound(tempP%array3),ubound(tempP%array3),nbdim)
  746. compute_average = .FALSE.
  747. type_update_temp(1:nbdim) = type_update(1:nbdim)
  748. IF (ANY(type_update == Agrif_Update_Full_Weighting)) THEN
  749. compute_average = .TRUE.
  750. allocate(tempP_average)
  751. call Agrif_array_allocate(tempP_average,lbound(tempP%array3),ubound(tempP%array3),nbdim)
  752. WHERE (type_update(1:nbdim) == Agrif_Update_Full_Weighting)
  753. type_update_temp(1:nbdim) = Agrif_Update_Average
  754. END WHERE
  755. call Agrif_Update_3D_Recursive( type_update_temp(1:3), &
  756. tempP_average%array3, &
  757. tempCextend%array3, &
  758. indmin(1:3), indmax(1:3), &
  759. pttruetabwhole(1:3), cetruetabwhole(1:3), &
  760. s_Child_temp(1:3), s_Parent_temp(1:3), &
  761. ds_child(1:3), ds_parent(1:3) )
  762. coeff_multi = 1.
  763. do nb_dimensions=1,nbdim
  764. coeff_multi = coeff_multi * nint(ds_parent(nb_dimensions)/ds_child(nb_dimensions))
  765. enddo
  766. ENDIF
  767. WHERE (tempCextend%array3 == Agrif_SpecialValueFineGrid)
  768. tempC_indic%array3 = 0.
  769. ELSEWHERE
  770. tempC_indic%array3 = 1.
  771. END WHERE
  772. Agrif_UseSpecialValueInUpdate = .FALSE.
  773. Agrif_Update_Weights = .TRUE.
  774. call Agrif_Update_3D_Recursive( type_update_temp(1:3), &
  775. tempP_indic%array3, &
  776. tempC_indic%array3, &
  777. indmin(1:3), indmax(1:3), &
  778. pttruetabwhole(1:3), cetruetabwhole(1:3), &
  779. s_Child_temp(1:3), s_Parent_temp(1:3), &
  780. ds_child(1:3), ds_parent(1:3) )
  781. Agrif_UseSpecialValueInUpdate = .TRUE.
  782. Agrif_Update_Weights = .FALSE.
  783. IF (compute_average) THEN
  784. WHERE (tempP_indic%array3 == 0.)
  785. tempP%array3 = Agrif_SpecialValueFineGrid
  786. ELSEWHERE ((tempP_indic%array3 == coeff_multi).AND.(tempP%array3 /= Agrif_SpecialValueFineGrid))
  787. tempP%array3 = tempP%array3 /tempP_indic%array3
  788. ELSEWHERE
  789. tempP%array3 = tempP_average%array3 /tempP_indic%array3
  790. END WHERE
  791. ELSE
  792. WHERE (tempP_indic%array3 == 0.)
  793. tempP%array3 = Agrif_SpecialValueFineGrid
  794. ELSEWHERE
  795. tempP%array3 = tempP%array3 /tempP_indic%array3
  796. END WHERE
  797. ENDIF
  798. deallocate(tempP_indic%array3)
  799. deallocate(tempC_indic%array3)
  800. deallocate(tempC_indic)
  801. deallocate(tempP_indic)
  802. IF (compute_average) THEN
  803. deallocate(tempP_average%array3)
  804. deallocate(tempP_average)
  805. ENDIF
  806. ENDIF
  807. endif
  808. if ( nbdim == 4 ) then
  809. call Agrif_Update_4D_Recursive( type_update(1:4), &
  810. tempP%array4, &
  811. tempCextend%array4, &
  812. indmin(1:4), indmax(1:4), &
  813. pttruetabwhole(1:4), cetruetabwhole(1:4), &
  814. s_Child_temp(1:4), s_Parent_temp(1:4), &
  815. ds_child(1:4), ds_parent(1:4) )
  816. IF (Agrif_UseSpecialValueInUpdate) THEN
  817. allocate(tempC_indic)
  818. allocate(tempP_indic)
  819. call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array4),ubound(tempCextend%array4),nbdim)
  820. call Agrif_array_allocate(tempP_indic,lbound(tempP%array4),ubound(tempP%array4),nbdim)
  821. compute_average = .FALSE.
  822. type_update_temp(1:nbdim) = type_update(1:nbdim)
  823. IF (ANY(type_update == Agrif_Update_Full_Weighting)) THEN
  824. compute_average = .TRUE.
  825. allocate(tempP_average)
  826. call Agrif_array_allocate(tempP_average,lbound(tempP%array4),ubound(tempP%array4),nbdim)
  827. WHERE (type_update(1:nbdim) == Agrif_Update_Full_Weighting)
  828. type_update_temp(1:nbdim) = Agrif_Update_Average
  829. END WHERE
  830. call Agrif_Update_4D_Recursive( type_update_temp(1:4), &
  831. tempP_average%array4, &
  832. tempCextend%array4, &
  833. indmin(1:4), indmax(1:4), &
  834. pttruetabwhole(1:4), cetruetabwhole(1:4), &
  835. s_Child_temp(1:4), s_Parent_temp(1:4), &
  836. ds_child(1:4), ds_parent(1:4) )
  837. coeff_multi = 1.
  838. do nb_dimensions=1,nbdim
  839. coeff_multi = coeff_multi * nint(ds_parent(nb_dimensions)/ds_child(nb_dimensions))
  840. enddo
  841. ENDIF
  842. WHERE (tempCextend%array4 == Agrif_SpecialValueFineGrid)
  843. tempC_indic%array4 = 0.
  844. ELSEWHERE
  845. tempC_indic%array4 = 1.
  846. END WHERE
  847. Agrif_UseSpecialValueInUpdate = .FALSE.
  848. Agrif_Update_Weights = .TRUE.
  849. call Agrif_Update_4D_Recursive( type_update_temp(1:4), &
  850. tempP_indic%array4, &
  851. tempC_indic%array4, &
  852. indmin(1:4), indmax(1:4), &
  853. pttruetabwhole(1:4), cetruetabwhole(1:4), &
  854. s_Child_temp(1:4), s_Parent_temp(1:4), &
  855. ds_child(1:4), ds_parent(1:4) )
  856. Agrif_UseSpecialValueInUpdate = .TRUE.
  857. Agrif_Update_Weights = .FALSE.
  858. IF (compute_average) THEN
  859. WHERE (tempP_indic%array4 == 0.)
  860. tempP%array4 = Agrif_SpecialValueFineGrid
  861. ELSEWHERE ((tempP_indic%array4 == coeff_multi).AND.(tempP%array4 /= Agrif_SpecialValueFineGrid))
  862. tempP%array4 = tempP%array4 /tempP_indic%array4
  863. ELSEWHERE
  864. tempP%array4 = tempP_average%array4 /tempP_indic%array4
  865. END WHERE
  866. ELSE
  867. WHERE (tempP_indic%array4 == 0.)
  868. tempP%array4 = Agrif_SpecialValueFineGrid
  869. ELSEWHERE
  870. tempP%array4 = tempP%array4 /tempP_indic%array4
  871. END WHERE
  872. ENDIF
  873. deallocate(tempP_indic%array4)
  874. deallocate(tempC_indic%array4)
  875. deallocate(tempC_indic)
  876. deallocate(tempP_indic)
  877. IF (compute_average) THEN
  878. deallocate(tempP_average%array4)
  879. deallocate(tempP_average)
  880. ENDIF
  881. ENDIF
  882. endif
  883. if ( nbdim == 5 ) then
  884. call Agrif_Update_5D_Recursive( type_update(1:5), &
  885. tempP%array5, &
  886. tempCextend%array5, &
  887. indmin(1:5), indmax(1:5), &
  888. pttruetabwhole(1:5), cetruetabwhole(1:5), &
  889. s_Child_temp(1:5), s_Parent_temp(1:5), &
  890. ds_child(1:5), ds_parent(1:5) )
  891. IF (Agrif_UseSpecialValueInUpdate) THEN
  892. allocate(tempC_indic)
  893. allocate(tempP_indic)
  894. call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array5),ubound(tempCextend%array5),nbdim)
  895. call Agrif_array_allocate(tempP_indic,lbound(tempP%array5),ubound(tempP%array5),nbdim)
  896. compute_average = .FALSE.
  897. type_update_temp(1:nbdim) = type_update(1:nbdim)
  898. IF (ANY(type_update == Agrif_Update_Full_Weighting)) THEN
  899. compute_average = .TRUE.
  900. allocate(tempP_average)
  901. call Agrif_array_allocate(tempP_average,lbound(tempP%array5),ubound(tempP%array5),nbdim)
  902. WHERE (type_update(1:nbdim) == Agrif_Update_Full_Weighting)
  903. type_update_temp(1:nbdim) = Agrif_Update_Average
  904. END WHERE
  905. call Agrif_Update_5D_Recursive( type_update_temp(1:5), &
  906. tempP_average%array5, &
  907. tempCextend%array5, &
  908. indmin(1:5), indmax(1:5), &
  909. pttruetabwhole(1:5), cetruetabwhole(1:5), &
  910. s_Child_temp(1:5), s_Parent_temp(1:5), &
  911. ds_child(1:5), ds_parent(1:5) )
  912. coeff_multi = 1.
  913. do nb_dimensions=1,nbdim
  914. coeff_multi = coeff_multi * nint(ds_parent(nb_dimensions)/ds_child(nb_dimensions))
  915. enddo
  916. ENDIF
  917. WHERE (tempCextend%array5 == Agrif_SpecialValueFineGrid)
  918. tempC_indic%array5 = 0.
  919. ELSEWHERE
  920. tempC_indic%array5 = 1.
  921. END WHERE
  922. Agrif_UseSpecialValueInUpdate = .FALSE.
  923. Agrif_Update_Weights = .TRUE.
  924. call Agrif_Update_5D_Recursive( type_update_temp(1:5), &
  925. tempP_indic%array5, &
  926. tempC_indic%array5, &
  927. indmin(1:5), indmax(1:5), &
  928. pttruetabwhole(1:5), cetruetabwhole(1:5), &
  929. s_Child_temp(1:5), s_Parent_temp(1:5), &
  930. ds_child(1:5), ds_parent(1:5) )
  931. Agrif_UseSpecialValueInUpdate = .TRUE.
  932. Agrif_Update_Weights = .FALSE.
  933. IF (compute_average) THEN
  934. WHERE (tempP_indic%array5 == 0.)
  935. tempP%array5 = Agrif_SpecialValueFineGrid
  936. ELSEWHERE ((tempP_indic%array5 == coeff_multi).AND.(tempP%array5 /= Agrif_SpecialValueFineGrid))
  937. tempP%array5 = tempP%array5 /tempP_indic%array5
  938. ELSEWHERE
  939. tempP%array5 = tempP_average%array5 /tempP_indic%array5
  940. END WHERE
  941. ELSE
  942. WHERE (tempP_indic%array5 == 0.)
  943. tempP%array5 = Agrif_SpecialValueFineGrid
  944. ELSEWHERE
  945. tempP%array5 = tempP%array5 /tempP_indic%array5
  946. END WHERE
  947. ENDIF
  948. deallocate(tempP_indic%array5)
  949. deallocate(tempC_indic%array5)
  950. deallocate(tempC_indic)
  951. deallocate(tempP_indic)
  952. IF (compute_average) THEN
  953. deallocate(tempP_average%array5)
  954. deallocate(tempP_average)
  955. ENDIF
  956. ENDIF
  957. endif
  958. if ( nbdim == 6 ) then
  959. call Agrif_Update_6D_Recursive( type_update(1:6), &
  960. tempP%array6, &
  961. tempCextend%array6, &
  962. indmin(1:6), indmax(1:6), &
  963. pttruetabwhole(1:6), cetruetabwhole(1:6), &
  964. s_Child_temp(1:6), s_Parent_temp(1:6), &
  965. ds_child(1:6), ds_parent(1:6) )
  966. IF (Agrif_UseSpecialValueInUpdate) THEN
  967. allocate(tempC_indic)
  968. allocate(tempP_indic)
  969. call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array6),ubound(tempCextend%array6),nbdim)
  970. call Agrif_array_allocate(tempP_indic,lbound(tempP%array6),ubound(tempP%array6),nbdim)
  971. compute_average = .FALSE.
  972. type_update_temp(1:nbdim) = type_update(1:nbdim)
  973. IF (ANY(type_update == Agrif_Update_Full_Weighting)) THEN
  974. compute_average = .TRUE.
  975. allocate(tempP_average)
  976. call Agrif_array_allocate(tempP_average,lbound(tempP%array6),ubound(tempP%array6),nbdim)
  977. type_update_temp(1:nbdim) = type_update
  978. WHERE (type_update(1:nbdim) == Agrif_Update_Full_Weighting)
  979. type_update_temp(1:nbdim) = Agrif_Update_Average
  980. END WHERE
  981. call Agrif_Update_6D_Recursive( type_update_temp(1:6), &
  982. tempP_average%array6, &
  983. tempCextend%array6, &
  984. indmin(1:6), indmax(1:6), &
  985. pttruetabwhole(1:6), cetruetabwhole(1:6), &
  986. s_Child_temp(1:6), s_Parent_temp(1:6), &
  987. ds_child(1:6), ds_parent(1:6) )
  988. coeff_multi = 1.
  989. do nb_dimensions=1,nbdim
  990. coeff_multi = coeff_multi * nint(ds_parent(nb_dimensions)/ds_child(nb_dimensions))
  991. enddo
  992. ENDIF
  993. IF (compute_average) THEN
  994. WHERE (tempP_indic%array6 == 0.)
  995. tempP%array6 = Agrif_SpecialValueFineGrid
  996. ELSEWHERE ((tempP_indic%array6 == coeff_multi).AND.(tempP%array6 /= Agrif_SpecialValueFineGrid))
  997. tempP%array6 = tempP%array6 /tempP_indic%array6
  998. ELSEWHERE
  999. tempP%array6 = tempP_average%array6 /tempP_indic%array6
  1000. END WHERE
  1001. ELSE
  1002. WHERE (tempP_indic%array6 == 0.)
  1003. tempP%array6 = Agrif_SpecialValueFineGrid
  1004. ELSEWHERE
  1005. tempP%array6 = tempP%array6 /tempP_indic%array6
  1006. END WHERE
  1007. ENDIF
  1008. Agrif_UseSpecialValueInUpdate = .FALSE.
  1009. Agrif_Update_Weights = .TRUE.
  1010. call Agrif_Update_6D_Recursive( type_update_temp(1:6), &
  1011. tempP_indic%array6, &
  1012. tempC_indic%array6, &
  1013. indmin(1:6), indmax(1:6), &
  1014. pttruetabwhole(1:6), cetruetabwhole(1:6), &
  1015. s_Child_temp(1:6), s_Parent_temp(1:6), &
  1016. ds_child(1:6), ds_parent(1:6) )
  1017. Agrif_UseSpecialValueInUpdate = .TRUE.
  1018. Agrif_Update_Weights = .FALSE.
  1019. WHERE (tempP_indic%array6 == 0.)
  1020. tempP%array6 = Agrif_SpecialValueFineGrid
  1021. ELSEWHERE
  1022. tempP%array6 = tempP%array6 /tempP_indic%array6
  1023. END WHERE
  1024. deallocate(tempP_indic%array6)
  1025. deallocate(tempC_indic%array6)
  1026. deallocate(tempC_indic)
  1027. deallocate(tempP_indic)
  1028. IF (compute_average) THEN
  1029. deallocate(tempP_average%array6)
  1030. deallocate(tempP_average)
  1031. ENDIF
  1032. ENDIF
  1033. endif
  1034. !
  1035. call Agrif_array_deallocate(tempCextend,nbdim)
  1036. !
  1037. ENDIF
  1038. #if defined AGRIF_MPI
  1039. local_proc = Agrif_Procrank
  1040. call Agrif_get_var_bounds_array(parent,lowerbound,upperbound,nbdim)
  1041. call Agrif_ChildGrid_to_ParentGrid()
  1042. call Agrif_Childbounds(nbdim, lowerbound, upperbound, &
  1043. indminglob, indmaxglob, local_proc, coords, &
  1044. indminglob2, indmaxglob2, member)
  1045. !
  1046. IF (member) THEN
  1047. call Agrif_GlobalToLocalBounds(parentarray, lowerbound, upperbound, &
  1048. indminglob2, indmaxglob2, coords, &
  1049. nbdim, local_proc, member)
  1050. ENDIF
  1051. call Agrif_ParentGrid_to_ChildGrid()
  1052. if (.not.find_list_update) then
  1053. tab3(:,1) = indmin(:)
  1054. tab3(:,2) = indmax(:)
  1055. tab3(:,3) = indminglob2(:)
  1056. tab3(:,4) = indmaxglob2(:)
  1057. !
  1058. call MPI_ALLGATHER(tab3,4*nbdim,MPI_INTEGER,tab4,4*nbdim,MPI_INTEGER,Agrif_mpi_comm,code)
  1059. IF ( .not.associated(tempPextend) ) allocate(tempPextend)
  1060. DO k=0,Agrif_Nbprocs-1
  1061. do j=1,4
  1062. do i=1,nbdim
  1063. tab5t(i,k,j) = tab4(i,j,k)
  1064. enddo
  1065. enddo
  1066. enddo
  1067. memberin1(1) = member
  1068. call MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall2,1,MPI_LOGICAL,Agrif_mpi_comm,code)
  1069. call Get_External_Data_first(tab5t(:,:,1),tab5t(:,:,2),tab5t(:,:,3),tab5t(:,:,4), &
  1070. nbdim, memberinall2, coords, &
  1071. sendtoproc2, recvfromproc2, &
  1072. tab5t(:,:,5),tab5t(:,:,6),tab5t(:,:,7),tab5t(:,:,8))
  1073. call Agrif_Addto_list_update(child%list_update,pttab,petab,lb_child,lb_parent, &
  1074. nbdim,tab4t,tab5t,memberinall,memberinall2, &
  1075. sendtoproc1,recvfromproc1,sendtoproc2,recvfromproc2)
  1076. endif
  1077. call ExchangeSameLevel(sendtoproc2,recvfromproc2,nbdim, &
  1078. tab5t(:,:,3),tab5t(:,:,4),tab5t(:,:,5),tab5t(:,:,6),&
  1079. tab5t(:,:,7),tab5t(:,:,8),member,tempP,tempPextend)
  1080. #else
  1081. tempPextend => tempP
  1082. parentarray(:,1,1) = indmin
  1083. parentarray(:,2,1) = indmax
  1084. parentarray(:,1,2) = indmin
  1085. parentarray(:,2,2) = indmax
  1086. member = .TRUE.
  1087. #endif
  1088. !
  1089. ! Special values on the child grid
  1090. if ( Agrif_UseSpecialValueFineGrid ) then
  1091. !
  1092. !cc noraftab(1:nbdim) =
  1093. !cc & child % root_var % interptab(1:nbdim) == 'N'
  1094. !
  1095. #if defined AGRIF_MPI
  1096. !
  1097. ! allocate(childvalues% var)
  1098. !
  1099. ! Call Agrif_array_allocate(childvalues%var,
  1100. ! & pttruetab,cetruetab,nbdim)
  1101. ! Call Agrif_var_full_copy_array(childvalues% var,
  1102. ! & tempC,
  1103. ! & nbdim)
  1104. ! Call Agrif_CheckMasknD(tempC,childvalues,
  1105. ! & pttruetab(1:nbdim),cetruetab(1:nbdim),
  1106. ! & pttruetab(1:nbdim),cetruetab(1:nbdim),
  1107. ! & noraftab(1:nbdim),nbdim)
  1108. ! Call Agrif_array_deallocate(childvalues% var,nbdim)
  1109. ! Deallocate(childvalues % var)
  1110. !
  1111. #else
  1112. !
  1113. ! Call Agrif_get_var_bounds_array(child,
  1114. ! & lowerbound,upperbound,nbdim)
  1115. ! Call Agrif_CheckMasknD(tempC,child,
  1116. ! & pttruetab(1:nbdim),cetruetab(1:nbdim),
  1117. ! & lowerbound,
  1118. ! & upperbound,
  1119. ! & noraftab(1:nbdim),nbdim)
  1120. !
  1121. #endif
  1122. !
  1123. endif
  1124. !
  1125. ! Special values on the parent grid
  1126. if (Agrif_UseSpecialValue) then
  1127. !
  1128. #if defined AGRIF_MPI
  1129. !
  1130. ! Call GiveAgrif_SpecialValueToTab_mpi(parent,tempP,
  1131. ! & parentarray,
  1132. ! & Agrif_SpecialValue,nbdim)
  1133. !
  1134. !
  1135. #else
  1136. !
  1137. ! Call GiveAgrif_SpecialValueToTab(parent,tempP,
  1138. ! & indmin,indmax,
  1139. ! & Agrif_SpecialValue,nbdim)
  1140. !
  1141. #endif
  1142. !
  1143. endif
  1144. !
  1145. IF (member) THEN
  1146. call Agrif_ChildGrid_to_ParentGrid()
  1147. !
  1148. SELECT CASE(nbdim)
  1149. CASE(1)
  1150. call procname( tempPextend % array1( &
  1151. parentarray(1,1,1):parentarray(1,2,1)), &
  1152. parentarray(1,1,2),parentarray(1,2,2),.FALSE.,nbin,ndirin)
  1153. CASE(2)
  1154. call procname( tempPextend % array2( &
  1155. parentarray(1,1,1):parentarray(1,2,1), &
  1156. parentarray(2,1,1):parentarray(2,2,1)), &
  1157. parentarray(1,1,2),parentarray(1,2,2), &
  1158. parentarray(2,1,2),parentarray(2,2,2),.FALSE.,nbin,ndirin)
  1159. CASE(3)
  1160. call procname( tempPextend % array3( &
  1161. parentarray(1,1,1):parentarray(1,2,1), &
  1162. parentarray(2,1,1):parentarray(2,2,1), &
  1163. parentarray(3,1,1):parentarray(3,2,1)), &
  1164. parentarray(1,1,2),parentarray(1,2,2), &
  1165. parentarray(2,1,2),parentarray(2,2,2), &
  1166. parentarray(3,1,2),parentarray(3,2,2),.FALSE.,nbin,ndirin)
  1167. CASE(4)
  1168. call procname( tempPextend % array4( &
  1169. parentarray(1,1,1):parentarray(1,2,1), &
  1170. parentarray(2,1,1):parentarray(2,2,1), &
  1171. parentarray(3,1,1):parentarray(3,2,1), &
  1172. parentarray(4,1,1):parentarray(4,2,1)), &
  1173. parentarray(1,1,2),parentarray(1,2,2), &
  1174. parentarray(2,1,2),parentarray(2,2,2), &
  1175. parentarray(3,1,2),parentarray(3,2,2), &
  1176. parentarray(4,1,2),parentarray(4,2,2),.FALSE.,nbin,ndirin)
  1177. CASE(5)
  1178. call procname( tempPextend % array5( &
  1179. parentarray(1,1,1):parentarray(1,2,1), &
  1180. parentarray(2,1,1):parentarray(2,2,1), &
  1181. parentarray(3,1,1):parentarray(3,2,1), &
  1182. parentarray(4,1,1):parentarray(4,2,1), &
  1183. parentarray(5,1,1):parentarray(5,2,1)), &
  1184. parentarray(1,1,2),parentarray(1,2,2), &
  1185. parentarray(2,1,2),parentarray(2,2,2), &
  1186. parentarray(3,1,2),parentarray(3,2,2), &
  1187. parentarray(4,1,2),parentarray(4,2,2), &
  1188. parentarray(5,1,2),parentarray(5,2,2),.FALSE.,nbin,ndirin)
  1189. CASE(6)
  1190. call procname( tempPextend % array6( &
  1191. parentarray(1,1,1):parentarray(1,2,1), &
  1192. parentarray(2,1,1):parentarray(2,2,1), &
  1193. parentarray(3,1,1):parentarray(3,2,1), &
  1194. parentarray(4,1,1):parentarray(4,2,1), &
  1195. parentarray(5,1,1):parentarray(5,2,1), &
  1196. parentarray(6,1,1):parentarray(6,2,1)), &
  1197. parentarray(1,1,2),parentarray(1,2,2), &
  1198. parentarray(2,1,2),parentarray(2,2,2), &
  1199. parentarray(3,1,2),parentarray(3,2,2), &
  1200. parentarray(4,1,2),parentarray(4,2,2), &
  1201. parentarray(5,1,2),parentarray(5,2,2), &
  1202. parentarray(6,1,2),parentarray(6,2,2),.FALSE.,nbin,ndirin)
  1203. END SELECT
  1204. !
  1205. call Agrif_ParentGrid_to_ChildGrid()
  1206. !
  1207. call Agrif_array_deallocate(tempPextend,nbdim)
  1208. !
  1209. ENDIF
  1210. !
  1211. #if defined AGRIF_MPI
  1212. IF (memberin) THEN
  1213. call Agrif_array_deallocate(tempP,nbdim)
  1214. call Agrif_array_deallocate(tempC,nbdim)
  1215. ENDIF
  1216. #endif
  1217. !---------------------------------------------------------------------------------------------------
  1218. end subroutine Agrif_UpdatenD
  1219. !===================================================================================================
  1220. !
  1221. !===================================================================================================
  1222. ! subroutine Agrif_Prtbounds
  1223. !
  1224. !> calculates the bounds of the parent grid to be updated by the child grid
  1225. !---------------------------------------------------------------------------------------------------
  1226. subroutine Agrif_Prtbounds ( nbdim, indmin, indmax, s_Parent_temp, s_Child_temp, &
  1227. s_child, ds_child, s_parent, ds_parent, &
  1228. pttruetab, cetruetab, lb_child, lb_parent &
  1229. #if defined AGRIF_MPI
  1230. ,posvar, type_update, do_update, &
  1231. pttruetabwhole, cetruetabwhole &
  1232. #endif
  1233. )
  1234. !---------------------------------------------------------------------------------------------------
  1235. integer, intent(in) :: nbdim
  1236. integer, dimension(nbdim), intent(out) :: indmin, indmax
  1237. real, dimension(nbdim), intent(out) :: s_Parent_temp, s_Child_temp
  1238. real, dimension(nbdim), intent(in) :: s_child, ds_child
  1239. real, dimension(nbdim), intent(in) :: s_parent, ds_parent
  1240. integer, dimension(nbdim), intent(in) :: pttruetab, cetruetab
  1241. integer, dimension(nbdim), intent(in) :: lb_child, lb_parent
  1242. #if defined AGRIF_MPI
  1243. integer, dimension(nbdim), intent(in) :: posvar !< Position of the variable on the cell (1 or 2)
  1244. integer, dimension(nbdim), intent(in) :: type_update
  1245. logical, dimension(nbdim), intent(in) :: do_update
  1246. integer,dimension(nbdim), intent(out) :: pttruetabwhole, cetruetabwhole
  1247. #endif
  1248. !
  1249. real,dimension(nbdim) :: dim_newmin,dim_newmax
  1250. integer :: i
  1251. #if defined AGRIF_MPI
  1252. real :: positionmin, positionmax
  1253. integer :: imin, imax
  1254. integer :: coeffraf
  1255. #endif
  1256. !
  1257. do i = 1,nbdim
  1258. !
  1259. dim_newmin(i) = s_child(i) + (pttruetab(i) - lb_child(i)) * ds_child(i)
  1260. dim_newmax(i) = s_child(i) + (cetruetab(i) - lb_child(i)) * ds_child(i)
  1261. !
  1262. indmin(i) = lb_parent(i) + agrif_ceiling((dim_newmin(i)-s_parent(i))/ds_parent(i))
  1263. indmax(i) = lb_parent(i) + agrif_int( (dim_newmax(i)-s_parent(i))/ds_parent(i))
  1264. !
  1265. #if defined AGRIF_MPI
  1266. positionmin = s_parent(i) + (indmin(i)-lb_parent(i))*ds_parent(i)
  1267. IF ( do_update(i) ) THEN
  1268. IF (posvar(i) == 1) THEN
  1269. IF (type_update(i) == Agrif_Update_Average) THEN
  1270. positionmin = positionmin - ds_parent(i)/2.
  1271. ELSE IF (type_update(i) == Agrif_Update_Full_Weighting) THEN
  1272. positionmin = positionmin - (ds_parent(i)-ds_child(i))
  1273. ENDIF
  1274. ELSE
  1275. IF (type_update(i) /= Agrif_Update_Full_Weighting) THEN
  1276. positionmin = positionmin - ds_parent(i)/2.
  1277. ELSE
  1278. coeffraf = nint(ds_parent(i)/ds_child(i))
  1279. if (mod(coeffraf,2) == 1) then
  1280. positionmin = positionmin - (ds_parent(i)-ds_child(i))
  1281. else
  1282. positionmin = positionmin - (ds_parent(i)-ds_child(i))-ds_child(i)/2.
  1283. endif
  1284. ENDIF
  1285. ENDIF
  1286. ENDIF
  1287. !
  1288. imin = lb_child(i) + agrif_ceiling((positionmin-s_child(i))/ds_child(i))
  1289. positionmin = s_child(i) + (imin - lb_child(i)) * ds_child(i)
  1290. positionmax = s_parent(i) + (indmax(i)-lb_parent(i))*ds_parent(i)
  1291. pttruetabwhole(i) = imin
  1292. IF ( do_update(i) ) THEN
  1293. IF (posvar(i) == 1) THEN
  1294. IF (type_update(i) == Agrif_Update_Average) THEN
  1295. positionmax = positionmax + ds_parent(i)/2.
  1296. ELSE IF (type_update(i) == Agrif_Update_Full_Weighting) THEN
  1297. positionmax = positionmax + (ds_parent(i)-ds_child(i))
  1298. ENDIF
  1299. ELSE
  1300. IF (type_update(i) /= Agrif_Update_Full_Weighting) THEN
  1301. positionmax = positionmax + ds_parent(i)/2.
  1302. ELSE
  1303. coeffraf = nint(ds_parent(i)/ds_child(i))
  1304. if (mod(coeffraf,2) == 1) then
  1305. positionmax = positionmax + (ds_parent(i)-ds_child(i))
  1306. else
  1307. positionmax = positionmax + (ds_parent(i)-ds_child(i)) + ds_child(i)/2.
  1308. endif
  1309. ENDIF
  1310. ENDIF
  1311. ENDIF
  1312. imax = lb_child(i) +agrif_int((positionmax-s_child(i))/ds_child(i))
  1313. positionmax = s_child(i) + (imax - lb_child(i)) * ds_child(i)
  1314. cetruetabwhole(i) = imax
  1315. #endif
  1316. !
  1317. s_Parent_temp(i) = s_parent(i) + (indmin(i) - lb_parent(i)) * ds_parent(i)
  1318. s_Child_temp(i) = dim_newmin(i)
  1319. #if defined AGRIF_MPI
  1320. s_Child_temp(i) = positionmin
  1321. #endif
  1322. !
  1323. enddo
  1324. !---------------------------------------------------------------------------------------------------
  1325. end subroutine Agrif_Prtbounds
  1326. !===================================================================================================
  1327. !
  1328. !===================================================================================================
  1329. ! subroutine Agrif_Update_1D_Recursive
  1330. !
  1331. !> Updates a 1D grid variable on the parent grid
  1332. !---------------------------------------------------------------------------------------------------
  1333. subroutine Agrif_Update_1D_Recursive ( type_update, &
  1334. tempP, tempC, &
  1335. indmin, indmax, &
  1336. lb_child, ub_child, &
  1337. s_child, s_parent, &
  1338. ds_child, ds_parent )
  1339. !---------------------------------------------------------------------------------------------------
  1340. integer, intent(in) :: type_update !< Type of update (copy or average)
  1341. integer, intent(in) :: indmin, indmax
  1342. integer, intent(in) :: lb_child, ub_child
  1343. real, intent(in) :: s_child, s_parent
  1344. real, intent(in) :: ds_child, ds_parent
  1345. real, dimension(indmin:indmax), intent(out) :: tempP
  1346. real, dimension(lb_child:ub_child), intent(in) :: tempC
  1347. !---------------------------------------------------------------------------------------------------
  1348. call Agrif_UpdateBase(type_update, &
  1349. tempP(indmin:indmax), &
  1350. tempC(lb_child:ub_child), &
  1351. indmin, indmax, &
  1352. lb_child, ub_child, &
  1353. s_parent, s_child, &
  1354. ds_parent, ds_child)
  1355. !---------------------------------------------------------------------------------------------------
  1356. end subroutine Agrif_Update_1D_Recursive
  1357. !===================================================================================================
  1358. !
  1359. !===================================================================================================
  1360. ! subroutine Agrif_Update_2D_Recursive
  1361. !
  1362. !> updates a 2D grid variable on the parent grid.
  1363. !! Calls #Agrif_Update_1D_Recursive and #Agrif_UpdateBase
  1364. !---------------------------------------------------------------------------------------------------
  1365. subroutine Agrif_Update_2D_Recursive ( type_update, &
  1366. tempP, tempC, &
  1367. indmin, indmax, &
  1368. lb_child, ub_child, &
  1369. s_child, s_parent, &
  1370. ds_child, ds_parent )
  1371. !---------------------------------------------------------------------------------------------------
  1372. integer, dimension(2), intent(in) :: type_update !< Type of update (copy or average)
  1373. integer, dimension(2), intent(in) :: indmin, indmax
  1374. integer, dimension(2), intent(in) :: lb_child, ub_child
  1375. real, dimension(2), intent(in) :: s_child, s_parent
  1376. real, dimension(2), intent(in) :: ds_child, ds_parent
  1377. real, dimension( &
  1378. indmin(1):indmax(1), &
  1379. indmin(2):indmax(2)), intent(out) :: tempP
  1380. real, dimension(:,:), intent(in) :: tempC
  1381. !---------------------------------------------------------------------------------------------------
  1382. real, dimension(indmin(1):indmax(1), lb_child(2):ub_child(2)) :: tabtemp
  1383. real, dimension(indmin(2):indmax(2), indmin(1):indmax(1)) :: tempP_trsp
  1384. real, dimension(lb_child(2):ub_child(2), indmin(1):indmax(1)) :: tabtemp_trsp
  1385. integer :: i, j
  1386. integer :: coeffraf
  1387. !
  1388. tabtemp = 0.
  1389. coeffraf = nint ( ds_parent(1) / ds_child(1) )
  1390. !
  1391. IF((type_update(1) == Agrif_Update_Average) .AND. (coeffraf /= 1 )) THEN
  1392. !---CDIR NEXPAND
  1393. if ( .NOT. precomputedone(1) ) then
  1394. call Average1dPrecompute( ub_child(2)-lb_child(2)+1, &
  1395. indmax(1)-indmin(1)+1, &
  1396. ub_child(1)-lb_child(1)+1, &
  1397. s_parent(1),s_child(1),ds_parent(1),ds_child(1),1)
  1398. ! precomputedone(1) = .TRUE.
  1399. endif
  1400. !---CDIR NEXPAND
  1401. call Average1dAfterCompute( tabtemp, tempC, size(tabtemp), size(tempC), &
  1402. s_parent(1),s_child(1),ds_parent(1),ds_child(1),1)
  1403. !
  1404. ELSE IF ((type_update(1) == Agrif_Update_Copy) .AND. (coeffraf /= 1 ))THEN
  1405. !---CDIR NEXPAND
  1406. if ( .NOT. precomputedone(1) ) then
  1407. call Agrif_basicupdate_copy1d_before( ub_child(2)-lb_child(2)+1, &
  1408. indmax(1)-indmin(1)+1, &
  1409. ub_child(1)-lb_child(1)+1, &
  1410. s_parent(1),s_child(1),ds_parent(1),ds_child(1),1)
  1411. ! precomputedone(1) = .TRUE.
  1412. endif
  1413. !---CDIR NEXPAND
  1414. call Agrif_basicupdate_copy1d_after(tabtemp,tempC,size(tabtemp),size(tempC),1)
  1415. !
  1416. ELSE
  1417. do j = lb_child(2),ub_child(2)
  1418. !
  1419. !---CDIR NEXPAND
  1420. call Agrif_Update_1D_Recursive( type_update(1), &
  1421. tabtemp(:,j), &
  1422. tempC(:,j-lb_child(2)+1), &
  1423. indmin(1), indmax(1), &
  1424. lb_child(1),ub_child(1), &
  1425. s_child(1), s_parent(1), &
  1426. ds_child(1),ds_parent(1))
  1427. enddo
  1428. ENDIF
  1429. !
  1430. tabtemp_trsp = TRANSPOSE(tabtemp)
  1431. coeffraf = nint(ds_parent(2)/ds_child(2))
  1432. !
  1433. tempP_trsp = 0.
  1434. !
  1435. IF((type_update(2) == Agrif_Update_Average) .AND. (coeffraf /= 1 )) THEN
  1436. !---CDIR NEXPAND
  1437. if ( .NOT. precomputedone(2) ) then
  1438. call Average1dPrecompute( indmax(1)-indmin(1)+1, &
  1439. indmax(2)-indmin(2)+1, &
  1440. ub_child(2)-lb_child(2)+1,&
  1441. s_parent(2),s_child(2),ds_parent(2),ds_child(2),2)
  1442. ! precomputedone(2) = .TRUE.
  1443. endif
  1444. !---CDIR NEXPAND
  1445. call Average1dAfterCompute( tempP_trsp, tabtemp_trsp, size(tempP_trsp), size(tabtemp_trsp),&
  1446. s_parent(2),s_child(2),ds_parent(2),ds_child(2),2)
  1447. !
  1448. ELSE IF ((type_update(2) == Agrif_Update_Copy) .AND. (coeffraf /= 1 )) THEN
  1449. !---CDIR NEXPAND
  1450. if ( .NOT. precomputedone(2) ) then
  1451. call Agrif_basicupdate_copy1d_before( indmax(1)-indmin(1)+1, &
  1452. indmax(2)-indmin(2)+1, &
  1453. ub_child(2)-lb_child(2)+1, &
  1454. s_parent(2),s_child(2),ds_parent(2),ds_child(2),2)
  1455. ! precomputedone(2) = .TRUE.
  1456. endif
  1457. !---CDIR NEXPAND
  1458. call Agrif_basicupdate_copy1d_after( tempP_trsp, tabtemp_trsp, size(tempP_trsp), size(tabtemp_trsp),2)
  1459. !
  1460. ELSE
  1461. do i = indmin(1),indmax(1)
  1462. !
  1463. !---CDIR NEXPAND
  1464. call Agrif_UpdateBase(type_update(2), &
  1465. tempP_trsp(indmin(2):indmax(2),i), &
  1466. tabtemp_trsp(lb_child(2):ub_child(2),i),&
  1467. indmin(2),indmax(2), &
  1468. lb_child(2),ub_child(2), &
  1469. s_parent(2),s_child(2), &
  1470. ds_parent(2),ds_child(2))
  1471. !
  1472. enddo
  1473. ENDIF
  1474. !
  1475. tempP = TRANSPOSE(tempP_trsp)
  1476. !---------------------------------------------------------------------------------------------------
  1477. end subroutine Agrif_Update_2D_Recursive
  1478. !===================================================================================================
  1479. !
  1480. subroutine Agrif_Update_2D_Recursive_ok ( type_update, &
  1481. tempP, tempC, &
  1482. indmin, indmax, &
  1483. lb_child, ub_child, &
  1484. s_child, s_parent, ds_child, ds_parent )
  1485. !---------------------------------------------------------------------------------------------------
  1486. INTEGER, DIMENSION(2), intent(in) :: type_update !< Type of update (copy or average)
  1487. INTEGER, DIMENSION(2), intent(in) :: indmin, indmax
  1488. INTEGER, DIMENSION(2), intent(in) :: lb_child, ub_child
  1489. REAL, DIMENSION(2), intent(in) :: s_child, s_parent
  1490. REAL, DIMENSION(2), intent(in) :: ds_child, ds_parent
  1491. REAL, DIMENSION( &
  1492. indmin(1):indmax(1), &
  1493. indmin(2):indmax(2)), intent(out) :: tempP
  1494. REAL, DIMENSION( &
  1495. lb_child(1):ub_child(1), &
  1496. lb_child(2):ub_child(2)), intent(in) :: tempC
  1497. !
  1498. REAL, DIMENSION(indmin(1):indmax(1), lb_child(2):ub_child(2)) :: tabtemp
  1499. INTEGER :: i
  1500. !
  1501. do i = lb_child(2),ub_child(2)
  1502. call Agrif_Update_1D_Recursive(type_update(1), &
  1503. tabtemp(:, i), &
  1504. tempC(:,i), &
  1505. indmin(1),indmax(1), &
  1506. lb_child(1),ub_child(1), &
  1507. s_child(1), s_parent(1), &
  1508. ds_child(1),ds_parent(1))
  1509. enddo
  1510. !
  1511. tempP = 0.
  1512. !
  1513. do i = indmin(1),indmax(1)
  1514. call Agrif_UpdateBase(type_update(2), &
  1515. tempP(i,:), &
  1516. tabtemp(i,:), &
  1517. indmin(2),indmax(2), &
  1518. lb_child(2),ub_child(2), &
  1519. s_parent(2),s_child(2), &
  1520. ds_parent(2),ds_child(2))
  1521. enddo
  1522. !---------------------------------------------------------------------------------------------------
  1523. end subroutine Agrif_Update_2D_Recursive_ok
  1524. !===================================================================================================
  1525. !
  1526. !===================================================================================================
  1527. ! subroutine Agrif_Update_3D_Recursive
  1528. !
  1529. !> Updates a 3D grid variable on the parent grid.
  1530. !! Calls #Agrif_Update_2D_Recursive and #Agrif_UpdateBase.
  1531. !---------------------------------------------------------------------------------------------------
  1532. subroutine Agrif_Update_3D_Recursive ( type_update, &
  1533. tempP, tempC, &
  1534. indmin, indmax, &
  1535. lb_child, ub_child, &
  1536. s_child, s_parent, &
  1537. ds_child, ds_parent )
  1538. !---------------------------------------------------------------------------------------------------
  1539. integer, dimension(3), intent(in) :: type_update !< Type of update (copy or average)
  1540. integer, dimension(3), intent(in) :: indmin, indmax
  1541. integer, dimension(3), intent(in) :: lb_child, ub_child
  1542. real, dimension(3), intent(in) :: s_child, s_parent
  1543. real, dimension(3), intent(in) :: ds_child, ds_parent
  1544. real, dimension( &
  1545. indmin(1):indmax(1), &
  1546. indmin(2):indmax(2), &
  1547. indmin(3):indmax(3)), intent(out) :: tempP
  1548. real, dimension( &
  1549. lb_child(1):ub_child(1), &
  1550. lb_child(2):ub_child(2), &
  1551. lb_child(3):ub_child(3)), intent(in) :: tempC
  1552. !---------------------------------------------------------------------------------------------------
  1553. real, dimension( &
  1554. indmin(1):indmax(1), &
  1555. indmin(2):indmax(2), &
  1556. lb_child(3):ub_child(3)) :: tabtemp
  1557. integer :: i,j,k
  1558. integer :: coeffraf,locind_child_left
  1559. integer :: kuinf
  1560. !
  1561. coeffraf = nint ( ds_parent(1) / ds_child(1) )
  1562. !
  1563. if ((type_update(1) == Agrif_Update_Average) .AND. (coeffraf /= 1 )) then
  1564. !---CDIR NEXPAND
  1565. call Average1dPrecompute(ub_child(2)-lb_child(2)+1,&
  1566. indmax(1)-indmin(1)+1,&
  1567. ub_child(1)-lb_child(1)+1,&
  1568. s_parent(1),s_child(1),ds_parent(1),ds_child(1),1)
  1569. precomputedone(1) = .TRUE.
  1570. else if ((type_update(1) == Agrif_Update_Copy) .AND. (coeffraf /= 1 )) then
  1571. !---CDIR NEXPAND
  1572. call Agrif_basicupdate_copy1d_before(ub_child(2)-lb_child(2)+1, &
  1573. indmax(1)-indmin(1)+1, &
  1574. ub_child(1)-lb_child(1)+1, &
  1575. s_parent(1),s_child(1),ds_parent(1),ds_child(1),1)
  1576. precomputedone(1) = .TRUE.
  1577. endif
  1578. !
  1579. coeffraf = nint ( ds_parent(2) / ds_child(2) )
  1580. !
  1581. if ((type_update(2) == Agrif_Update_Average) .AND. (coeffraf /= 1 )) then
  1582. !---CDIR NEXPAND
  1583. call Average1dPrecompute(indmax(1)-indmin(1)+1,&
  1584. indmax(2)-indmin(2)+1,&
  1585. ub_child(2)-lb_child(2)+1,&
  1586. s_parent(2),s_child(2),ds_parent(2),ds_child(2),2)
  1587. precomputedone(2) = .TRUE.
  1588. else if ((type_update(2) == Agrif_Update_Copy) .AND. (coeffraf /= 1 )) then
  1589. !---CDIR NEXPAND
  1590. call Agrif_basicupdate_copy1d_before( indmax(1)-indmin(1)+1, &
  1591. indmax(2)-indmin(2)+1, &
  1592. ub_child(2)-lb_child(2)+1, &
  1593. s_parent(2),s_child(2),ds_parent(2),ds_child(2),2)
  1594. precomputedone(2) = .TRUE.
  1595. endif
  1596. !
  1597. do k = lb_child(3),ub_child(3)
  1598. call Agrif_Update_2D_Recursive( type_update(1:2),tabtemp(:,:,k),tempC(:,:,k), &
  1599. indmin(1:2),indmax(1:2), &
  1600. lb_child(1:2),ub_child(1:2), &
  1601. s_child(1:2),s_parent(1:2), &
  1602. ds_child(1:2),ds_parent(1:2) )
  1603. enddo
  1604. !
  1605. precomputedone(1) = .FALSE.
  1606. precomputedone(2) = .FALSE.
  1607. !
  1608. coeffraf = nint ( ds_parent(3) / ds_child(3) )
  1609. locind_child_left = 1 + agrif_int((s_parent(3)-s_child(3))/ds_child(3))
  1610. !
  1611. if (coeffraf == 1) then
  1612. kuinf = lb_child(3)+locind_child_left-2
  1613. do k=indmin(3),indmax(3)
  1614. kuinf = kuinf + 1
  1615. do j = indmin(2),indmax(2)
  1616. do i = indmin(1),indmax(1)
  1617. tempP(i,j,k) = tabtemp(i,j,kuinf)
  1618. enddo
  1619. enddo
  1620. enddo
  1621. else
  1622. tempP = 0.
  1623. do j = indmin(2),indmax(2)
  1624. do i = indmin(1),indmax(1)
  1625. call Agrif_UpdateBase(type_update(3),tempP(i,j,:),tabtemp(i,j,:), &
  1626. indmin(3),indmax(3), &
  1627. lb_child(3),ub_child(3), &
  1628. s_parent(3),s_child(3), &
  1629. ds_parent(3),ds_child(3))
  1630. !
  1631. enddo
  1632. enddo
  1633. endif
  1634. !---------------------------------------------------------------------------------------------------
  1635. end subroutine Agrif_Update_3D_Recursive
  1636. !===================================================================================================
  1637. !
  1638. !===================================================================================================
  1639. ! subroutine Agrif_Update_4D_Recursive
  1640. !
  1641. !> Updates a 4D grid variable on the parent grid.
  1642. !! Calls #Agrif_Update_3D_Recursive and #Agrif_UpdateBase.
  1643. !---------------------------------------------------------------------------------------------------
  1644. subroutine Agrif_Update_4D_Recursive ( type_update, &
  1645. tempP, tempC, &
  1646. indmin, indmax, &
  1647. lb_child, ub_child, &
  1648. s_child, s_parent, &
  1649. ds_child, ds_parent )
  1650. !---------------------------------------------------------------------------------------------------
  1651. integer, dimension(4), intent(in) :: type_update !< Type of update (copy or average)
  1652. integer, dimension(4), intent(in) :: indmin, indmax
  1653. integer, dimension(4), intent(in) :: lb_child, ub_child
  1654. real, dimension(4), intent(in) :: s_child, s_parent
  1655. real, dimension(4), intent(in) :: ds_child, ds_parent
  1656. real, dimension( &
  1657. indmin(1):indmax(1), &
  1658. indmin(2):indmax(2), &
  1659. indmin(3):indmax(3), &
  1660. indmin(4):indmax(4)), intent(out) :: tempP
  1661. real, dimension( &
  1662. lb_child(1):ub_child(1), &
  1663. lb_child(2):ub_child(2), &
  1664. lb_child(3):ub_child(3), &
  1665. lb_child(4):ub_child(4)), intent(in) :: tempC
  1666. !---------------------------------------------------------------------------------------------------
  1667. real, dimension(:,:,:,:), allocatable :: tabtemp
  1668. integer :: i,j,k,l
  1669. !
  1670. allocate(tabtemp(indmin(1):indmax(1), &
  1671. indmin(2):indmax(2), &
  1672. indmin(3):indmax(3), &
  1673. lb_child(4):ub_child(4)))
  1674. !
  1675. do l = lb_child(4), ub_child(4)
  1676. call Agrif_Update_3D_Recursive(type_update(1:3), &
  1677. tabtemp(indmin(1):indmax(1), &
  1678. indmin(2):indmax(2), &
  1679. indmin(3):indmax(3), l), &
  1680. tempC(lb_child(1):ub_child(1), &
  1681. lb_child(2):ub_child(2), &
  1682. lb_child(3):ub_child(3), l), &
  1683. indmin(1:3), indmax(1:3), &
  1684. lb_child(1:3), ub_child(1:3), &
  1685. s_child(1:3), s_parent(1:3), &
  1686. ds_child(1:3), ds_parent(1:3))
  1687. enddo
  1688. !
  1689. tempP = 0.
  1690. !
  1691. do k = indmin(3), indmax(3)
  1692. do j = indmin(2), indmax(2)
  1693. do i = indmin(1), indmax(1)
  1694. call Agrif_UpdateBase(type_update(4), &
  1695. tempP(i,j,k,indmin(4):indmax(4)), &
  1696. tabtemp(i,j,k,lb_child(4):ub_child(4)), &
  1697. indmin(4), indmax(4), &
  1698. lb_child(4), ub_child(4), &
  1699. s_parent(4), s_child(4), &
  1700. ds_parent(4),ds_child(4) )
  1701. enddo
  1702. enddo
  1703. enddo
  1704. !
  1705. deallocate(tabtemp)
  1706. !---------------------------------------------------------------------------------------------------
  1707. end subroutine Agrif_Update_4D_Recursive
  1708. !===================================================================================================
  1709. !
  1710. !===================================================================================================
  1711. ! subroutine Agrif_Update_5D_Recursive
  1712. !
  1713. !> Updates a 5D grid variable on the parent grid.
  1714. !! Calls #Agrif_Update_4D_Recursive and #Agrif_UpdateBase.
  1715. !---------------------------------------------------------------------------------------------------
  1716. subroutine Agrif_Update_5D_Recursive ( type_update, &
  1717. tempP, tempC, &
  1718. indmin, indmax, &
  1719. lb_child, ub_child, &
  1720. s_child, s_parent, &
  1721. ds_child, ds_parent )
  1722. !---------------------------------------------------------------------------------------------------
  1723. integer, dimension(5), intent(in) :: type_update !< Type of update (copy or average)
  1724. integer, dimension(5), intent(in) :: indmin, indmax
  1725. integer, dimension(5), intent(in) :: lb_child, ub_child
  1726. real, dimension(5), intent(in) :: s_child, s_parent
  1727. real, dimension(5), intent(in) :: ds_child, ds_parent
  1728. real, dimension( &
  1729. indmin(1):indmax(1), &
  1730. indmin(2):indmax(2), &
  1731. indmin(3):indmax(3), &
  1732. indmin(4):indmax(4), &
  1733. indmin(5):indmax(5)), intent(out) :: tempP
  1734. real, dimension( &
  1735. lb_child(1):ub_child(1), &
  1736. lb_child(2):ub_child(2), &
  1737. lb_child(3):ub_child(3), &
  1738. lb_child(4):ub_child(4), &
  1739. lb_child(5):ub_child(5)), intent(in) :: tempC
  1740. !---------------------------------------------------------------------------------------------------
  1741. real, dimension(:,:,:,:,:), allocatable :: tabtemp
  1742. integer :: i,j,k,l,m
  1743. !
  1744. allocate(tabtemp(indmin(1):indmax(1), &
  1745. indmin(2):indmax(2), &
  1746. indmin(3):indmax(3), &
  1747. indmin(4):indmax(4), &
  1748. lb_child(5):ub_child(5)))
  1749. !
  1750. do m = lb_child(5), ub_child(5)
  1751. call Agrif_Update_4D_Recursive(type_update(1:4), &
  1752. tabtemp(indmin(1):indmax(1), &
  1753. indmin(2):indmax(2), &
  1754. indmin(3):indmax(3), &
  1755. indmin(4):indmax(4), m), &
  1756. tempC(lb_child(1):ub_child(1), &
  1757. lb_child(2):ub_child(2), &
  1758. lb_child(3):ub_child(3), &
  1759. lb_child(4):ub_child(4), m), &
  1760. indmin(1:4),indmax(1:4), &
  1761. lb_child(1:4), ub_child(1:4), &
  1762. s_child(1:4), s_parent(1:4), &
  1763. ds_child(1:4), ds_parent(1:4))
  1764. enddo
  1765. !
  1766. tempP = 0.
  1767. !
  1768. do l = indmin(4), indmax(4)
  1769. do k = indmin(3), indmax(3)
  1770. do j = indmin(2), indmax(2)
  1771. do i = indmin(1), indmax(1)
  1772. call Agrif_UpdateBase( type_update(5), &
  1773. tempP(i,j,k,l,indmin(5):indmax(5)), &
  1774. tabtemp(i,j,k,l,lb_child(5):ub_child(5)), &
  1775. indmin(5), indmax(5), &
  1776. lb_child(5), ub_child(5), &
  1777. s_parent(5), s_child(5), &
  1778. ds_parent(5),ds_child(5) )
  1779. enddo
  1780. enddo
  1781. enddo
  1782. enddo
  1783. !
  1784. deallocate(tabtemp)
  1785. !---------------------------------------------------------------------------------------------------
  1786. end subroutine Agrif_Update_5D_Recursive
  1787. !===================================================================================================
  1788. !
  1789. !===================================================================================================
  1790. ! subroutine Agrif_Update_6D_Recursive
  1791. !
  1792. !> Updates a 6D grid variable on the parent grid.
  1793. !! Calls #Agrif_Update_5D_Recursive and #Agrif_UpdateBase.
  1794. !---------------------------------------------------------------------------------------------------
  1795. subroutine Agrif_Update_6D_Recursive ( type_update, &
  1796. tempP, tempC, &
  1797. indmin, indmax, &
  1798. lb_child, ub_child, &
  1799. s_child, s_parent, &
  1800. ds_child, ds_parent )
  1801. !---------------------------------------------------------------------------------------------------
  1802. integer, dimension(6), intent(in) :: type_update !< Type of update (copy or average)
  1803. integer, dimension(6), intent(in) :: indmin, indmax
  1804. integer, dimension(6), intent(in) :: lb_child, ub_child
  1805. real, dimension(6), intent(in) :: s_child, s_parent
  1806. real, dimension(6), intent(in) :: ds_child, ds_parent
  1807. real, dimension( &
  1808. indmin(1):indmax(1), &
  1809. indmin(2):indmax(2), &
  1810. indmin(3):indmax(3), &
  1811. indmin(4):indmax(4), &
  1812. indmin(5):indmax(5), &
  1813. indmin(6):indmax(6)), intent(out) :: tempP
  1814. real, dimension( &
  1815. lb_child(1):ub_child(1), &
  1816. lb_child(2):ub_child(2), &
  1817. lb_child(3):ub_child(3), &
  1818. lb_child(4):ub_child(4), &
  1819. lb_child(5):ub_child(5), &
  1820. lb_child(6):ub_child(6)), intent(in) :: tempC
  1821. !---------------------------------------------------------------------------------------------------
  1822. real, dimension(:,:,:,:,:,:), allocatable :: tabtemp
  1823. integer :: i,j,k,l,m,n
  1824. !
  1825. allocate(tabtemp(indmin(1):indmax(1), &
  1826. indmin(2):indmax(2), &
  1827. indmin(3):indmax(3), &
  1828. indmin(4):indmax(4), &
  1829. indmin(5):indmax(5), &
  1830. lb_child(6):ub_child(6)))
  1831. !
  1832. do n = lb_child(6),ub_child(6)
  1833. call Agrif_Update_5D_Recursive(type_update(1:5), &
  1834. tabtemp(indmin(1):indmax(1), &
  1835. indmin(2):indmax(2), &
  1836. indmin(3):indmax(3), &
  1837. indmin(4):indmax(4), &
  1838. indmin(5):indmax(5), n), &
  1839. tempC(lb_child(1):ub_child(1), &
  1840. lb_child(2):ub_child(2), &
  1841. lb_child(3):ub_child(3), &
  1842. lb_child(4):ub_child(4), &
  1843. lb_child(5):ub_child(5), n), &
  1844. indmin(1:5), indmax(1:5), &
  1845. lb_child(1:5),ub_child(1:5), &
  1846. s_child(1:5), s_parent(1:5), &
  1847. ds_child(1:5),ds_parent(1:5))
  1848. enddo
  1849. !
  1850. tempP = 0.
  1851. !
  1852. do m = indmin(5), indmax(5)
  1853. do l = indmin(4), indmax(4)
  1854. do k = indmin(3), indmax(3)
  1855. do j = indmin(2), indmax(2)
  1856. do i = indmin(1), indmax(1)
  1857. call Agrif_UpdateBase( type_update(6), &
  1858. tempP(i,j,k,l,m,indmin(6):indmax(6)), &
  1859. tabtemp(i,j,k,l,m,lb_child(6):ub_child(6)), &
  1860. indmin(6), indmax(6), &
  1861. lb_child(6), ub_child(6), &
  1862. s_parent(6), s_child(6), &
  1863. ds_parent(6), ds_child(6) )
  1864. enddo
  1865. enddo
  1866. enddo
  1867. enddo
  1868. enddo
  1869. !
  1870. deallocate(tabtemp)
  1871. !---------------------------------------------------------------------------------------------------
  1872. end subroutine Agrif_Update_6D_Recursive
  1873. !===================================================================================================
  1874. !
  1875. !===================================================================================================
  1876. ! subroutine Agrif_UpdateBase
  1877. !
  1878. !> Calls the updating method chosen by the user (copy, average or full-weighting).
  1879. !---------------------------------------------------------------------------------------------------
  1880. subroutine Agrif_UpdateBase ( type_update, &
  1881. parent_tab, child_tab, &
  1882. indmin, indmax, &
  1883. lb_child, ub_child, &
  1884. s_parent, s_child, &
  1885. ds_parent, ds_child )
  1886. !---------------------------------------------------------------------------------------------------
  1887. integer, intent(in) :: type_update
  1888. integer, intent(in) :: indmin, indmax
  1889. integer, intent(in) :: lb_child, ub_child
  1890. real, dimension(indmin:indmax), intent(out):: parent_tab
  1891. real, dimension(lb_child:ub_child), intent(in) :: child_tab
  1892. real, intent(in) :: s_parent, s_child
  1893. real, intent(in) :: ds_parent, ds_child
  1894. !---------------------------------------------------------------------------------------------------
  1895. integer :: np ! Length of parent array
  1896. integer :: nc ! Length of child array
  1897. !
  1898. np = indmax - indmin + 1
  1899. nc = ub_child - lb_child + 1
  1900. !
  1901. if ( type_update == Agrif_Update_Copy ) then
  1902. !
  1903. call Agrif_basicupdate_copy1d( &
  1904. parent_tab, child_tab, &
  1905. np, nc, &
  1906. s_parent, s_child, &
  1907. ds_parent, ds_child )
  1908. !
  1909. elseif ( type_update == Agrif_Update_Average ) then
  1910. !
  1911. call Agrif_basicupdate_average1d( &
  1912. parent_tab, child_tab, &
  1913. np, nc, &
  1914. s_parent, s_child, &
  1915. ds_parent, ds_child )
  1916. !
  1917. elseif ( type_update == Agrif_Update_Full_Weighting ) then
  1918. !
  1919. call Agrif_basicupdate_full_weighting1D( &
  1920. parent_tab, child_tab, &
  1921. np, nc, &
  1922. s_parent, s_child, &
  1923. ds_parent, ds_child )
  1924. !
  1925. endif
  1926. !---------------------------------------------------------------------------------------------------
  1927. end subroutine Agrif_UpdateBase
  1928. !===================================================================================================
  1929. !
  1930. #if defined AGRIF_MPI
  1931. !===================================================================================================
  1932. ! subroutine Agrif_Find_list_update
  1933. !---------------------------------------------------------------------------------------------------
  1934. subroutine Agrif_Find_list_update ( list_update, pttab, petab, lb_child, lb_parent, nbdim, &
  1935. find_list_update, tab4t, tab5t, memberinall, memberinall2, &
  1936. sendtoproc1, recvfromproc1, sendtoproc2, recvfromproc2 )
  1937. !---------------------------------------------------------------------------------------------------
  1938. TYPE(Agrif_List_Interp_Loc), pointer :: list_update
  1939. INTEGER, intent(in) :: nbdim
  1940. INTEGER, DIMENSION(nbdim), intent(in) :: pttab, petab
  1941. INTEGER, DIMENSION(nbdim), intent(in) :: lb_child, lb_parent
  1942. LOGICAL, intent(out) :: find_list_update
  1943. INTEGER, DIMENSION(nbdim,0:Agrif_Nbprocs-1,8), intent(out) :: tab4t
  1944. INTEGER, DIMENSION(nbdim,0:Agrif_Nbprocs-1,8), intent(out) :: tab5t
  1945. LOGICAL, DIMENSION(0:Agrif_Nbprocs-1), intent(out) :: memberinall,memberinall2
  1946. LOGICAL, DIMENSION(0:Agrif_Nbprocs-1), intent(out) :: sendtoproc1,recvfromproc1
  1947. LOGICAL, DIMENSION(0:Agrif_Nbprocs-1), intent(out) :: sendtoproc2,recvfromproc2
  1948. !
  1949. Type(Agrif_List_Interp_Loc), Pointer :: parcours
  1950. INTEGER :: i
  1951. !
  1952. find_list_update = .FALSE.
  1953. !
  1954. parcours => list_update
  1955. Find_loop : do while ( associated(parcours) )
  1956. do i = 1,nbdim
  1957. IF ((pttab(i) /= parcours%interp_loc%pttab(i)) .OR. &
  1958. (petab(i) /= parcours%interp_loc%petab(i)) .OR. &
  1959. (lb_child(i) /= parcours%interp_loc%pttab_child(i)) .OR. &
  1960. (lb_parent(i) /= parcours%interp_loc%pttab_parent(i))) THEN
  1961. parcours => parcours%suiv
  1962. cycle Find_loop
  1963. ENDIF
  1964. enddo
  1965. !
  1966. tab4t = parcours%interp_loc%tab4t(1:nbdim,0:Agrif_Nbprocs-1,1:8)
  1967. tab5t = parcours%interp_loc%tab5t(1:nbdim,0:Agrif_Nbprocs-1,1:8)
  1968. memberinall = parcours%interp_loc%memberinall(0:Agrif_Nbprocs-1)
  1969. memberinall2 = parcours%interp_loc%memberinall2(0:Agrif_Nbprocs-1)
  1970. sendtoproc1 = parcours%interp_loc%sendtoproc1(0:Agrif_Nbprocs-1)
  1971. sendtoproc2 = parcours%interp_loc%sendtoproc2(0:Agrif_Nbprocs-1)
  1972. recvfromproc1 = parcours%interp_loc%recvfromproc1(0:Agrif_Nbprocs-1)
  1973. recvfromproc2 = parcours%interp_loc%recvfromproc2(0:Agrif_Nbprocs-1)
  1974. !
  1975. find_list_update = .TRUE.
  1976. exit Find_loop
  1977. !
  1978. enddo Find_loop
  1979. !---------------------------------------------------------------------------------------------------
  1980. end subroutine Agrif_Find_list_update
  1981. !===================================================================================================
  1982. !
  1983. !===================================================================================================
  1984. ! subroutine Agrif_AddTo_list_update
  1985. !---------------------------------------------------------------------------------------------------
  1986. subroutine Agrif_AddTo_list_update ( list_update, pttab, petab, lb_child, lb_parent, &
  1987. nbdim, tab4t, tab5t, memberinall, memberinall2, &
  1988. sendtoproc1, recvfromproc1, sendtoproc2, recvfromproc2 )
  1989. !---------------------------------------------------------------------------------------------------
  1990. TYPE(Agrif_List_Interp_Loc), pointer :: list_update
  1991. INTEGER, intent(in) :: nbdim
  1992. INTEGER, DIMENSION(nbdim), intent(in) :: pttab, petab
  1993. INTEGER, DIMENSION(nbdim), intent(in) :: lb_child, lb_parent
  1994. INTEGER, DIMENSION(nbdim,0:Agrif_Nbprocs-1,8), intent(in) :: tab4t
  1995. INTEGER, DIMENSION(nbdim,0:Agrif_Nbprocs-1,8), intent(in) :: tab5t
  1996. LOGICAL, DIMENSION(0:Agrif_Nbprocs-1), intent(in) :: memberinall, memberinall2
  1997. LOGICAL, DIMENSION(0:Agrif_Nbprocs-1), intent(in) :: sendtoproc1, recvfromproc1
  1998. LOGICAL, DIMENSION(0:Agrif_Nbprocs-1), intent(in) :: sendtoproc2, recvfromproc2
  1999. !
  2000. Type(Agrif_List_Interp_Loc), pointer :: parcours
  2001. !
  2002. allocate(parcours)
  2003. allocate(parcours%interp_loc)
  2004. parcours%interp_loc%pttab(1:nbdim) = pttab(1:nbdim)
  2005. parcours%interp_loc%petab(1:nbdim) = petab(1:nbdim)
  2006. parcours%interp_loc%pttab_child(1:nbdim) = lb_child(1:nbdim)
  2007. parcours%interp_loc%pttab_parent(1:nbdim) = lb_parent(1:nbdim)
  2008. allocate(parcours%interp_loc%tab4t(nbdim,0:Agrif_Nbprocs-1,8))
  2009. allocate(parcours%interp_loc%tab5t(nbdim,0:Agrif_Nbprocs-1,8))
  2010. allocate(parcours%interp_loc%memberinall (0:Agrif_Nbprocs-1))
  2011. allocate(parcours%interp_loc%memberinall2(0:Agrif_Nbprocs-1))
  2012. allocate(parcours%interp_loc%recvfromproc1(0:Agrif_Nbprocs-1))
  2013. allocate(parcours%interp_loc%recvfromproc2(0:Agrif_Nbprocs-1))
  2014. allocate(parcours%interp_loc%sendtoproc1(0:Agrif_Nbprocs-1))
  2015. allocate(parcours%interp_loc%sendtoproc2(0:Agrif_Nbprocs-1))
  2016. parcours%interp_loc%tab4t = tab4t
  2017. parcours%interp_loc%tab5t = tab5t
  2018. parcours%interp_loc%memberinall = memberinall
  2019. parcours%interp_loc%memberinall2 = memberinall2
  2020. parcours%interp_loc%sendtoproc1 = sendtoproc1
  2021. parcours%interp_loc%sendtoproc2 = sendtoproc2
  2022. parcours%interp_loc%recvfromproc1 = recvfromproc1
  2023. parcours%interp_loc%recvfromproc2 = recvfromproc2
  2024. parcours%suiv => list_update
  2025. list_update => parcours
  2026. !---------------------------------------------------------------------------------------------------
  2027. end subroutine Agrif_Addto_list_update
  2028. !===================================================================================================
  2029. #endif
  2030. !
  2031. end module Agrif_Update