@@ -386,6 +386,95 @@ function overwrite_initial_conditions!(
386386 )
387387end
388388
389+ """
390+ correct_surface_pressure_for_topography!(
391+ p_sfc,
392+ file_path,
393+ face_space,
394+ Y,
395+ ᶜT,
396+ ᶜq_tot,
397+ thermo_params,
398+ regridder_kwargs;
399+ surface_altitude_var = "z_sfc",
400+ )
401+
402+ Adjusts the surface pressure field `p_sfc` to account for mismatches between
403+ ERA5 (file) surface altitude and the model orography when specifying pressure.
404+
405+ Δz = z_model_surface - z_sfc
406+
407+ and applies a hydrostatic correction at the surface using the local moist gas
408+ constant and temperature at the surface:
409+
410+ p_sfc .= p_sfc .* exp.(-Δz * g ./ (R_m_sfc .* T_sfc))
411+
412+ where:
413+ - `g` is gravitational acceleration from `thermo_params`
414+ - `R_m_sfc` is the moist-air gas constant evaluated from `ᶜq_tot` at the surface
415+ - `T_sfc` is the air temperature from `ᶜT` at the surface
416+
417+ A small floor is applied to the denominator `R_m_sfc .* T_sfc` to avoid
418+ numerical blow-ups, and non-finite `Δz` entries leave `p_sfc` unchanged.
419+
420+ Returns `true` if the correction is applied; returns `false` if the surface
421+ altitude field cannot be loaded.
422+
423+ Arguments
424+ - `p_sfc`: face field of surface pressure to be corrected (modified in-place)
425+ - `file_path`: path to the ERA5-derived initialization NetCDF file
426+ - `face_space`: face space of the model grid (for reading/regridding)
427+ - `Y`: prognostic state, used to obtain model surface height
428+ - `ᶜT`: center field of temperature
429+ - `ᶜq_tot`: center field of total specific humidity
430+ - `thermo_params`: thermodynamics parameter set
431+ - `regridder_kwargs`: keyword arguments forwarded to the regridder
432+ - `surface_altitude_var`: variable name for surface altitude (default `"z_sfc"`)
433+ """
434+ function correct_surface_pressure_for_topography! (
435+ p_sfc,
436+ file_path,
437+ face_space,
438+ Y,
439+ ᶜT,
440+ ᶜq_tot,
441+ thermo_params,
442+ regridder_kwargs;
443+ surface_altitude_var = " z_sfc" ,
444+ )
445+ ᶠz_surface = Fields. level (
446+ SpaceVaryingInputs. SpaceVaryingInput (
447+ file_path,
448+ surface_altitude_var,
449+ face_space,
450+ regridder_kwargs = regridder_kwargs,
451+ ),
452+ Fields. half,
453+ )
454+
455+ if ᶠz_surface === nothing
456+ return false
457+ end
458+
459+ FT = eltype (thermo_params)
460+ grav = thermo_params. grav
461+
462+ ᶠz_model_surface = Fields. level (Fields. coordinate_field (Y. f). z, Fields. half)
463+ ᶠΔz = zeros (face_space)
464+ @. ᶠΔz = ᶠz_model_surface - ᶠz_surface
465+
466+ ᶠR_m = ᶠinterp .(TD. gas_constant_air .(thermo_params, TD. PhasePartition .(ᶜq_tot)))
467+ ᶠR_m_sfc = Fields. level (ᶠR_m, Fields. half)
468+
469+ ᶠT = ᶠinterp .(ᶜT)
470+ ᶠT_sfc = Fields. level (ᶠT, Fields. half)
471+
472+ @. p_sfc = p_sfc * exp (FT (- 1 ) * ᶠΔz * grav / (ᶠR_m_sfc * ᶠT_sfc))
473+
474+ @info " Adjusted surface pressure to account for ERA5/model surface-height differences."
475+ return true
476+ end
477+
389478# WeatherModel function using the shared implementation
390479function overwrite_initial_conditions! (
391480 initial_condition:: WeatherModel ,
@@ -436,6 +525,26 @@ function overwrite_initial_conditions!(
436525 center_space,
437526 regridder_kwargs = regridder_kwargs,
438527 )
528+ # Apply hydrostatic surface-pressure correction only if surface altitude is available
529+ surface_altitude_var = " z_sfc"
530+ has_surface_altitude = NC. NCDataset (file_path) do ds
531+ haskey (ds, surface_altitude_var)
532+ end
533+ if has_surface_altitude
534+ correct_surface_pressure_for_topography! (
535+ p_sfc,
536+ file_path,
537+ face_space,
538+ Y,
539+ ᶜT,
540+ ᶜq_tot,
541+ thermo_params,
542+ regridder_kwargs;
543+ surface_altitude_var = surface_altitude_var,
544+ )
545+ else
546+ @warn " Skipping topographic correction because variable `$surface_altitude_var ` is missing from $(file_path) ."
547+ end
439548
440549 # With the known temperature (ᶜT) and moisture (ᶜq_tot) profile,
441550 # recompute the pressure levels assuming hydrostatic balance is maintained.
0 commit comments