From 8dd34601c17ec6d28ba617331698d715f7468f4e Mon Sep 17 00:00:00 2001 From: Harrison Nicholls Date: Thu, 4 Jul 2024 20:06:56 +0100 Subject: [PATCH] Surface albedo fixed --- README.md | 8 ++-- res/config/default.toml | 4 +- src/atmosphere.jl | 101 +++++++++++++++++++++------------------- src/energy.jl | 12 ++--- 4 files changed, 66 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index ab200c25..94afd624 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/res/config/default.toml b/res/config/default.toml index cdaa3934..90caeddd 100644 --- a/res/config/default.toml +++ b/res/config/default.toml @@ -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] @@ -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] diff --git a/src/atmosphere.jl b/src/atmosphere.jl index 832f3023..74c32c13 100644 --- a/src/atmosphere.jl +++ b/src/atmosphere.jl @@ -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 @@ -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 @@ -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 @@ -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 ####################################### diff --git a/src/energy.jl b/src/energy.jl index ce2f3130..f956482f 100644 --- a/src/energy.jl +++ b/src/energy.jl @@ -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 @@ -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 @@ -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,