22 #include <fms_platform.h> 36 use fv_mp_nlm_mod,
only: mp_reduce_sum, mp_reduce_min, mp_reduce_max
43 #ifdef NO_QUAD_PRECISION 45 integer,
parameter::
f_p = selected_real_kind(15)
48 integer,
parameter::
f_p = selected_real_kind(20)
53 real(kind=R_GRID) ::
radius=cnst_radius
85 TYPE(FV_ATMOS_TYPE),
INTENT(INOUT),
TARGET :: atm
86 LOGICAL,
INTENT(IN) :: non_ortho
87 INTEGER,
INTENT(IN) :: npx, npy, npz
88 INTEGER,
INTENT(IN) :: grid_type, c2l_order
95 REAL(kind=r_grid),
INTENT(IN) :: q1(2), q2(2)
96 REAL(kind=r_grid),
INTENT(IN),
OPTIONAL ::
radius 97 REAL(f_p) :: p1(2), p2(2)
114 arg1 = (p1(2)-p2(2))/2.
115 arg2 = (p1(1)-p2(1))/2.
116 arg3 = sin(arg1)**2 + cos(p1(2))*cos(p2(2))*sin(arg2)**2
118 result2 = asin(result1)
128 & mode, grid_type, domain, nested, c2l_ord, bd)
131 INTEGER,
INTENT(IN) :: km, npx, npy,
grid_type, c2l_ord
133 INTEGER,
INTENT(IN) :: mode
135 REAL,
INTENT(INOUT) :: u(bd%isd:bd%ied, bd%jsd:bd%jed+1, km)
136 REAL,
INTENT(INOUT) :: v(bd%isd:bd%ied+1, bd%jsd:bd%jed, km)
137 REAL,
INTENT(OUT) :: ua(bd%isd:bd%ied, bd%jsd:bd%jed, km)
138 REAL,
INTENT(OUT) :: va(bd%isd:bd%ied, bd%jsd:bd%jed, km)
139 TYPE(
domain2d),
INTENT(INOUT) :: domain
140 LOGICAL,
INTENT(IN) :: nested
141 IF (c2l_ord .EQ. 2)
THEN 146 & domain, nested, mode, bd)
149 SUBROUTINE c2l_ord4(u, v, ua, va, gridstruct, npx, npy, km, grid_type&
150 & , domain, nested, mode, bd)
152 TYPE(FV_GRID_BOUNDS_TYPE),
INTENT(IN) :: bd
153 INTEGER,
INTENT(IN) :: km, npx, npy, grid_type
155 INTEGER,
INTENT(IN) :: mode
156 TYPE(FV_GRID_TYPE),
INTENT(IN),
TARGET :: gridstruct
157 REAL,
INTENT(INOUT) :: u(bd%isd:bd%ied, bd%jsd:bd%jed+1, km)
158 REAL,
INTENT(INOUT) :: v(bd%isd:bd%ied+1, bd%jsd:bd%jed, km)
159 REAL,
INTENT(OUT) :: ua(bd%isd:bd%ied, bd%jsd:bd%jed, km)
160 REAL,
INTENT(OUT) :: va(bd%isd:bd%ied, bd%jsd:bd%jed, km)
161 TYPE(DOMAIN2D),
INTENT(INOUT) :: domain
162 LOGICAL,
INTENT(IN) :: nested
165 REAL,
SAVE :: a1=0.5625
166 REAL,
SAVE :: a2=-0.0625
167 REAL,
SAVE :: c1=1.125
168 REAL,
SAVE :: c2=-0.125
169 REAL :: utmp(bd%is:bd%ie, bd%js:bd%je+1)
170 REAL :: vtmp(bd%is:bd%ie+1, bd%js:bd%je)
171 REAL :: wu(bd%is:bd%ie, bd%js:bd%je+1)
172 REAL :: wv(bd%is:bd%ie+1, bd%js:bd%je)
174 INTEGER :: is, ie, js, je
189 IF (mode .GT. 0)
THEN 206 IF (npy - 1 .GT. je)
THEN 217 IF (npx - 1 .GT. ie)
THEN 223 utmp(i, j) = c2*(u(i, j-1, k)+u(i, j+2, k)) + c1*(u(i, j, &
225 vtmp(i, j) = c2*(v(i-1, j, k)+v(i+2, j, k)) + c1*(v(i, j, &
235 IF (npy - 2 .GT. je)
THEN 246 IF (npx - 2 .GT. ie)
THEN 252 utmp(i, j) = c2*(u(i, j-1, k)+u(i, j+2, k)) + c1*(u(i, j, &
254 vtmp(i, j) = c2*(v(i-1, j, k)+v(i+2, j, k)) + c1*(v(i, j, &
260 wv(i, 1) = v(i, 1, k)*gridstruct%dy(i, 1)
263 vtmp(i, 1) = 2.*(wv(i, 1)+wv(i+1, 1))/(gridstruct%dy(i, 1)&
264 & +gridstruct%dy(i+1, 1))
265 utmp(i, 1) = 2.*(u(i, 1, k)*gridstruct%dx(i, 1)+u(i, 2, k)&
266 & *gridstruct%dx(i, 2))/(gridstruct%dx(i, 1)+gridstruct%dx&
272 IF (je + 1 .EQ. npy)
THEN 275 wv(i, j) = v(i, j, k)*gridstruct%dy(i, j)
278 vtmp(i, j) = 2.*(wv(i, j)+wv(i+1, j))/(gridstruct%dy(i, j)&
279 & +gridstruct%dy(i+1, j))
280 utmp(i, j) = 2.*(u(i, j, k)*gridstruct%dx(i, j)+u(i, j+1, &
281 & k)*gridstruct%dx(i, j+1))/(gridstruct%dx(i, j)+&
282 & gridstruct%dx(i, j+1))
290 wv(1, j) = v(1, j, k)*gridstruct%dy(1, j)
291 wv(2, j) = v(2, j, k)*gridstruct%dy(2, j)
294 wu(i, j) = u(i, j, k)*gridstruct%dx(i, j)
297 utmp(i, j) = 2.*(wu(i, j)+wu(i, j+1))/(gridstruct%dx(i, j)&
298 & +gridstruct%dx(i, j+1))
299 vtmp(i, j) = 2.*(wv(1, j)+wv(2, j))/(gridstruct%dy(1, j)+&
300 & gridstruct%dy(2, j))
305 IF (ie + 1 .EQ. npx)
THEN 308 wv(i, j) = v(i, j, k)*gridstruct%dy(i, j)
309 wv(i+1, j) = v(i+1, j, k)*gridstruct%dy(i+1, j)
312 wu(i, j) = u(i, j, k)*gridstruct%dx(i, j)
315 utmp(i, j) = 2.*(wu(i, j)+wu(i, j+1))/(gridstruct%dx(i, j)&
316 & +gridstruct%dx(i, j+1))
317 vtmp(i, j) = 2.*(wv(i, j)+wv(i+1, j))/(gridstruct%dy(i, j)&
318 & +gridstruct%dy(i+1, j))
327 ua(i, j, k) = gridstruct%a11(i, j)*utmp(i, j) + gridstruct%&
328 & a12(i, j)*vtmp(i, j)
329 va(i, j, k) = gridstruct%a21(i, j)*utmp(i, j) + gridstruct%&
330 & a22(i, j)*vtmp(i, j)
337 ua(i, j, k) = a2*(u(i, j-1, k)+u(i, j+2, k)) + a1*(u(i, j, k&
339 va(i, j, k) = a2*(v(i-1, j, k)+v(i+2, j, k)) + a1*(v(i, j, k&
349 SUBROUTINE c2l_ord2_tlm(u, u_tl, v, v_tl, ua, ua_tl, va, va_tl, &
350 & gridstruct, km, grid_type, bd, do_halo)
354 REAL,
INTENT(IN) :: u(bd%isd:bd%ied, bd%jsd:bd%jed+1, km)
355 REAL,
INTENT(IN) :: u_tl(bd%isd:bd%ied, bd%jsd:bd%jed+1, km)
356 REAL,
INTENT(IN) :: v(bd%isd:bd%ied+1, bd%jsd:bd%jed, km)
357 REAL,
INTENT(IN) :: v_tl(bd%isd:bd%ied+1, bd%jsd:bd%jed, km)
359 LOGICAL,
INTENT(IN) :: do_halo
361 REAL,
INTENT(OUT) :: ua(bd%isd:bd%ied, bd%jsd:bd%jed, km)
362 REAL,
INTENT(OUT) :: ua_tl(bd%isd:bd%ied, bd%jsd:bd%jed, km)
363 REAL,
INTENT(OUT) :: va(bd%isd:bd%ied, bd%jsd:bd%jed, km)
364 REAL,
INTENT(OUT) :: va_tl(bd%isd:bd%ied, bd%jsd:bd%jed, km)
367 REAL :: wu(bd%is-1:bd%ie+1, bd%js-1:bd%je+2)
368 REAL :: wu_tl(bd%is-1:bd%ie+1, bd%js-1:bd%je+2)
369 REAL :: wv(bd%is-1:bd%ie+2, bd%js-1:bd%je+1)
370 REAL :: wv_tl(bd%is-1:bd%ie+2, bd%js-1:bd%je+1)
371 REAL :: u1(bd%is-1:bd%ie+1), v1(bd%is-1:bd%ie+1)
372 REAL :: u1_tl(bd%is-1:bd%ie+1), v1_tl(bd%is-1:bd%ie+1)
374 INTEGER :: is, ie, js, je
375 REAL,
DIMENSION(:, :),
POINTER :: a11, a12, a21, a22
376 REAL,
DIMENSION(:, :),
POINTER :: dx, dy, rdxa, rdya
377 a11 => gridstruct%a11
378 a12 => gridstruct%a12
379 a21 => gridstruct%a21
380 a22 => gridstruct%a22
383 rdxa => gridstruct%rdxa
384 rdya => gridstruct%rdya
410 wu_tl(i, j) = dx(i, j)*u_tl(i, j, k)
411 wu(i, j) = u(i, j, k)*dx(i, j)
416 wv_tl(i, j) = dy(i, j)*v_tl(i, j, k)
417 wv(i, j) = v(i, j, k)*dy(i, j)
423 u1_tl(i) = 2.*(wu_tl(i, j)+wu_tl(i, j+1))/(dx(i, j)+dx(i, j+&
425 u1(i) = 2.*(wu(i, j)+wu(i, j+1))/(dx(i, j)+dx(i, j+1))
426 v1_tl(i) = 2.*(wv_tl(i, j)+wv_tl(i+1, j))/(dy(i, j)+dy(i+1, &
428 v1(i) = 2.*(wv(i, j)+wv(i+1, j))/(dy(i, j)+dy(i+1, j))
432 ua_tl(i, j, k) = a11(i, j)*u1_tl(i) + a12(i, j)*v1_tl(i)
433 ua(i, j, k) = a11(i, j)*u1(i) + a12(i, j)*v1(i)
434 va_tl(i, j, k) = a21(i, j)*u1_tl(i) + a22(i, j)*v1_tl(i)
435 va(i, j, k) = a21(i, j)*u1(i) + a22(i, j)*v1(i)
442 ua_tl(i, j, k) = 0.5*(u_tl(i, j, k)+u_tl(i, j+1, k))
443 ua(i, j, k) = 0.5*(u(i, j, k)+u(i, j+1, k))
444 va_tl(i, j, k) = 0.5*(v_tl(i, j, k)+v_tl(i+1, j, k))
445 va(i, j, k) = 0.5*(v(i, j, k)+v(i+1, j, k))
451 SUBROUTINE c2l_ord2(u, v, ua, va, gridstruct, km, grid_type, bd, &
456 REAL,
INTENT(IN) :: u(bd%isd:bd%ied, bd%jsd:bd%jed+1, km)
457 REAL,
INTENT(IN) :: v(bd%isd:bd%ied+1, bd%jsd:bd%jed, km)
459 LOGICAL,
INTENT(IN) :: do_halo
461 REAL,
INTENT(OUT) :: ua(bd%isd:bd%ied, bd%jsd:bd%jed, km)
462 REAL,
INTENT(OUT) :: va(bd%isd:bd%ied, bd%jsd:bd%jed, km)
465 REAL :: wu(bd%is-1:bd%ie+1, bd%js-1:bd%je+2)
466 REAL :: wv(bd%is-1:bd%ie+2, bd%js-1:bd%je+1)
467 REAL :: u1(bd%is-1:bd%ie+1), v1(bd%is-1:bd%ie+1)
469 INTEGER :: is, ie, js, je
470 REAL,
DIMENSION(:, :),
POINTER :: a11, a12, a21, a22
471 REAL,
DIMENSION(:, :),
POINTER :: dx, dy, rdxa, rdya
472 a11 => gridstruct%a11
473 a12 => gridstruct%a12
474 a21 => gridstruct%a21
475 a22 => gridstruct%a22
478 rdxa => gridstruct%rdxa
479 rdya => gridstruct%rdya
497 wu(i, j) = u(i, j, k)*dx(i, j)
502 wv(i, j) = v(i, j, k)*dy(i, j)
508 u1(i) = 2.*(wu(i, j)+wu(i, j+1))/(dx(i, j)+dx(i, j+1))
509 v1(i) = 2.*(wv(i, j)+wv(i+1, j))/(dy(i, j)+dy(i+1, j))
513 ua(i, j, k) = a11(i, j)*u1(i) + a12(i, j)*v1(i)
514 va(i, j, k) = a21(i, j)*u1(i) + a22(i, j)*v1(i)
521 ua(i, j, k) = 0.5*(u(i, j, k)+u(i, j+1, k))
522 va(i, j, k) = 0.5*(v(i, j, k)+v(i+1, j, k))
531 REAL FUNCTION g_sum_tlm(domain, p, p_tl, ifirst, ilast, jfirst, jlast, ngc, area, mode, reproduce, g_sum)
533 integer,
intent(IN) :: ifirst, ilast
534 integer,
intent(IN) :: jfirst, jlast, ngc
535 integer,
intent(IN) :: mode
536 logical,
intent(in),
optional :: reproduce
537 real,
intent(IN) :: p(ifirst:ilast,jfirst:jlast)
538 real,
intent(IN) :: p_tl(ifirst:ilast,jfirst:jlast)
539 real(kind=R_GRID),
intent(IN) :: area(ifirst-ngc:ilast+ngc,jfirst-ngc:jlast+ngc)
540 type(
domain2d),
intent(IN) :: domain
543 logical,
SAVE :: g_sum_initialized = .false.
544 real(kind=R_GRID),
SAVE :: global_area
545 real :: tmp(ifirst:ilast,jfirst:jlast)
548 if ( .not. g_sum_initialized )
then 550 if ( is_master() )
write(*,*)
'Global Area=',global_area
551 g_sum_initialized = .true.
557 if (
present(reproduce) )
then 559 gsum =
mpp_global_sum(domain, p(:,:)*area(ifirst:ilast,jfirst:jlast), &
560 flags=bitwise_efp_sum)
561 gsum_tl =
mpp_global_sum(domain, p_tl(:,:)*area(ifirst:ilast,jfirst:jlast), &
562 flags=bitwise_efp_sum)
564 gsum =
mpp_global_sum(domain, p(:,:)*area(ifirst:ilast,jfirst:jlast))
565 gsum_tl =
mpp_global_sum(domain, p_tl(:,:)*area(ifirst:ilast,jfirst:jlast))
575 gsum = gsum + p(i,j)*area(i,j)
576 gsum_tl = gsum_tl + p_tl(i,j)*area(i,j)
579 call mp_reduce_sum(gsum)
580 call mp_reduce_sum(gsum_tl)
584 g_sum = gsum / global_area
595 REAL FUNCTION g_sum(domain, p, ifirst, ilast, jfirst, jlast, ngc, area, mode, reproduce)
597 integer,
intent(IN) :: ifirst, ilast
598 integer,
intent(IN) :: jfirst, jlast, ngc
599 integer,
intent(IN) :: mode
600 logical,
intent(in),
optional :: reproduce
601 real,
intent(IN) :: p(ifirst:ilast,jfirst:jlast)
602 real(kind=R_GRID),
intent(IN) :: area(ifirst-ngc:ilast+ngc,jfirst-ngc:jlast+ngc)
603 type(
domain2d),
intent(IN) :: domain
606 logical,
SAVE :: g_sum_initialized = .false.
607 real(kind=R_GRID),
SAVE :: global_area
608 real :: tmp(ifirst:ilast,jfirst:jlast)
610 if ( .not. g_sum_initialized )
then 612 if ( is_master() )
write(*,*)
'Global Area=',global_area
613 g_sum_initialized = .true.
619 if (
present(reproduce) )
then 621 gsum =
mpp_global_sum(domain, p(:,:)*area(ifirst:ilast,jfirst:jlast), &
622 flags=bitwise_efp_sum)
624 gsum =
mpp_global_sum(domain, p(:,:)*area(ifirst:ilast,jfirst:jlast))
633 gsum = gsum + p(i,j)*area(i,j)
636 call mp_reduce_sum(gsum)
640 g_sum = gsum / global_area
real, parameter, public radius
Radius of the Earth [m].
real, parameter, public omega
Rotation rate of the Earth [1/s].
subroutine, public cubed_to_latlon(u, v, ua, va, gridstruct, npx, npy, km, mode, grid_type, domain, nested, c2l_ord, bd)
real(kind=8), parameter, public pi_8
Ratio of circle circumference to diameter [N/A].
subroutine, public set_eta(km, ks, ptop, ak, bk)
integer, parameter, public corner
subroutine, public c2l_ord2_tlm(u, u_tl, v, v_tl, ua, ua_tl, va, va_tl, gridstruct, km, grid_type, bd, do_halo)
subroutine grid_utils_init(atm, npx, npy, npz, non_ortho, grid_type, c2l_order)
subroutine, public c2l_ord2(u, v, ua, va, gridstruct, km, grid_type, bd, do_halo)
real, parameter, public ptop_min
subroutine c2l_ord4(u, v, ua, va, gridstruct, npx, npy, km, grid_type, domain, nested, mode, bd)
integer, parameter, public agrid
real function, public g_sum(domain, p, ifirst, ilast, jfirst, jlast, ngc, area, mode, reproduce)
real, parameter tiny_number
subroutine grid_utils_end()
integer, parameter, public ng
subroutine timing_on(blk_name)
integer, parameter, public r_grid
real function, public great_circle_dist(q1, q2, radius)
integer, parameter, public f_p
real, parameter, public big_number
integer, parameter, public scalar_pair
integer, parameter, public cgrid_ne
Derived type containing the data.
real function, public g_sum_tlm(domain, p, p_tl, ifirst, ilast, jfirst, jlast, ngc, area, mode, reproduce, g_sum)
real(fp), parameter, public pi
subroutine timing_off(blk_name)