From 08af17a82c6e53ba1db9c113436f415a959159f9 Mon Sep 17 00:00:00 2001 From: Harrison Nicholls Date: Thu, 4 Jul 2024 20:24:34 +0100 Subject: [PATCH] Docs and tests --- res/config/55cnce_chem.toml | 3 +-- res/config/default.toml | 2 +- src/atmosphere.jl | 11 ++------ src/energy.jl | 9 +++---- test/runtests.jl | 51 ++++++++++++++++++++++++++++--------- 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/res/config/55cnce_chem.toml b/res/config/55cnce_chem.toml index 63ed4d25..67357692 100644 --- a/res/config/55cnce_chem.toml +++ b/res/config/55cnce_chem.toml @@ -21,8 +21,7 @@ title = "Roughly 55 Cancri e @ fO2=IW" [composition] p_top = 1e-7 - # p_dict = { H2O=0.206, CO2=14.184, N2 =16.303, H2 =0.462, CO =211.539 } - p_dict = {H2O = 0.308,CO2 = 15.516,N2 = 16.065,H2 = 0.691,CO = 231.415 } + p_dict = {H2O = 0.308,CO2 = 15.516,N2 = 16.065,H2 = 0.691,CO = 231.415 } include_all = true chemistry = 1 condensates = [] diff --git a/res/config/default.toml b/res/config/default.toml index 90caeddd..8c7d0b8f 100644 --- a/res/config/default.toml +++ b/res/config/default.toml @@ -11,7 +11,7 @@ title = "Default" # Name for this configuration file 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= "blackbody" # Surface material (can be "blackbody" or path to data file). - albedo_s = 0.12 # Grey surface albedo when material=blackbody. + albedo_s = 0.3 # 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] skin_d = 0.01 # Conductive skin thickness [m]. Used when sol_type=2. diff --git a/src/atmosphere.jl b/src/atmosphere.jl index 74c32c13..949b3108 100644 --- a/src/atmosphere.jl +++ b/src/atmosphere.jl @@ -1125,8 +1125,8 @@ module atmosphere end - # Calc layer properties using initial temperature profile - # Can generate weird issues since the TOA temperature can be large + # Calc layer properties using initial temperature profile. + # Can generate weird issues since the TOA temperature may be large # large but pressure small, which gives it a low density. With the # hydrostatic integrator, this can cause dz to blow up, especially # with a low MMW gas. Should be okay as long as the T(p) provided @@ -1194,7 +1194,6 @@ module atmosphere ########################################### 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) @@ -1232,12 +1231,6 @@ module atmosphere 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 f956482f..0c486f3f 100644 --- a/src/energy.jl +++ b/src/energy.jl @@ -66,8 +66,8 @@ module energy # Downward SW flux at TOA atmos.toa_heating = atmos.instellation * (1.0 - atmos.albedo_b) * atmos.s0_fact * cosd(atmos.zenith_degrees) - # SOCRATES requires this to be passed as two variables, since it needs to know - # the zenith angle of the direct beam. + # SOCRATES requires this to be passed as two variables, since it + # needs to know the angle of the direct beam. atmos.bound.zen_0[1] = 1.0/cosd(atmos.zenith_degrees) # Convert the zenith angles to secants. atmos.bound.solar_irrad[1] = atmos.instellation * (1.0 - atmos.albedo_b) * atmos.s0_fact end @@ -123,7 +123,7 @@ module energy # 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 + atmos.bound.rho_alb[1, atmosphere.SOCRATES.rad_pcf.ip_surf_alb_dir, :] .= atmos.albedo_s_arr ################################################### # Cloud information @@ -280,6 +280,7 @@ module energy return nothing end + # Calculate conductive fluxes function conduct!(atmos::atmosphere.Atmos_t) # top layer @@ -296,8 +297,6 @@ module energy end - - """ **Calculate dry convective fluxes using mixing length theory.** diff --git a/test/runtests.jl b/test/runtests.jl index 02388ff9..462a4cc2 100755 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -62,6 +62,7 @@ else @warn "Fail" passing = false end +@info "--------------------------" @@ -72,9 +73,9 @@ end @info " " @info "Testing composition" -tmp_surf = 200.0 # Surface temperature [kelvin] -toa_heating = 1000.00 # Instellation flux [W m-2] -p_surf = 50.0 # bar +tmp_surf = 200.0 # Surface temperature [kelvin] +toa_heating = 10000.00 # Instellation flux [W m-2] +p_surf = 1.0 # bar theta = 65.0 mf_dict = Dict([ ("H2O" , 0.5), @@ -112,7 +113,7 @@ else passing = false end atmosphere.deallocate!(atmos) - +@info "--------------------------" @@ -123,7 +124,7 @@ atmosphere.deallocate!(atmos) @info " " @info "Testing instellation" -tmp_surf = 200.0 # Surface temperature [kelvin] +tmp_surf = 200.0 # Surface temperature [kelvin] toa_heating = 1000.00 # Instellation flux [W m-2] p_surf = 50.0 # bar theta = 65.0 @@ -178,6 +179,9 @@ else passing = false end atmosphere.deallocate!(atmos) +@info "--------------------------" + + # ------------- # Test greenhouse effect @@ -206,16 +210,18 @@ atmosphere.setup!(atmos, ROOT_DIR, output_dir, flag_gcontinuum=true, flag_rayleigh=false, overlap_method=4, - condensates=["H2O"] + condensates=["H2O"], + surface_material="blackbody", + albedo_s=0.5 ) atmosphere.allocate!(atmos,joinpath(ROOT_DIR,"res/stellar_spectra/sun.txt")) setpt.prevent_surfsupersat!(atmos) setpt.dry_adiabat!(atmos) setpt.saturation!(atmos, "H2O") atmosphere.calc_layer_props!(atmos) -energy.radtrans!(atmos, true) +energy.radtrans!(atmos, true) # LW only -val_e = [270.0, 290.0] +val_e = [270.0, 280.0] val_o = atmos.flux_u_lw[1] @info "Expected range = $(val_e) W m-2" @info "Modelled value = $(val_o) W m-2" @@ -225,8 +231,29 @@ else @warn "Fail" passing = false end -atmosphere.deallocate!(atmos) +@info "--------------------------" + + +# ------------- +# Test surface albedo +# ------------- +@info " " +@info "Testing surface albedo " +energy.radtrans!(atmos, false) # SW only + +val_e = [20.0, 40.0] # known from previous tests +val_o = atmos.flux_u_sw[end] # bottom level +@info "Expected range = $(val_e) W m-2" +@info "Modelled value = $(val_o) W m-2" +if ( val_o > val_e[1]) && (val_o < val_e[2]) + @info "Pass" +else + @warn "Fail" + passing = false +end +atmosphere.deallocate!(atmos) +@info "--------------------------" # ------------- @@ -273,8 +300,7 @@ else passing = false end atmosphere.deallocate!(atmos) - - +@info "--------------------------" # ------------- @@ -283,7 +309,7 @@ atmosphere.deallocate!(atmos) @info " " @info "Testing heating rates" -tmp_surf = 2500.0 # Surface temperature [kelvin] +tmp_surf = 2500.0 # Surface temperature [kelvin] toa_heating = 1000.0 # Instellation flux [W m-2] p_surf = 5.0 # bar theta = 45.0 @@ -325,6 +351,7 @@ else passing = false end atmosphere.deallocate!(atmos) +@info "--------------------------" # -------------