Ignore:
Timestamp:
Oct 26, 2020 10:05:58 AM (4 years ago)
Author:
eckhard
Message:

inifor: Fixed an error in surface pressure extrapolation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/UTIL/inifor/src/inifor_transform.f90

    r4714 r4756  
    2626! -----------------
    2727! $Id$
     28! Fixed an error in surface pressure extrapolation where the cosmo grid was
     29!    misinterpreted as palm grid
     30! Improved code readability and formatting
     31!
     32!
     33! 4714 2020-09-29 12:47:35Z eckhard
    2834! Fixed off-by-one indexing error for profile quantities
    2935!
     
    381387!------------------------------------------------------------------------------!
    382388 SUBROUTINE interp_average_profile(source_array, profile_array, avg_grid)
    383     TYPE(grid_definition), INTENT(IN)          ::  avg_grid
    384     REAL(wp), DIMENSION(:,:,:), INTENT(IN)     ::  source_array(0:,0:,:)
    385     REAL(wp), DIMENSION(:), INTENT(OUT)        ::  profile_array
     389    TYPE(grid_definition), INTENT(IN)      ::  avg_grid
     390    REAL(wp), DIMENSION(:,:,:), INTENT(IN) ::  source_array(0:,0:,:)
     391    REAL(wp), DIMENSION(:), INTENT(OUT)    ::  profile_array
    386392
    387393    INTEGER(iwp) ::  i_source, j_source, k_profile, k_source, l, m
     
    438444 SUBROUTINE average_profile( source_array, profile_array, avg_grid )
    439445
    440     TYPE(grid_definition), INTENT(IN)          ::  avg_grid
    441     REAL(wp), DIMENSION(:,:,:), INTENT(IN)     ::  source_array(0:,0:,:)
    442     REAL(wp), DIMENSION(:), INTENT(OUT)        ::  profile_array
     446    TYPE(grid_definition), INTENT(IN) ::  avg_grid
     447    REAL(wp), INTENT(IN)              ::  source_array(0:,0:,:)
     448    REAL(wp), INTENT(OUT)             ::  profile_array(:)
    443449
    444450    INTEGER(iwp) ::  i_source, j_source, l, nz, nlev
     
    484490                                           cosmo_grid, avg_grid )
    485491
    486     TYPE(grid_definition), INTENT(IN)          ::  cosmo_grid, avg_grid
    487     REAL(wp), DIMENSION(:,:,:), INTENT(IN)     ::  cosmo_pressure(0:,0:,:)
    488     REAL(wp), DIMENSION(:), INTENT(OUT)        ::  profile_array
    489 
    490     INTEGER(iwp) ::  i_source, j_source, l, nz, nlev
    491 
    492     REAL(wp)                            ::  ni_columns
    493     REAL(wp), DIMENSION(:), ALLOCATABLE ::  basic_state_pressure
     492    TYPE(grid_definition), INTENT(IN) ::  cosmo_grid, avg_grid
     493    REAL(wp), INTENT(IN)              ::  cosmo_pressure(0:,0:,:)
     494    REAL(wp), INTENT(OUT)             ::  profile_array(:)
     495
     496    INTEGER(iwp)          ::  i_source, j_source, l, nz, nlev
     497    REAL(wp)              ::  ni_columns
     498    REAL(wp), ALLOCATABLE ::  basic_state_pressure(:)
    494499
    495500    nlev = SIZE( cosmo_pressure, 3 )
     
    624629! Description:
    625630! ------------
    626 !> Takes the averaged pressure profile <p> and sets the lowest entry to the
    627 !> extrapolated pressure at the surface.
    628 !------------------------------------------------------------------------------!
    629  SUBROUTINE get_surface_pressure(p, rho, avg_grid)
    630     REAL(wp), DIMENSION(:), INTENT(IN)    ::  rho
    631     REAL(wp), DIMENSION(:), INTENT(INOUT) ::  p
     631!> Takes the averaged pressure profile p_palm and sets the lowest entry to the
     632!> extrapolated pressure at the surface, assuming a linear density profile.
     633!------------------------------------------------------------------------------!
     634 SUBROUTINE get_surface_pressure(p_palm, rho_cosmo, avg_grid)
     635    REAL(wp), DIMENSION(:), INTENT(IN)    ::  rho_cosmo
     636    REAL(wp), DIMENSION(:), INTENT(INOUT) ::  p_palm
    632637    TYPE(grid_definition), INTENT(IN)     ::  avg_grid
    633638
    634     REAL(wp)     ::  drhodz, dz, zk, rhok
    635     INTEGER(iwp) ::  k_min
    636 
    637     k_min = avg_grid%k_min
    638     zk    = avg_grid%z(k_min)
    639     rhok  = rho(k_min)
    640     dz    = avg_grid%z(k_min + 1) - avg_grid%z(k_min)
    641     drhodz = ( rho(k_min + 1) - rho(k_min) ) / dz
    642 
    643     p(1) = linear_density_pressure( p(k_min), zk, rhok, drhodz,                &
    644                                     z = 0.0_wp, g=G )
     639    REAL(wp)     ::  drhodz_surface_cosmo
     640    INTEGER(iwp) ::  k_min_palm
     641
     642    drhodz_surface_cosmo =                                                     &
     643       ( rho_cosmo(2) - rho_cosmo(1) ) /                                       &
     644       ( avg_grid%intermediate_h(1,1,2) - avg_grid%intermediate_h(1,1,1) )
     645
     646    k_min_palm = avg_grid%k_min
     647
     648    p_palm(1) = linear_density_pressure(                                       &
     649       p0 = p_palm(k_min_palm),                                                &
     650       z0 = avg_grid%z(k_min_palm),                                            &
     651       rho00 = rho_cosmo(1),                                                   &
     652       z00 = avg_grid%intermediate_h(1,1,1),                                   &
     653       drhodz = drhodz_surface_cosmo,                                          &
     654       g = G,                                                                  &
     655       z = 0.0_wp                                                              &
     656    )
    645657
    646658 END SUBROUTINE get_surface_pressure
    647659
    648660
    649  FUNCTION linear_density_pressure(pk, zk, rhok, drhodz, z, g)  RESULT(p)
    650 
    651     REAL(wp), INTENT(IN)  ::  pk, zk, rhok, drhodz, g, z
     661!------------------------------------------------------------------------------!
     662! Description:
     663! -----------
     664!> Computes the hydrostatic pressure p at height z given the pressure p0 at
     665!> height z0. The pressure is computed based on the solution of the hydrostatic
     666!> equation assuming a linear density profile with density rho00 at z00 and the
     667!> vertical density gradient drhodz.
     668!------------------------------------------------------------------------------!
     669 FUNCTION linear_density_pressure(p0, z0, rho00, z00, drhodz, g, z)  RESULT(p)
     670
     671    REAL(wp), INTENT(IN)  ::  p0, z0, rho00, z00, drhodz, g, z
    652672    REAL(wp) ::  p
    653673
    654     p = pk + ( zk - z ) * g * ( rhok - 0.5_wp * drhodz * (zk - z) )
     674    p = p0 - ( z - z0 ) * g * (                                                &
     675           rho00 + 0.5_wp * drhodz * ( z + z0 - 2.0_wp * z00 )                 &
     676        )
    655677
    656678 END FUNCTION linear_density_pressure
    657679
    658 !-----------------------------------------------------------------------------!
     680!------------------------------------------------------------------------------!
    659681! Description:
    660682! -----------
    661683!> This routine computes profiles of the two geostrophic wind components ug and
    662684!> vg.
    663 !-----------------------------------------------------------------------------!
     685!------------------------------------------------------------------------------!
    664686 SUBROUTINE geostrophic_winds(p_north, p_south, p_east, p_west, rho, f3,    &
    665687                              Lx, Ly, phi_n, lam_n, phi_g, lam_g, ug, vg)
     
    683705
    684706
    685 !-----------------------------------------------------------------------------!
     707!------------------------------------------------------------------------------!
    686708! Description:
    687709! -----------
     
    689711!> Cartesian coordinates (x,y) onto a sphere. It returns the latitude and
    690712!> lngitude of a geographical system centered at x0 and y0.
    691 !-----------------------------------------------------------------------------!
     713!------------------------------------------------------------------------------!
    692714 SUBROUTINE inv_plate_carree(x, y, x0, y0, r, lat, lon)
    693715    REAL(wp), INTENT(IN)  ::  x(:), y(:), x0, y0, r
     
    706728
    707729
    708 !-----------------------------------------------------------------------------!
     730!------------------------------------------------------------------------------!
    709731! Description:
    710732! ------------
Note: See TracChangeset for help on using the changeset viewer.