forked from wrf-model/WRF
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodule_intermediate_nmm.F
249 lines (220 loc) · 10.4 KB
/
module_intermediate_nmm.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
! MODULE module_intermediate_nmm
! This module contains routines that feed parent grid variables to the
! intermediate grid when doing up-interpolation. This is needed by
! the new NMM interpolation routines, which require certain variables
! on the target domain in order to do log(P)-space vertical
! interpolation.
!
! This module is also used during forcing (parent->nest boundary) to
! copy variables to the intermediate domain that may not otherwise be
! copied by the forcing routines.
!
! Author: Samuel Trahan
!
! History:
! Aug 2012 - written by Sam Trahan for up-interpolation
! Sep 2012 - updated to also work with forcing (parent->nest bdy)
module module_intermediate_nmm
#if (NMM_CORE == 1 && NMM_NEST==1)
contains
SUBROUTINE parent_to_inter_part1 ( grid, intermediate_grid, ngrid, config_flags )
USE module_state_description
USE module_domain, ONLY : domain, get_ijk_from_grid
USE module_configure, ONLY : grid_config_rec_type
USE module_dm, ONLY : ntasks, ntasks_x, ntasks_y, itrace, local_communicator, mytask, &
ipe_save, jpe_save, ips_save, jps_save, get_dm_max_halo_width, &
nest_pes_x, nest_pes_y, &
intercomm_active, nest_task_offsets, &
mpi_comm_to_mom, mpi_comm_to_kid, which_kid!, &
!push_communicators_for_domain,pop_communicators_for_domain
USE module_timing
IMPLICIT NONE
TYPE(domain), POINTER :: grid
TYPE(domain), POINTER :: intermediate_grid
TYPE(domain), POINTER :: ngrid
INTEGER nlev, msize
INTEGER i,j,pig,pjg,cm,cn,nig,njg,retval,k,ioffset,ierr
INTEGER iparstrt,jparstrt,sw
TYPE (grid_config_rec_type) :: config_flags
REAL xv(500)
INTEGER :: cids, cide, cjds, cjde, ckds, ckde, &
cims, cime, cjms, cjme, ckms, ckme, &
cips, cipe, cjps, cjpe, ckps, ckpe
INTEGER :: iids, iide, ijds, ijde, ikds, ikde, &
iims, iime, ijms, ijme, ikms, ikme, &
iips, iipe, ijps, ijpe, ikps, ikpe
INTEGER :: nids, nide, njds, njde, nkds, nkde, &
nims, nime, njms, njme, nkms, nkme, &
nips, nipe, njps, njpe, nkps, nkpe
INTEGER idim1,idim2,idim3,idim4,idim5,idim6,idim7
INTEGER icoord, jcoord, idim_cd, jdim_cd, pgr
INTEGER local_comm, myproc, nproc
INTEGER thisdomain_max_halo_width
! CALL wrf_get_dm_communicator ( local_comm )
CALL wrf_get_myproc( myproc )
CALL wrf_get_nproc( nproc )
CALL get_ijk_from_grid ( grid , &
cids, cide, cjds, cjde, ckds, ckde, &
cims, cime, cjms, cjme, ckms, ckme, &
cips, cipe, cjps, cjpe, ckps, ckpe )
CALL get_ijk_from_grid ( intermediate_grid , &
iids, iide, ijds, ijde, ikds, ikde, &
iims, iime, ijms, ijme, ikms, ikme, &
iips, iipe, ijps, ijpe, ikps, ikpe )
CALL get_ijk_from_grid ( ngrid , &
nids, nide, njds, njde, nkds, nkde, &
nims, nime, njms, njme, nkms, nkme, &
nips, nipe, njps, njpe, nkps, nkpe )
CALL nl_get_parent_grid_ratio ( ngrid%id, pgr )
CALL nl_get_i_parent_start ( intermediate_grid%id, iparstrt )
CALL nl_get_j_parent_start ( intermediate_grid%id, jparstrt )
CALL nl_get_shw ( intermediate_grid%id, sw )
icoord = iparstrt - sw
jcoord = jparstrt - sw
idim_cd = iide - iids + 1
jdim_cd = ijde - ijds + 1
nlev = ckde - ckds + 1
CALL get_dm_max_halo_width ( ngrid%id , thisdomain_max_halo_width )
CALL wrf_dm_nestexchange_init
IF ( grid%active_this_task ) THEN
msize = 5
CALL rsl_lite_to_child_info( msize*4 &
,cips,cipe,cjps,cjpe &
,iids,iide,ijds,ijde &
,nids,nide,njds,njde &
,pgr , sw &
,nest_task_offsets(ngrid%id) &
,nest_pes_x(grid%id) &
,nest_pes_y(grid%id) &
,nest_pes_x(intermediate_grid%id) &
,nest_pes_y(intermediate_grid%id) &
,thisdomain_max_halo_width &
,icoord,jcoord &
,idim_cd,jdim_cd &
,pig,pjg,retval )
DO while ( retval .eq. 1 )
IF ( SIZE(grid%hres_fis) .GT. 1 ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c
xv(1)=grid%hres_fis(pig,pjg)
CALL rsl_lite_to_child_msg(4,xv)
ENDIF
IF ( SIZE(grid%sm) .GT. 1 ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c
xv(1)=grid%sm(pig,pjg)
CALL rsl_lite_to_child_msg(4,xv)
ENDIF
IF ( SIZE(grid%pd) .GT. 1 ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c
xv(1)=grid%pd(pig,pjg)
CALL rsl_lite_to_child_msg(4,xv)
ENDIF
IF ( SIZE(grid%fis) .GT. 1 ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c
xv(1)=grid%fis(pig,pjg)
CALL rsl_lite_to_child_msg(4,xv)
ENDIF
CALL rsl_lite_to_child_info( msize*4 &
,cips,cipe,cjps,cjpe &
,iids,iide,ijds,ijde &
,nids,nide,njds,njde &
,pgr , sw &
,nest_task_offsets(ngrid%id) &
,nest_pes_x(grid%id) &
,nest_pes_y(grid%id) &
,nest_pes_x(intermediate_grid%id) &
,nest_pes_y(intermediate_grid%id) &
,thisdomain_max_halo_width &
,icoord,jcoord &
,idim_cd,jdim_cd &
,pig,pjg,retval )
ENDDO
ENDIF ! grid%active_this_task
IF ( intercomm_active( grid%id ) ) THEN ! I am parent
local_comm = mpi_comm_to_kid( which_kid(ngrid%id), grid%id )
ioffset = nest_task_offsets(ngrid%id)
ELSE IF ( intercomm_active( ngrid%id ) ) THEN ! I am nest
local_comm = mpi_comm_to_mom( ngrid%id )
ioffset = nest_task_offsets(ngrid%id)
ENDIF
IF ( grid%active_this_task .OR. ngrid%active_this_task ) THEN
#if defined(DM_PARALLEL) && !defined(STUBMPI)
CALL mpi_comm_rank(local_comm,myproc,ierr)
CALL mpi_comm_size(local_comm,nproc,ierr)
#endif
CALL rsl_lite_bcast_msgs( myproc, nest_pes_x(grid%id)*nest_pes_y(grid%id), &
nest_pes_x(ngrid%id)*nest_pes_y(ngrid%id), &
ioffset, local_comm )
ENDIF
RETURN
END SUBROUTINE parent_to_inter_part1
SUBROUTINE parent_to_inter_part2 ( grid, ngrid, config_flags )
USE module_state_description
USE module_domain, ONLY : domain, get_ijk_from_grid
USE module_configure, ONLY : grid_config_rec_type
USE module_dm, ONLY : ntasks, ntasks_x, ntasks_y, itrace, local_communicator, mytask, &
ipe_save, jpe_save, ips_save, jps_save, get_dm_max_halo_width!, &
!push_communicators_for_domain,pop_communicators_for_domain
USE module_comm_dm, ONLY : HALO_NMM_INT_UP_sub
IMPLICIT NONE
TYPE(domain), POINTER :: grid
TYPE(domain), POINTER :: cgrid
TYPE(domain), POINTER :: ngrid
INTEGER nlev, msize
INTEGER i,j,pig,pjg,cm,cn,nig,njg,retval,k
TYPE (grid_config_rec_type) :: config_flags
REAL xv(500)
INTEGER :: cids, cide, cjds, cjde, ckds, ckde, &
cims, cime, cjms, cjme, ckms, ckme, &
cips, cipe, cjps, cjpe, ckps, ckpe
INTEGER :: nids, nide, njds, njde, nkds, nkde, &
nims, nime, njms, njme, nkms, nkme, &
nips, nipe, njps, njpe, nkps, nkpe
INTEGER :: ids, ide, jds, jde, kds, kde, &
ims, ime, jms, jme, kms, kme, &
ips, ipe, jps, jpe, kps, kpe
INTEGER idim1,idim2,idim3,idim4,idim5,idim6,idim7
REAL dummy_xs, dummy_xe, dummy_ys, dummy_ye
integer myproc
CALL get_ijk_from_grid ( grid , &
cids, cide, cjds, cjde, ckds, ckde, &
cims, cime, cjms, cjme, ckms, ckme, &
cips, cipe, cjps, cjpe, ckps, ckpe )
IF ( ngrid%active_this_task ) THEN
nlev = ckde - ckds + 1
!write(0,*) 'IN parent_to_inter_part2'
CALL rsl_lite_from_parent_info(pig,pjg,retval)
DO while ( retval .eq. 1 )
!write(0,*) 'top of loop'
IF ( SIZE(grid%hres_fis) .GT. 1 ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c
CALL rsl_lite_from_parent_msg(4,xv)
grid%hres_fis(pig,pjg) = xv(1)
ENDIF
!write(0,*)'do sm'
IF ( SIZE(grid%sm) .GT. 1 ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c
CALL rsl_lite_from_parent_msg(4,xv)
grid%sm(pig,pjg) = xv(1)
ENDIF
!write(0,*)'do pd'
IF ( SIZE(grid%pd) .GT. 1 ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c
CALL rsl_lite_from_parent_msg(4,xv)
grid%pd(pig,pjg) = xv(1)
ENDIF
!write(0,*)'do fis'
IF ( SIZE(grid%fis) .GT. 1 ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c
CALL rsl_lite_from_parent_msg(4,xv)
grid%fis(pig,pjg) = xv(1)
ENDIF
!write(0,*) 'call rsl_lite_from_parent_info'
CALL rsl_lite_from_parent_info(pig,pjg,retval)
!write(0,*) 'back with retval=',retval
ENDDO
!write(0,*) 'out of loop'
CALL get_ijk_from_grid ( grid , &
ids, ide, jds, jde, kds, kde, &
ims, ime, jms, jme, kms, kme, &
ips, ipe, jps, jpe, kps, kpe )
CALL push_communicators_for_domain( grid%id )
#include "HALO_NMM_INT_UP.inc"
CALL pop_communicators_for_domain
ENDIF
CALL wrf_dm_nestexchange_init
RETURN
END SUBROUTINE parent_to_inter_part2
#endif
end module module_intermediate_nmm