Skip to content

Commit

Permalink
Surface albedo fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nichollsh committed Jul 4, 2024
1 parent 7452efb commit 8dd3460
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 59 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ See the Getting Started page in the [documentation](https://nichollsh.github.io/
## Repository structure
* `agni.jl` - AGNI executable
* `LICENSE.txt` - License for use and re-use
* `doc/` - Further documentation
* `out/` - Output files
* `res/` - Resources (configuration files, etc.)
* `deps/` - Package build scripts
* `docs/` - Documentation source files
* `misc/` - Miscellaneous files
* `out/` - Model output
* `res/` - Resources (configs, thermodynamic data, etc.)
* `src/` - Package source code
* `test/` - Package tests
* `tutorials/` - Notebooks and tutorials
Expand Down
4 changes: 2 additions & 2 deletions res/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ title = "Default" # Name for this configuration file
albedo_b = 0.18 # Pseudo bond-albedo which downscales the stellar flux by 1-this_value.
s0_fact = 0.6652 # Stellar flux scale factor which accounts for planetary rotation (c.f. Cronin+13).
zenith_angle = 60.0 # Characteristic zenith angle for incoming stellar radiation [degrees].
surface_material= "res/surface_albedo/c9mb29.tab" # Surface material (can be "blackbody" or path to spectral albedo file).
surface_material= "blackbody" # Surface material (can be "blackbody" or path to data file).
albedo_s = 0.12 # Grey surface albedo when material=blackbody.
radius = 6.37e6 # Planet radius at the surface [m].
gravity = 9.81 # Gravitational acceleration at the surface [m s-2]
Expand All @@ -23,7 +23,7 @@ title = "Default" # Name for this configuration file

[files]
input_sf = "res/spectral_files/Frostflow/256/Frostflow.sf" # Path to SOCRATES spectral file.
input_star = "res/stellar_spectra/sun.txt" # Path to stellar spectrum.
input_star = "res/stellar_spectra/trappist-1.txt" # Path to stellar spectrum.
output_dir = "out/" # Path to output directory.

[composition]
Expand Down
101 changes: 54 additions & 47 deletions src/atmosphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -984,57 +984,16 @@ module atmosphere
atmos.dimen.nd_subcol_gen = 1
atmos.dimen.nd_subcol_req = 1
atmos.dimen.nd_aerosol_mode = 1

# atmos.control.l_flux_ground = false

SOCRATES.allocate_atm( atmos.atm, atmos.dimen, atmos.spectrum)
SOCRATES.allocate_cld( atmos.cld, atmos.dimen, atmos.spectrum)
SOCRATES.allocate_aer( atmos.aer, atmos.dimen, atmos.spectrum)
SOCRATES.allocate_bound(atmos.bound, atmos.dimen, atmos.spectrum)

###########################################
# Surface properties
###########################################
atmos.albedo_s_arr = zeros(Float64, atmos.nbands)

# set array values
if atmos.surface_material == "blackbody"
# grey albedo
fill!(atmos.albedo_s_arr, atmos.albedo_s)

else
# spectral albedo

# try to find a matching file
atmos.surface_material = abspath(atmos.surface_material)
if !isfile(atmos.surface_material)
error("Could not find surface albedo file '$(atmos.surface_material)'")
end
# fill!(atmos.bound.flux_ground, 100.0)

# read data from file
_alb_data::Array = readdlm(atmos.surface_material, Float64)
_alb_w::Array{Float64, 1} = _alb_data[:,1] # wavelength [nm]
_alb_a::Array{Float64, 1} = _alb_data[:,2] # albedo [dimensionless]

# extrapolate to 0 wavelength, with constant value
pushfirst!(_alb_w, 0.0)
pushfirst!(_alb_a, _alb_a[1])

# extrapolate to large wavelength, with constant value
push!(_alb_w, 1e10)
push!(_alb_a, _alb_a[end])

# create interpolator
_alb_itp::Interpolator = Interpolator(_alb_w, _alb_a)

# use interpolator to fill band values
for i in 1:atmos.nbands
# evaluate at band centre, converting from m to nm
atmos.albedo_s_arr[i] = _alb_itp(0.5 * (atmos.bands_min[i] + atmos.bands_max[i]) * 1.0e9)
end

end

# pass albedos to socrates
fill!(atmos.bound.rho_alb, 0.0)
atmos.bound.rho_alb[1, SOCRATES.rad_pcf.ip_surf_alb_diff, :] .= atmos.albedo_s_arr

###########################################
# Number of profiles, and profile coordinates
Expand All @@ -1060,7 +1019,7 @@ module atmosphere
end

SOCRATES.allocate_control(atmos.control, atmos.spectrum)

if n_channel == 1
atmos.control.map_channel[1:atmos.spectrum.Basic.n_band] .= 1
elseif n_channel == atmos.spectrum.Basic.n_band
Expand Down Expand Up @@ -1215,7 +1174,6 @@ module atmosphere
atmos.control.i_cloud = SOCRATES.rad_pcf.ip_cloud_off # 5 (clear sky)
end

SOCRATES.allocate_cld( atmos.cld, atmos.dimen, atmos.spectrum)
SOCRATES.allocate_cld_prsc(atmos.cld, atmos.dimen, atmos.spectrum)

if atmos.control.l_cloud
Expand All @@ -1231,6 +1189,55 @@ module atmosphere

atmos.control.i_angular_integration = SOCRATES.rad_pcf.ip_two_stream

###########################################
# Surface properties
###########################################
atmos.albedo_s_arr = zeros(Float64, atmos.nbands)

# set array values
if atmos.surface_material == "blackbody"
# grey albedo
fill!(atmos.albedo_s_arr, atmos.albedo_s)

else
# spectral albedo

# try to find a matching file
atmos.surface_material = abspath(atmos.surface_material)
if !isfile(atmos.surface_material)
error("Could not find surface albedo file '$(atmos.surface_material)'")
end

# read data from file
_alb_data::Array = readdlm(atmos.surface_material, Float64)
_alb_w::Array{Float64, 1} = _alb_data[:,1] # wavelength [nm]
_alb_a::Array{Float64, 1} = _alb_data[:,2] # albedo [dimensionless]

# extrapolate to 0 wavelength, with constant value
pushfirst!(_alb_w, 0.0)
pushfirst!(_alb_a, _alb_a[1])

# extrapolate to large wavelength, with constant value
push!(_alb_w, 1e10)
push!(_alb_a, _alb_a[end])

# create interpolator
_alb_itp::Interpolator = Interpolator(_alb_w, _alb_a)

# use interpolator to fill band values
for i in 1:atmos.nbands
# evaluate at band centre, converting from m to nm
atmos.albedo_s_arr[i] = _alb_itp(0.5 * (atmos.bands_min[i] + atmos.bands_max[i]) * 1.0e9)
end

end

# pass albedos to socrates
fill!(atmos.bound.rho_alb, 0.0)
atmos.bound.rho_alb[1, SOCRATES.rad_pcf.ip_surf_alb_diff, :] .= 0.0
atmos.bound.rho_alb[1, SOCRATES.rad_pcf.ip_surf_alb_dir, :] .= atmos.albedo_s_arr


#######################################
# Output arrays
#######################################
Expand Down
12 changes: 5 additions & 7 deletions src/energy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ module energy
atmos.bound.solar_irrad[1] = atmos.instellation * (1.0 - atmos.albedo_b) * atmos.s0_fact
end

atmos.bound.rho_alb[:, atmosphere.SOCRATES.rad_pcf.ip_surf_alb_diff, :] .= atmos.albedo_s

# Set the two-stream approximation to be used (-t f)
if lw
atmos.control.i_2stream = atmosphere.SOCRATES.rad_pcf.ip_elsasser
Expand Down Expand Up @@ -122,11 +120,10 @@ module energy
# IP_surface_char = 51, file suffix 'surf'
#####################################

if atmos.control.i_angular_integration == atmosphere.SOCRATES.rad_pcf.ip_two_stream
if !lw
atmos.bound.rho_alb[:, atmosphere.SOCRATES.rad_pcf.ip_surf_alb_dir, :] .= atmos.bound.rho_alb[:, atmosphere.SOCRATES.rad_pcf.ip_surf_alb_diff, :]
end
end
# set albedos
fill!(atmos.bound.rho_alb, 0.0)
atmos.bound.rho_alb[1, atmosphere.SOCRATES.rad_pcf.ip_surf_alb_diff, :] .= atmos.albedo_s_arr
atmos.bound.rho_alb[1, atmosphere.SOCRATES.rad_pcf.ip_surf_alb_dir, :] .= atmos.albedo_s_arr

###################################################
# Cloud information
Expand Down Expand Up @@ -183,6 +180,7 @@ module energy
end
end


# Do radiative transfer
atmosphere.atmosphere.SOCRATES.radiance_calc(atmos.control, atmos.dimen, atmos.spectrum,
atmos.atm, atmos.cld, atmos.aer,
Expand Down

0 comments on commit 8dd3460

Please sign in to comment.