Skip to content

Commit

Permalink
Docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nichollsh committed Jul 4, 2024
1 parent 8dd3460 commit 08af17a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
3 changes: 1 addition & 2 deletions res/config/55cnce_chem.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion res/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 2 additions & 9 deletions src/atmosphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
#######################################
Expand Down
9 changes: 4 additions & 5 deletions src/energy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -280,6 +280,7 @@ module energy
return nothing
end


# Calculate conductive fluxes
function conduct!(atmos::atmosphere.Atmos_t)
# top layer
Expand All @@ -296,8 +297,6 @@ module energy
end




"""
**Calculate dry convective fluxes using mixing length theory.**
Expand Down
51 changes: 39 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ else
@warn "Fail"
passing = false
end
@info "--------------------------"



Expand All @@ -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),
Expand Down Expand Up @@ -112,7 +113,7 @@ else
passing = false
end
atmosphere.deallocate!(atmos)

@info "--------------------------"



Expand All @@ -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
Expand Down Expand Up @@ -178,6 +179,9 @@ else
passing = false
end
atmosphere.deallocate!(atmos)
@info "--------------------------"



# -------------
# Test greenhouse effect
Expand Down Expand Up @@ -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"
Expand All @@ -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 "--------------------------"


# -------------
Expand Down Expand Up @@ -273,8 +300,7 @@ else
passing = false
end
atmosphere.deallocate!(atmos)


@info "--------------------------"


# -------------
Expand All @@ -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
Expand Down Expand Up @@ -325,6 +351,7 @@ else
passing = false
end
atmosphere.deallocate!(atmos)
@info "--------------------------"


# -------------
Expand Down

0 comments on commit 08af17a

Please sign in to comment.