Skip to content

Commit d5e2c86

Browse files
committed
wip - progress on interface
1 parent 1a59f92 commit d5e2c86

File tree

5 files changed

+132
-11
lines changed

5 files changed

+132
-11
lines changed

src/Radiation/Radiation.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ module Radiation
22

33
export
44
AbstractRadiationModel,
5-
RRTMGPModel,
6-
initialize_rrtmgp_model,
7-
compute_vertical_fluxes!,
8-
flux_results
5+
GrayRadiationModel,
6+
update_radative_fluxes!
97

10-
include("rrtmgp_backend.jl")
8+
include("rrtmgp_interface.jl")
119
include("radiation_model.jl")
10+
include("radiation_model_utils.jl")
11+
include("radiation_model_gray.jl")
1212

1313
end

src/Radiation/gray_breezy.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ p_surface = 100_000 # surface pressure (Pa)
3131
p_top = 9_000 # top of atmosphere pressure / emission level (Pa)
3232
lat_center = 0
3333
optical_properties = GrayOpticalThicknessSchneider2004(FT)
34-
# cos_zenith .= cos(deg2rad * 52.95) # corresponding to ~52.95 deg zenith angle
35-
# toa_flux .= FT(1407.679)
36-
# sfc_alb_direct .= FT(0.1)
37-
# sfc_alb_diffuse .= FT(0.1)
38-
# inc_flux_diffuse = nothing
39-
# Grid setup, we also need to say where on the planet our box is located
4034
grid = RectilinearGrid(
4135
architecture,
4236
FT,

src/Radiation/radiation_model.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
abstract type AbstractRadiationModel end
2+
3+
function update_radative_fluxes!(model::AbstractRadiationModel)
4+
throw("Not implemented for $(typeof(model)).")
5+
end
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

src/Radiation/radiation_model_utils.jl

Whitespace-only changes.

0 commit comments

Comments
 (0)