tm5_tendency_eval.F90 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. !#################################################################
  2. !
  3. ! tendency dimensions
  4. !
  5. !### macro's #####################################################
  6. !
  7. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  8. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  9. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  10. !
  11. #include "tm5.inc"
  12. !
  13. !#################################################################
  14. module TM5_Tendency_eval
  15. use GO, only : gol, goPr, goErr
  16. use tm5_tendency
  17. implicit none
  18. ! --- in/out --------------------------------
  19. #ifdef oasis4
  20. public :: prism_init_time
  21. #endif
  22. public :: set_init_tend,apply_tendency,reset_tendency
  23. contains
  24. #ifdef oasis4
  25. subroutine prism_init_time
  26. ! subroutine to get start/end timing from prism-coupler.
  27. use dims , only : idatei,idatee, idatet
  28. use PRISM , only : PRISM_Jobstart_date, PRISM_Jobend_date
  29. !
  30. ! set times provided by prism coupler:
  31. !
  32. idatei(1) = PRISM_Jobstart_date%year
  33. idatei(2) = PRISM_Jobstart_date%month
  34. idatei(3) = PRISM_Jobstart_date%day
  35. idatei(4) = PRISM_Jobstart_date%hour
  36. idatei(5) = PRISM_Jobstart_date%minute
  37. idatei(6) = nint(PRISM_Jobstart_date%second)
  38. !
  39. idatee(1) = PRISM_Jobend_date%year
  40. idatee(2) = PRISM_Jobend_date%month
  41. idatee(3) = PRISM_Jobend_date%day
  42. idatee(4) = PRISM_Jobend_date%hour
  43. idatee(5) = PRISM_Jobend_date%minute
  44. idatee(6) = nint(PRISM_Jobend_date%second)
  45. ! copy
  46. idatet = idatee
  47. end subroutine prism_init_time
  48. #endif
  49. subroutine set_init_tend (rcfile,status)
  50. use GO , only : gol, goPr, goErr, goLabel
  51. use GO , only : TrcFile, Init, Done, ReadRc
  52. use GO , only : TDate, NewDate, IncrDate, AnyDate
  53. use dims , only : idate
  54. use tracer_data , only : PLC_Set, PLC_Reset
  55. use tracer_data , only : plc_reset_period
  56. #ifdef with_feedback
  57. use tm5_feedback , only : fdb_ntr, fdb_trname, fdb_replace
  58. use tm5_feedback , only : fdb_firstonly
  59. #endif
  60. #ifdef oasis4
  61. use prism_putget , only : TM5_Prism_Puts
  62. #endif
  63. ! --- in/out ----------------------------------------
  64. character(len=*), intent(in) :: rcfile
  65. integer, intent(out) :: status
  66. ! --- const ----------------------------------------
  67. character(len=*), parameter :: rname = mname//'/set_tend'
  68. ! --- local ---------------------------------------------
  69. integer :: itr, ipr
  70. #ifdef with_feedback
  71. integer :: fdb_itr
  72. #endif
  73. type(TrcFile) :: rcF
  74. type(TDate) :: tdyn
  75. ! --- begin -----------------------------------------------
  76. write (gol,'(a,": read tendency settings ...")') rname; call goPr
  77. ! open rcfile:
  78. call Init( rcF, rcfile, status )
  79. IF_NOTOK_RETURN(status=1)
  80. ! which tendencies form pchem ?
  81. call ReadRc( rcF, 'tend.pchem.emis' , tend_pchem_emis , status )
  82. IF_NOTOK_RETURN(status=1)
  83. call ReadRc( rcF, 'tend.pchem.drydepos', tend_pchem_drydepos, status )
  84. IF_NOTOK_RETURN(status=1)
  85. call ReadRc( rcF, 'tend.pchem.convdiff', tend_pchem_convdiff, status )
  86. IF_NOTOK_RETURN(status=1)
  87. ! which tendencies form lchem ?
  88. call ReadRc( rcF, 'tend.lchem.convdiff', tend_lchem_convdiff, status )
  89. IF_NOTOK_RETURN(status=1)
  90. call ReadRc( rcF, 'tend.lchem.chem' , tend_lchem_chem , status )
  91. IF_NOTOK_RETURN(status=1)
  92. call ReadRc( rcF, 'tend.lchem.emis' , tend_lchem_emis , status )
  93. IF_NOTOK_RETURN(status=1)
  94. call ReadRc( rcF, 'tend.lchem.drydepos', tend_lchem_drydepos, status )
  95. IF_NOTOK_RETURN(status=1)
  96. call ReadRc( rcF, 'tend.lchem.wetdepos', tend_lchem_wetdepos, status )
  97. IF_NOTOK_RETURN(status=1)
  98. #ifdef with_feedback
  99. ! apply feedbacks for certain tracers ?
  100. do fdb_itr = 1, fdb_ntr
  101. call ReadRc( rcF, 'feedback.replace.'//trim(fdb_trname(fdb_itr)), fdb_replace(fdb_it
  102. r), status )
  103. IF_NOTOK_RETURN(status=1)
  104. end do
  105. ! adhoc: only at start time field seem to be send:
  106. call ReadRc( rcF, 'feedback.firstonly', fdb_firstonly, status )
  107. IF_NOTOK_RETURN(status=1)
  108. #endif
  109. call Done( rcF, status )
  110. IF_NOTOK_RETURN(status=1)
  111. write (gol,'(a,": initialize tendency data ...")') rname; call goPr
  112. ! Do not fill current tracer fields from rm_k / rm_t: They are not present yet.
  113. ! Use the previously stored values instead.
  114. ! do itr = 1, plc_ntr
  115. ! call PLC_Set( 'fill-tracer', itr, plc_ipr_conc, status )
  116. ! IF_NOTOK_RETURN(status=1)
  117. ! end do
  118. ! reset pchem and lchem only:
  119. do itr = 1, plc_ntr
  120. ipr = plc_ipr_pchem
  121. call PLC_Reset( itr, ipr, status )
  122. IF_NOTOK_RETURN(status=1)
  123. ipr = plc_ipr_lchem
  124. call PLC_Reset( itr, ipr, status )
  125. IF_NOTOK_RETURN(status=1)
  126. end do
  127. ! add tendencies:
  128. do itr = 1, plc_ntr
  129. ! ~~ collected into pchem
  130. if ( tend_pchem_emis ) then
  131. call PLC_Set( 'add-low', itr, plc_ipr_pchem, status, ipr2=plc_ipr_pemi )
  132. IF_NOTOK_RETURN(status=1)
  133. end if
  134. if ( tend_pchem_drydepos ) then
  135. call PLC_Set( 'add', itr, plc_ipr_pchem, status, ipr2=plc_ipr_lddep, fac=-1.0 )
  136. IF_NOTOK_RETURN(status=1)
  137. end if
  138. if ( tend_pchem_convdiff ) then
  139. call PLC_Set( 'add', itr, plc_ipr_pchem, status, ipr2=plc_ipr_tcnvd )
  140. IF_NOTOK_RETURN(status=1)
  141. end if
  142. ! ~~ collected into lchem
  143. ! conventions: lchem negative means 'loss',
  144. ! thus emissions have a positive contribution to lchem ...
  145. if ( tend_lchem_convdiff ) then
  146. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_tcnvd )
  147. IF_NOTOK_RETURN(status=1)
  148. end if
  149. if ( tend_lchem_chem ) then
  150. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_tchem )
  151. IF_NOTOK_RETURN(status=1)
  152. end if
  153. if ( tend_lchem_emis ) then
  154. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_pemi )
  155. IF_NOTOK_RETURN(status=1)
  156. end if
  157. if ( tend_lchem_drydepos ) then
  158. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_lddep, fac=-1.0 )
  159. IF_NOTOK_RETURN(status=1)
  160. end if
  161. if ( tend_lchem_wetdepos ) then
  162. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_lwdep, fac=-1.0 )
  163. IF_NOTOK_RETURN(status=1)
  164. end if
  165. end do
  166. #ifdef oasis4
  167. write (gol,'(a,": send chemical tendency data ...")') rname; call goPr
  168. ! put tendencies to IFS:
  169. ! current time (begin of dynamics step)
  170. tdyn = NewDate( time6=idate )
  171. call TM5_Prism_Puts( tdyn , status, isfirst=.true. )
  172. IF_NOTOK_RETURN(status=1)
  173. #endif
  174. end subroutine set_init_tend
  175. subroutine apply_tendency (isfirst, tdyn, status )
  176. use GO, only : gol, goPr, goErr
  177. use GO , only : TDate
  178. use tracer_data , only : PLC_Set
  179. #ifdef oasis4
  180. use prism_putget , only : TM5_Prism_Puts, TM5_Prism_gets
  181. #endif
  182. ! --- in/out ----------------------------------
  183. type(TDate),intent(in) :: tdyn
  184. logical, intent(in) :: isfirst
  185. integer, intent(out) :: status
  186. ! --- const ------------------------------
  187. character(len=*), parameter :: rname = mname//'/apply_tendency'
  188. ! --- local ----------------------------------
  189. integer :: itr, ipr
  190. ! --- begin -----------------------------------
  191. ! no modifications of tendencies if this is initial time,
  192. ! since fields are either zero or read from restart file:
  193. if ( .not. isfirst ) then
  194. ! add budgets collected parallel over tracers:
  195. do itr = 1, plc_ntr
  196. call PLC_Set( 'add-t', itr, plc_ipr_tcnvd, status ) ! convection/diffusion
  197. IF_NOTOK_RETURN(status=1)
  198. call PLC_Set( 'add-t', itr, plc_ipr_lwdep, status ) ! wet deposition
  199. IF_NOTOK_RETURN(status=1)
  200. call PLC_Set( 'add-t', itr, plc_ipr_pemi , status ) ! emissions (not nox)
  201. IF_NOTOK_RETURN(status=1)
  202. end do
  203. ! dry depos is applied in chemistry, thus substract loss from chemical production
  204. ! (note that loss is positive, thus adding loss to change is the same as removing it):
  205. do itr = 1, plc_ntr
  206. call PLC_Set( 'add', itr, plc_ipr_tchem, status, ipr2=plc_ipr_lddep )
  207. IF_NOTOK_RETURN(status=1)
  208. end do
  209. ! nox emis is applied in chemistry, thus substract nox emis from chemical tendency:
  210. call PLC_Set( 'add', plc_itr_nox, plc_ipr_tchem, status, ipr2=plc_ipr_pemi, fac=-1.0 )
  211. IF_NOTOK_RETURN(status=1)
  212. ! fill current tracer fields:
  213. do itr = 1, plc_ntr
  214. call PLC_Set( 'fill-tracer', itr, plc_ipr_conc, status )
  215. IF_NOTOK_RETURN(status=1)
  216. end do
  217. ! add tendencies:
  218. do itr = 1, plc_ntr
  219. ! ~~ collected into pchem
  220. if ( tend_pchem_emis ) then
  221. call PLC_Set( 'add-low', itr, plc_ipr_pchem, status, ipr2=plc_ipr_pemi )
  222. IF_NOTOK_RETURN(status=1)
  223. end if
  224. if ( tend_pchem_drydepos ) then
  225. call PLC_Set( 'add', itr, plc_ipr_pchem, status, ipr2=plc_ipr_lddep, fac=-1.0 )
  226. IF_NOTOK_RETURN(status=1)
  227. end if
  228. if ( tend_pchem_convdiff ) then
  229. call PLC_Set( 'add', itr, plc_ipr_pchem, status, ipr2=plc_ipr_tcnvd)
  230. IF_NOTOK_RETURN(status=1)
  231. end if
  232. ! ~~ collected into lchem
  233. ! conventions: lchem negative means 'loss',
  234. ! thus emissions have a positive contribution to lchem ...
  235. if ( tend_lchem_convdiff ) then
  236. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_tcnvd )
  237. IF_NOTOK_RETURN(status=1)
  238. end if
  239. if ( tend_lchem_chem ) then
  240. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_tchem )
  241. IF_NOTOK_RETURN(status=1)
  242. end if
  243. if ( tend_lchem_emis ) then
  244. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_pemi )
  245. IF_NOTOK_RETURN(status=1)
  246. end if
  247. if ( tend_lchem_drydepos ) then
  248. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_lddep, fac=-1.0 )
  249. IF_NOTOK_RETURN(status=1)
  250. end if
  251. if ( tend_lchem_wetdepos ) then
  252. call PLC_Set( 'add', itr, plc_ipr_lchem, status, ipr2=plc_ipr_lwdep, fac=-1.0 )
  253. IF_NOTOK_RETURN(status=1)
  254. end if
  255. end do
  256. end if ! not first
  257. #ifdef oasis4
  258. ! put tendencies to IFS:
  259. if ( .not. isfirst ) then ! First submission is already performed in initexit.F90, before meteo-gets.
  260. call TM5_Prism_Puts( tdyn, status )
  261. IF_NOTOK_RETURN(status=1)
  262. endif
  263. ! get concentrations, eventuall feedback:
  264. call TM5_Prism_Gets( tdyn, isfirst, status )
  265. IF_NOTOK_RETURN(status=1)
  266. #endif
  267. end subroutine apply_tendency
  268. subroutine reset_tendency ( status )
  269. use GO , only : gol, goPr, goErr, goLabel
  270. use tracer_data , only : PLC_Reset
  271. ! --- in/out ----------------------------------
  272. integer, intent(out) :: status
  273. ! --- const ------------------------------
  274. character(len=*), parameter :: rname = mname//'/reset_tendency'
  275. ! --- local ----------------------------------
  276. integer :: itr, ipr
  277. ! --- begin -----------------------------------
  278. ! loops over plc tracers and processes:
  279. do itr = 1, plc_ntr
  280. do ipr = 1, plc_npr
  281. ! not for for concentrations
  282. if ( ipr == plc_ipr_conc ) cycle
  283. ! reset tendencies to zero:
  284. call PLC_Reset( itr, ipr, status )
  285. IF_NOTOK_RETURN(status=1)
  286. end do ! ipr
  287. end do ! itr
  288. end subroutine reset_tendency
  289. end module TM5_Tendency_eval