1 subroutine da_hydrostaticp_to_rho_adj (xb, rho, p)
3 !---------------------------------------------------------------------------
4 ! Purpose: Adjoint of da_hydrostaticp_to_rho.
6 ! Method: Standard adjoint coding.
8 ! Assumptions: 1) Hydrostatic pressure.
9 ! 2) Model level stored top down.
10 !---------------------------------------------------------------------------
14 type(xb_type), intent(in) :: xb ! First guess structure.
15 real, intent(in) :: rho(ims:ime,jms:jme,kms:kme) ! Density inc. (cross pts).
16 real, intent(inout) :: p(ims:ime,jms:jme,kms:kme) ! Pressure inc. (cross pts)
18 integer :: i, j, k ! Loop counters.
19 real :: delta1 ! Height difference.
20 real :: delta2 ! Height difference.
21 real :: dPdz ! Vertical pressure gradient.
22 real :: temp(its:ite,jts:jte) ! Temporary array.
24 if (trace_use) call da_trace_entry("da_hydrostaticp_to_rho_adj")
26 !---------------------------------------------------------------------------
27 ! [4.0] Calculate density increment on top level:
28 !---------------------------------------------------------------------------
33 ! Put together to get density increment at bottom level:
34 dPdz = -rho(i,j,kte) / gravity
36 ! dP~/dz by forwards one-sided 2nd order finite differences:
38 delta1 = xb % h(i,j,kte) - xb % h(i,j,kte-1)
39 delta2 = xb % h(i,j,kte) - xb % h(i,j,kte-2)
41 p(i,j,k) = p(i,j,kte) + ( delta1 + delta2 ) * dPdz / (delta1 * delta2)
42 p(i,j,k-1) = p(i,j,kte-1) - (delta2 / delta1) * dPdz / (delta2 - delta1)
43 p(i,j,k-2) = p(i,j,kte-2) + (delta1 / delta2) * dPdz / (delta2 - delta1)
47 !---------------------------------------------------------------------------
48 ! [3.0] Calculate density increment on top level:
49 !---------------------------------------------------------------------------
54 ! Put together to get density increment at top level:
55 dPdz = -rho(i,j,kts) / gravity
57 ! dP~/dz by backwards one-sided 2nd order finite differences:
59 delta1 = xb % h(i,j,kts+1) - xb % h(i,j,kts)
60 delta2 = xb % h(i,j,kts+2) - xb % h(i,j,kts)
62 p(i,j,kts) = p(i,j,k) - (delta1 + delta2) * dPdz / (delta1 * delta2)
63 p(i,j,kts+1) = p(i,j,kts+1) + (delta2 / delta1) * dPdz / (delta2 - delta1)
64 p(i,j,kts+2) = p(i,j,kts+2) - (delta1 / delta2) * dPdz / (delta2 - delta1)
68 !---------------------------------------------------------------------------
69 ! [2.0] Calculate density increments at all levels except top/bottom:
70 !---------------------------------------------------------------------------
72 do k = kte-1, kts+1, -1
73 temp(its:ite,jts:jte) = -rho(its:ite,jts:jte,k) / &
74 ((xb%h(its:ite,jts:jte,k+1) - xb%h(its:ite,jts:jte,k-1)) * gravity)
76 p(its:ite,jts:jte,k-1) = p(its:ite,jts:jte,k-1) - temp(its:ite,jts:jte)
77 p(its:ite,jts:jte,k+1) = p(its:ite,jts:jte,k+1) + temp(its:ite,jts:jte)
80 end subroutine da_hydrostaticp_to_rho_adj