Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / var / da / da_lightning / da_div_profile_adj.inc
blob80b7855920b0b091196ba324af5f194372b00eb7
1 subroutine da_div_profile_adj(grid,jo_grad_x, info, n, k, ADJ_div)
3    !--------------------------------------------------------------------------
4    ! Purpose: Calculates divergence (div) on each level at the observed location (i,j). 
5    ! dx, dxm, dy, dym are horizontal interpolation weighting.
6    !                        d   U      d   V
7    !           Div = m^2 *[---(---) + ---(---) ] 
8    !                        dx  m      dy  M
9    ! Authors: Z Chen (zchen@fjnu.edu.cn), Jenny Sun (NCAR), X Qie (IAP)
10    !--------------------------------------------------------------------------
12    implicit none
14    type (x_type),         intent(inout) :: jo_grad_x ! grad_x(jo)
15    type (domain),         intent(in)    :: grid
16    type (infa_type),      intent(in)    :: info
17    integer,               intent(in)    :: n, k
18    real,                  intent(out)   :: ADJ_div
19                           
20    integer :: ii, jj    ! index dimension.
21   
22    integer :: i, j      ! OBS location
23    real    :: dx, dxm   ! interpolation weights.
24    real    :: dy, dym   ! interpolation weights.
25    real    :: coeff  
26    real    :: ADJ_div_m(2,2)
27    
28    if (trace_use_dull) call da_trace_entry ("da_div_profile_adj")
30    i   = info%i(1,n)
31    j   = info%j(1,n)
32    dx  = info%dx(1,n)
33    dy  = info%dy(1,n)
34    dxm = info%dxm(1,n)
35    dym = info%dym(1,n)
37 ! avoid the boundary mistake   
38    if(i == its) i = its + 1
39    if(i == ite) i = ite - 1
40    if(j == jts) j = jts + 1
41    if(j == jte) j = jte - 1
43    ADJ_div_m(1,1) = dym*dxm * ADJ_div
44    ADJ_div_m(2,1) = dym*dx *  ADJ_div
45    ADJ_div_m(1,2) = dy*dxm*   ADJ_div
46    ADJ_div_m(2,2) = dy*dx*    ADJ_div
47    ADJ_div        = 0.0
49    do ii = i, i+1
50       do jj = j, j+1
51          coeff = grid%xb%map_factor(ii,jj) * grid%xb%map_factor(ii,jj)*0.5/grid%xb%ds
52          
53          jo_grad_x%u(ii+1,jj,k) = jo_grad_x%u(ii+1,jj,k) + ADJ_div_m(ii-i+1,jj-j+1)/grid%xb%map_factor(ii+1,jj)*coeff
54                                                                   
55          jo_grad_x%u(ii-1,jj,k) = jo_grad_x%u(ii-1,jj,k) - ADJ_div_m(ii-i+1,jj-j+1)/grid%xb%map_factor(ii-1,jj)*coeff
56                                                                   
57          jo_grad_x%v(ii,jj+1,k) = jo_grad_x%v(ii,jj+1,k) + ADJ_div_m(ii-i+1,jj-j+1)/grid%xb%map_factor(ii,jj+1)*coeff
58                                                                   
59          jo_grad_x%v(ii,jj-1,k) = jo_grad_x%v(ii,jj-1,k) - ADJ_div_m(ii-i+1,jj-j+1)/grid%xb%map_factor(ii,jj-1)*coeff
60       end do
61    end do
63    if (trace_use_dull) call da_trace_exit("da_div_profile_adj")
65 end subroutine da_div_profile_adj