Skip to content

Commit

Permalink
Made ls_increase a parameter to solver function. Other minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nichollsh committed Aug 2, 2024
1 parent 11cba8a commit 470384e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/AGNI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module AGNI

# Setup file logger
if to_file
logger_file = FormatLogger(outpath; append=true) do io, args
logger_file = FormatLogger(outpath; append=false) do io, args
if args.level == LoggingExtras.Info
level = "INFO"
elseif args.level == LoggingExtras.Warn
Expand Down
7 changes: 4 additions & 3 deletions src/atmosphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ module atmosphere
- `mf_path::String` path to file containing VMRs at each level.
Optional arguments:
- `condensates::Array{String,1}` list of condensates (gas names).
- `condensates` list of condensates (gas names).
- `surface_material::String` surface material (default is "blackbody", but can point to file instead).
- `albedo_s::Float64` grey surface albedo used when `surface_material="blackbody"`.
- `tmp_floor::Float64` temperature floor [K].
Expand Down Expand Up @@ -285,9 +285,9 @@ module atmosphere
zenith_degrees::Float64, tmp_surf::Float64,
gravity::Float64, radius::Float64,
nlev_centre::Int, p_surf::Float64, p_top::Float64,
mf_dict::Dict{String, Float64}, mf_path::String;
mf_dict, mf_path::String;

condensates::Array{String,1} = String[],
condensates = String[],
surface_material::String = "blackbody",
albedo_s::Float64 = 0.0,
tmp_floor::Float64 = 2.0,
Expand Down Expand Up @@ -925,6 +925,7 @@ module atmosphere
# Setup spectral file
socstar::String = ""
if !isempty(stellar_spectrum)
@debug "Inserting stellar spectrum"

if !isfile(stellar_spectrum)
@error "Stellar spectrum file '$(stellar_spectrum)' does not exist"
Expand Down
2 changes: 1 addition & 1 deletion src/energy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ module energy
- `pmin::Float64` pressure [bar] below which convection is disabled
- `mltype::Int` mixing length value (1: scale height, 2: asymptotic)
"""
function mlt!(atmos::atmosphere.Atmos_t; pmin::Float64=1.0e-9, mltype::Int=2)
function mlt!(atmos::atmosphere.Atmos_t; pmin::Float64=1.0e-4, mltype::Int=2)

pmin *= 1.0e5 # convert bar to Pa

Expand Down
14 changes: 7 additions & 7 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,21 @@ module plotting

# LW component
if atmos.is_out_lw
plot!(plt, _symlog.(-1.0*atmos.flux_d_lw), arr_P, lw=w, lc=col_r, ls=:dash, linealpha=alpha)
plot!(plt, _symlog.( atmos.flux_u_lw), arr_P, lw=w, lc=col_r, ls=:dash, linealpha=alpha)
plot!(plt, _symlog.(-1.0*atmos.flux_d_lw), arr_P, lw=w, lc=col_r, ls=:dash, linealpha=alpha)
plot!(plt, _symlog.( atmos.flux_u_lw), arr_P, lw=w, lc=col_r, ls=:dash, linealpha=alpha)
end

# SW component
if atmos.is_out_sw
plot!(plt, _symlog.(-1.0.*atmos.flux_d_sw), arr_P, lw=w, lc=col_r, ls=:dot, linealpha=alpha)
plot!(plt, _symlog.( atmos.flux_u_sw), arr_P, lw=w, lc=col_r, ls=:dot, linealpha=alpha)
plot!(plt, _symlog.(-1.0.*atmos.flux_d_sw), arr_P, lw=w, lc=col_r, ls=:dot, linealpha=alpha)
plot!(plt, _symlog.( atmos.flux_u_sw), arr_P, lw=w, lc=col_r, ls=:dot, linealpha=alpha)
end

# Net radiative fluxes
if atmos.is_out_lw && atmos.is_out_sw
plot!(plt, _symlog.( atmos.flux_u), arr_P, lw=w, lc=col_r, ls=:solid, linealpha=alpha)
plot!(plt, _symlog.(-1.0.*atmos.flux_d), arr_P, lw=w, lc=col_r, ls=:solid, linealpha=alpha)
plot!(plt, _symlog.( atmos.flux_n), arr_P, lw=w, lc=col_n, ls=:solid, linealpha=alpha)
plot!(plt, _symlog.( atmos.flux_u), arr_P, lw=w, lc=col_r, ls=:solid, linealpha=alpha)
plot!(plt, _symlog.(-1.0.*atmos.flux_d), arr_P, lw=w, lc=col_r, ls=:solid, linealpha=alpha)
plot!(plt, _symlog.( atmos.flux_n), arr_P, lw=w, lc=col_n, ls=:solid, linealpha=alpha)
end

# Convective flux (MLT)
Expand Down
13 changes: 7 additions & 6 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ module solver
- `ls_method::Int` linesearch algorithm (0: None, 1: golden, 2: backtracking)
- `easy_start::Bool` improve convergence by introducing convection and phase change gradually
- `perturb_all::Bool` always recalculate entire Jacobian matrix? Otherwise updates columns only as required
- `ls_increase::Bool` factor by which the cost can increase from last step before triggering linesearch
- `detect_plateau::Bool` assist solver when it is stuck in a region of small dF/dT
- `modplot::Int` iteration frequency at which to make plots
- `save_frames::Bool` save plotting frames
Expand All @@ -107,6 +108,7 @@ module solver
max_steps::Int=400, max_runtime::Float64=900.0,
fdw::Float64=3.0e-5, fdc::Bool=true, fdo::Int=2,
method::Int=1, ls_method::Int=1, easy_start::Bool=false,
ls_increase::Float64=1.08,
detect_plateau::Bool=true, perturb_all::Bool=false,
modplot::Int=1, save_frames::Bool=true,
modprint::Int=1, plot_jacobian::Bool=false,
Expand Down Expand Up @@ -139,7 +141,7 @@ module solver
tmp_pad::Float64 = 10.0 # do not allow the solver to get closer than this to tmp_floor

# easy_start
easy_incr::Float64 = 1.7 # Factor by which to increase easy_sf at each step
easy_incr::Float64 = 2.0 # Factor by which to increase easy_sf at each step
easy_trig::Float64 = 0.1 # Increase sf when cost*easy_trig satisfies convergence

# finite difference
Expand All @@ -150,7 +152,6 @@ module solver

# linesearch
ls_tau::Float64 = 0.7 # backtracking downscale size
ls_increase::Float64 = 1.2 # factor by which cost can increase
ls_max_steps::Int = 20 # maximum steps
ls_min_scale::Float64 = 1.0e-5 # minimum scale

Expand Down Expand Up @@ -560,8 +561,8 @@ module solver
fill!(perturb, true)
for i in 3:arr_len-4
perturb[i] = (sum(abs.(r_cur[i-2:i+2])) > perturb_crit) ||
any(atmos.mask_l[i-1:i+1]) ||
any(atmos.mask_c[i-1:i+1])
any(atmos.mask_l[i-2:i+2]) ||
any(atmos.mask_c[i-2:i+2])
end
end

Expand Down Expand Up @@ -659,8 +660,8 @@ module solver

# Yes, we do need to do linesearch...
stepflags *= "Ls-"
if ls_method == 1

if (ls_method == 1) || (ls_cost*0.1 < conv_atol + conv_rtol * c_max)
# Use golden-section search method
ls_alpha = gs_search(_ls_func, ls_min_scale, ls_alpha,
1.0e-9, ls_min_scale, ls_max_steps)
Expand Down

0 comments on commit 470384e

Please sign in to comment.