1 subroutine da_hydrostaticp_to_rho_lin(grid, p, rho )
3 !---------------------------------------------------------------------------
4 ! Purpose: Calculates density increment from pressure increment fiteld.
6 ! Method: Hydrostatic eqn => rho~ = -dP~/dz / g.
8 ! Assumptions: 1) Hydrostatic pressure.
9 ! 2) Model level stored top down.
11 !---------------------------------------------------------------------------
15 type(domain), intent(in) :: grid
16 real, intent(in) :: p(ims:ime,jms:jme,kms:kme) ! Pressure inc. (cross pts)
17 real, intent(out) :: rho(ims:ime,jms:jme,kms:kme) ! Density inc. (cross pts)
19 integer :: i, j, k ! Loop counters.
20 real :: delta1 ! Height difference.
21 real :: delta2 ! Height difference.
22 real :: dPdz ! Vertical pressure gradient.
24 if (trace_use) call da_trace_entry("da_hydrostaticp_to_rho_lin")
26 !---------------------------------------------------------------------------
27 ! [2.0] Calculate density increments at all levels except top/bottom:
28 !---------------------------------------------------------------------------
31 rho(its:ite,jts:jte,k) = -( p(its:ite,jts:jte,k+1) - p(its:ite,jts:jte,k-1) ) / &
32 ( ( grid%xb % h(its:ite,jts:jte,k+1) - &
33 grid%xb % h(its:ite,jts:jte,k-1) ) * gravity )
36 !---------------------------------------------------------------------------
37 ! [3.0] Calculate density increment on bottom level:
38 !---------------------------------------------------------------------------
43 ! dP~/dz by backwards one-sided 2nd order finite differences:
45 delta1 = grid%xb % h(i,j,k+1) - grid%xb % h(i,j,k)
46 delta2 = grid%xb % h(i,j,k+2) - grid%xb % h(i,j,k)
47 dPdz = -( delta1 + delta2 ) * p(i,j,k) / ( delta1 * delta2 ) + &
48 ( delta2 / delta1 ) * p(i,j,k+1)/ ( delta2 - delta1 ) - &
49 ( delta1 / delta2 ) * p(i,j,k+2)/ ( delta2 - delta1 )
51 ! Put together to get density increment at top level:
52 rho(i,j,k) = -dPdz / gravity
56 !---------------------------------------------------------------------------
57 ! [4.0] Calculate density increment on top level:
58 !---------------------------------------------------------------------------
63 ! dP~/dz by forwards one-sided 2nd order finite differences:
65 delta1 = grid%xb % h(i,j,k) - grid%xb % h(i,j,k-1)
66 delta2 = grid%xb % h(i,j,k) - grid%xb % h(i,j,k-2)
68 dPdz = ( delta1 + delta2 ) * p(i,j,k) / ( delta1 * delta2 ) - &
69 ( delta2 / delta1 ) * p(i,j,k-1) / ( delta2 - delta1 ) + &
70 ( delta1 / delta2 ) * p(i,j,k-2) / ( delta2 - delta1 )
72 ! Put together to get density increment at bottom level:
73 rho(i,j,k) = -dPdz / gravity
77 if (trace_use) call da_trace_exit("da_hydrostaticp_to_rho_lin")
79 end subroutine da_hydrostaticp_to_rho_lin