1 subroutine da_wpec_constraint_lin(grid, xbx)
3 !---------------------------------------------------------------------------
4 ! Purpose: Calculates TLM of balance equation G(x)
5 !---------------------------------------------------------------------------
9 type(domain), intent(inout) :: grid
10 type(xbx_type), intent(in) :: xbx ! Header & non-gridded vars.
12 integer :: i, j, k ! Loop counters.
13 integer :: is, ie ! 1st dim. end points.
14 integer :: js, je ! 2nd dim. end points.
16 real :: coefx(ims:ime,jms:jme) ! Multiplicative coefficient.
17 real :: coefy(ims:ime,jms:jme) ! Multiplicative coefficient.
18 real :: term_x(ims:ime,jms:jme) ! Balance eqn x term
19 real :: term_y(ims:ime,jms:jme) ! Balance eqn y term
20 real :: phi_b_x(ims:ime,jms:jme) ! Balance eqn x term
21 real :: phi_b_y(ims:ime,jms:jme) ! Balance eqn y term
24 if (trace_use) call da_trace_entry("da_wpec_constraint_lin")
26 !---------------------------------------------------------------------------
27 ! [1.0] Initialise i and set multiplicative constants
28 !---------------------------------------------------------------------------
30 is = its; ie = ite; js = jts; je = jte
31 if (.not.global .and. its == ids) is = ids+1
32 if (.not.global .and. ite == ide) ie = ide-1
33 if (jts == jds ) js = jds+1; if (jte == jde) je = jde-1
35 if (fg_format == fg_format_kma_global) then
38 else if( fg_format == fg_format_wrf_arw_regional) then
41 else if (fg_format == fg_format_wrf_arw_global) then
42 write (unit=message(1),fmt='(A,I3)') ' needs work for fg_format_wrf_arw_global = ',fg_format
43 call da_error(__FILE__,__LINE__,message(1:1))
44 else if (fg_format == fg_format_wrf_nmm_regional) then
45 write (unit=message(1),fmt='(A,I3)') ' needs work for fg_format_wrf_nmm_regional = ',fg_format
46 call da_error(__FILE__,__LINE__,message(1:1))
48 write(unit=message(1),fmt='(A,I3)') 'Wrong FG_FORMAT = ',fg_format
49 call da_error(__FILE__,__LINE__,message(1:1))
63 !---------------------------------------------------------------------------
64 ! [2.0] Calculate RHS of balance equation in gridpoint space:
65 !---------------------------------------------------------------------------
67 ! [2.1] Include geostrophic terms in balance eqn if requested:
69 if (balance_type == balance_geo .OR. balance_type == balance_geocyc ) then
71 ! [2.1.1] Calculate term_x = -f rho v~:
72 term_x = term_x - grid%xb%rho(:,:,k) * grid%xb%cori * grid%xa%v(:,:,k)
74 ! [2.1.2] Calculate term_y = f rho u~:
75 term_y = term_y + grid%xb%rho(:,:,k) * grid%xb%cori * grid%xa%u(:,:,k)
79 ! [2.2] Include cyclostrophic terms in balance eqn if requested:
81 if (balance_type == balance_cyc .OR. balance_type == balance_geocyc ) then
85 ! [2.2.1] Calculate term_x = rho M ( u'du/dx + v'du/dy + udu'/dx + vdu'/dy )
86 term_x(i,j) = term_x(i,j) + grid%xb%rho(i,j,k) * &
87 ( coefx(i,j)*grid%xa%u(i,j,k) * ( grid%xb%u(i+1,j,k) - grid%xb%u(i-1,j,k)) + &
88 coefy(i,j)*grid%xa%v(i,j,k) * ( grid%xb%u(i,j+1,k) - grid%xb%u(i,j-1,k)) + &
89 coefx(i,j)*grid%xb%u(i,j,k) * ( grid%xa%u(i+1,j,k) - grid%xa%u(i-1,j,k)) + &
90 coefy(i,j)*grid%xb%v(i,j,k) * ( grid%xa%u(i,j+1,k) - grid%xa%u(i,j-1,k)))
92 ! [2.2.2] Calculate term_y = rho M ( u'dv/dx + v'dv/dy + udv'/dx + vdv'/dy )
93 term_y(i,j) = term_y(i,j) + grid%xb%rho(i,j,k) * &
94 ( coefx(i,j)*grid%xa%u(i,j,k) * ( grid%xb%v(i+1,j,k) - grid%xb%v(i-1,j,k)) + &
95 coefy(i,j)*grid%xa%v(i,j,k) * ( grid%xb%v(i,j+1,k) - grid%xb%v(i,j-1,k)) + &
96 coefx(i,j)*grid%xb%u(i,j,k) * ( grid%xa%v(i+1,j,k) - grid%xa%v(i-1,j,k)) + &
97 coefy(i,j)*grid%xb%v(i,j,k) * ( grid%xa%v(i,j+1,k) - grid%xa%v(i,j-1,k)))
103 ! [2.3] Include phi_b terms in balance eqn
106 phi_b_x(i,j) = coefx(i,j)*(grid%xa%p(i+1,j,k)-grid%xa%p(i-1,j,k) + grid%xb % rho(i,j,k)*(grid%xa%geoh(i+1,j,k)-grid%xa%geoh(i-1,j,k)) )
107 phi_b_y(i,j) = coefy(i,j)*(grid%xa%p(i,j+1,k)-grid%xa%p(i,j-1,k) + grid%xb % rho(i,j,k)*(grid%xa%geoh(i,j+1,k)-grid%xa%geoh(i,j-1,k)) )
111 !------------------------------------------------------------------------------
112 ! [3.0] Solve Grad_p for balance equation :
113 !------------------------------------------------------------------------------
116 grid%xa%grad_p_x(i,j,k)=phi_b_x(i,j)+term_x(i,j)
117 grid%xa%grad_p_y(i,j,k)=phi_b_y(i,j)+term_y(i,j)
123 if (trace_use) call da_trace_exit("da_wpec_constraint_lin")
125 end subroutine da_wpec_constraint_lin