|
| 1 | +using RRTMGP.Optics: GrayOpticalThicknessSchneider2004 |
| 2 | +using RRTMGP.AtmosphericStates: GrayAtmosphericState |
| 3 | +using RRTMGP.RTE: TwoStreamLWRTE, TwoStreamSWRTE |
| 4 | +using RRTMGP.RTESolver: solve_lw!, solve_sw! |
| 5 | + |
| 6 | +using Oceananigans |
| 7 | +using Oceananigans: field |
| 8 | +using Oceananigans.Architectures: array_type |
| 9 | +using Oceananigans: RectilinearGrid |
| 10 | + |
| 11 | +mutable struct GrayRadiationModel{FT, DA, SLVLW, SLVSW, AS, OTP} <: AbstractRadiationModel |
| 12 | + atmospheric_state :: AS |
| 13 | + slv_lw :: SLVLW |
| 14 | + slv_sw :: SLVSW |
| 15 | + optical_properties :: OTP |
| 16 | + cos_zenith_angle :: DA{FT} |
| 17 | + sfc_emissivity :: DA{FT} |
| 18 | + sfc_albedo_direct :: DA{FT} |
| 19 | + sfc_albedo_diffuse :: DA{FT} |
| 20 | + sw_toa_flux_inc :: DA{FT} |
| 21 | + sw_inc_flux_diffuse :: Union{Nothing, DA{FT}} |
| 22 | + lw_toa_inc_flux :: Union{Nothing, DA{FT}} |
| 23 | +end |
| 24 | + |
| 25 | +function GrayRadiationModel( |
| 26 | + grid; |
| 27 | + temperature, |
| 28 | + pressure, |
| 29 | + cos_zenith_angle, |
| 30 | + sfc_emissivity, |
| 31 | + sfc_albedo_direct, |
| 32 | + sfc_albedo_diffuse, |
| 33 | + sw_flux_inc_toa, |
| 34 | + sw_flux_inc_toa_diffusive, |
| 35 | + lw_flux_inc_toa, |
| 36 | + optical_properties=GrayOpticalThicknessSchneider2004(FT), |
| 37 | + lat_center=0 |
| 38 | +) |
| 39 | + # We assemble objects required for RRTMGP to work. |
| 40 | + atmospheric_state = GrayAtmosphericState( |
| 41 | + grid; |
| 42 | + temperature, |
| 43 | + pressure, |
| 44 | + otp=optical_properties, |
| 45 | + lat_center=lat_center |
| 46 | + ) |
| 47 | + SLVLW = TwoStreamLWRTE |
| 48 | + SLVSW = TwoStreamSWRTE |
| 49 | + lw_params = ( |
| 50 | + sfc_emission = sfc_emissivity, |
| 51 | + lw_inc_flux = lw_flux_inc_toa, |
| 52 | + ) |
| 53 | + sw_params = ( |
| 54 | + cos_zenith = cos_zenith_angle, |
| 55 | + toa_flux = sw_flux_inc_toa, |
| 56 | + sfc_alb_direct = sfc_albedo_diffuse, |
| 57 | + inc_flux_diffuse = sw_flux_inc_toa_diffusive, |
| 58 | + sfc_alb_diffuse = sfc_albedo_diffuse, |
| 59 | + ) |
| 60 | + slv_lw = SLVLW(grid; lw_params...) |
| 61 | + slv_sw = SLVSW(grid; sw_params...) |
| 62 | + |
| 63 | + if sfc_emissivity isa DA |
| 64 | + |
| 65 | + elseif sfc_emissivity isa AbstractFloat |
| 66 | + |
| 67 | + end |
| 68 | + |
| 69 | + return GrayRadiationModel( |
| 70 | + atmospheric_state, |
| 71 | + slv_lw, |
| 72 | + slv_sw, |
| 73 | + optical_properties, |
| 74 | + cos_zenith_angle, |
| 75 | + sfc_emission, |
| 76 | + sfc_albedo_direct, |
| 77 | + sfc_albedo_diffuse, |
| 78 | + sw_flux_inc_toa, |
| 79 | + sw_flux_inc_toa_diffusive, |
| 80 | + lw_flux_inc_toa, |
| 81 | + ) |
| 82 | +end |
| 83 | + |
| 84 | +function GrayRadiationModel( |
| 85 | + grid; |
| 86 | + temperature :: Field, |
| 87 | + pressure :: Field, |
| 88 | + zenith_angle :: FT, |
| 89 | + sfc_emissivity :: FT, |
| 90 | + sfc_albedo_direct :: FT, |
| 91 | + sfc_albedo_diffuse :: FT, |
| 92 | + sw_flux_inc_toa :: FT, |
| 93 | + sw_flux_inc_toa_diffusive :: Union{Nothing, FT}, |
| 94 | + lw_flux_inc_toa :: Union{Nothing, FT}, |
| 95 | + optical_properties=GrayOpticalThicknessSchneider2004(FT), |
| 96 | + lat_center=0 |
| 97 | +) |
| 98 | + FT = eltype(grid) |
| 99 | + DA = device_array(grid.architecture) |
| 100 | + Nx, Ny, Nz = grid.Nx, grid.Ny, grid.Nz |
| 101 | + Nbnd = 1 |
| 102 | + |
| 103 | + |
| 104 | + sfc_emission = DA{FT}(undef, Nbnd, Nx, Ny) |
| 105 | + sfc_alb_direct = DA{FT}(undef, Nbnd, Nx, Ny) |
| 106 | + sfc_alb_diffuse = DA{FT}(undef, Nbnd, Nx, Ny) |
| 107 | + cos_zenith = DA{FT}(undef, Nx, Ny) |
| 108 | + toa_flux = DA{FT}(undef, Nx, Ny) |
| 109 | + lw_toa_inc_flux = nothing |
| 110 | + inc_flux_diffuse = nothing |
| 111 | + fill!(sfc_emission, FT(sfc_emissivity)) |
| 112 | + fill!(sfc_alb_direct, FT(albedo_direct)) |
| 113 | + fill!(sfc_alb_diffuse, FT(albedo_diffuse)) |
| 114 | + fill!(cos_zenith, FT(cos(deg2rad * zenith_angle))) |
| 115 | + fill!(toa_flux, FT(sw_inc_flux)) |
| 116 | +end |
| 117 | + |
| 118 | +function (rad::GrayRadiationModel)(::Val{:ρe}, temperature, pressure) |
| 119 | + update_atmospheric_state(rad, temperature, pressure) |
| 120 | + solve_lw!(rad.slv_lw, rad.atmospheric_state) |
| 121 | + solve_sw!(rad.slv_sw, rad.atmospheric_state) |
| 122 | +end |
0 commit comments