@@ -290,6 +290,7 @@ module atmosphere
290290 aerosol_arr_l:: Dict{String, Array{Float64,1}} # Aerosol mass mixing ratio profiles [kg/kg]
291291 aerosol_arr_r:: Dict{String, Array{Float64,1}} # Aerosol particle size profiles [m]
292292 aerosol_val_r:: Float64 # Default particle size for aerosol species, if not specified in array
293+ aerosol_setby:: Dict{String, String} # Dict of how each aerosol is set (e.g. "value", "S8", "H2O", etc.)
293294 aerosol_names:: Array{String,1} # Map SOCRATES index (int) to name (string)
294295 aerosol_relhumid:: Float64 # Mean relative humidity used by moist aerosol schemes [0,1]
295296 aerosol_phase_num:: Int # Number of phase-function moments retained when averaging
@@ -440,7 +441,7 @@ module atmosphere
440441 - `flag_gcontinuum::Bool` include generalised continuum absorption?
441442 - `flag_continuum::Bool` include continuum absorption?
442443 - `flag_aerosol::Bool` include aerosols?
443- - `aerosol_species::Dict` aerosols MMR values to initialise profile with
444+ - `aerosol_species::Dict` aerosols MMR values or associated condensates
444445 - `flag_cloud::Bool` include clouds?
445446 - `phs_timescale::Float64` phase change timescale [s]
446447 - `evap_efficiency::Float64` re-evaporatione efficiency compared to saturating amount
@@ -497,7 +498,7 @@ module atmosphere
497498 flag_continuum:: Bool = false ,
498499 flag_aerosol:: Bool = false ,
499500 flag_cloud:: Bool = false ,
500- aerosol_species:: Dict = Dict {String, Float64} (),
501+ aerosol_species:: Dict = Dict {String, Union{ Float64,String} } (),
501502
502503 phs_timescale:: Float64 = 1e6 ,
503504 evap_efficiency:: Float64 = 0.05 ,
@@ -807,16 +808,33 @@ module atmosphere
807808 atmos. aerosol_val_r = 1.0e-5 # [INPUT] default particle size for aerosol species
808809 atmos. aerosol_arr_l = Dict {String, Array{Float64,1}} () # list of MMR profiles
809810 atmos. aerosol_arr_r = Dict {String, Array{Float64,1}} () # list of particle size profiles
811+ atmos. aerosol_setby = Dict {String, String} () # dictionary of how each aerosol is set (e.g. "value", "S8", "H2O", etc.)
810812 atmos. aerosol_names = String[] # list of species names, in same order as spectral file
811813 for (k, v) in aerosol_species
814+
815+ # set to zero for now (true values will be set elsewhere)
812816 k = lowercase (k)
813- _check_range (" Aerosol mass mixing ratio override for type $k " , v; min= 0.0 ) || return false
814817 atmos. aerosol_arr_l[k] = zeros (Float64, atmos. nlev_c)
815818 atmos. aerosol_arr_r[k] = zeros (Float64, atmos. nlev_c)
816- set_aerosol ! (atmos,k , v)
819+ push ! (atmos. aerosol_names, UNSET_STR) # set in allocate!
817820
818- # Store empty strings for now (set in allocate! function)
819- push! (atmos. aerosol_names, UNSET_STR)
821+ # MMR profile tied to condensate or set by value?
822+ if isa (v, String)
823+ # interpret as condensate name
824+ if ! (v in condensates)
825+ @error " Aerosol '$k ' is tied to '$v ', but $v is not in the list of condensates"
826+ return false
827+ end
828+ @debug " Aerosol '$k ' to be associated with species '$v '"
829+ set_aerosol! (atmos, k, 0.0 )
830+ atmos. aerosol_setby[k] = v
831+ else
832+ # interpret as MMR value
833+ v = Float64 (v)
834+ _check_range (" Aerosol mass mixing ratio override for type $k " , v; min= 0.0 ) || return false
835+ set_aerosol! (atmos, k, v)
836+ atmos. aerosol_setby[k] = " value"
837+ end
820838 end
821839
822840 # Read VMRs
@@ -2819,6 +2837,25 @@ module atmosphere
28192837 return aerosol_names
28202838 end
28212839
2840+ """
2841+ **Calculate condensate mass mixing ratio at a specific layer.**
2842+
2843+ Arguments:
2844+ - `atmos::atmosphere.Atmos_t` atmosphere struct instance to be used.
2845+ - `c::String` condensate species to calculate for (e.g. "H2O")
2846+ - `i::Int` layer index
2847+
2848+ Returns:
2849+ - `cond_mmr::Float64` condensate `c` mass mixing ratio at layer `i`
2850+ """
2851+ function calc_cond_mmr (atmos:: atmosphere.Atmos_t , c:: String , i:: Int64 ):: Float64
2852+ if atmos. cond_yield[c][i] > 0.0
2853+ return atmos. cond_yield[c][i]* atmos. cloud_alpha / atmos. layer_σ[i]
2854+ else
2855+ return 0.0
2856+ end
2857+ end
2858+
28222859 """
28232860 **Set water cloud profile based on saturation.**
28242861
@@ -2841,8 +2878,7 @@ module atmosphere
28412878 # liquid water content (take ratio of mass surface densities [kg/m^2])
28422879 if from_yield
28432880 # set by condensation yield
2844- atmos. cloud_arr_l[i] = (atmos. cond_yield[" H2O" ][i]* atmos. cloud_alpha) /
2845- atmos. layer_σ[i]
2881+ atmos. cloud_arr_l[i] = calc_cond_mmr (atmos, " H2O" , i)
28462882 else
28472883 # set by mask
28482884 atmos. cloud_arr_l[i] = atmos. gas_sat[" H2O" ][i] ? atmos. cloud_val_l : 0.0
@@ -2864,27 +2900,37 @@ module atmosphere
28642900 end
28652901
28662902 """
2867- **Set aerosol profiles for a given species.**
2903+ **Set aerosol MMR profiles for a given species.**
28682904
28692905 Arguments:
28702906 - `atmos::atmosphere.Atmos_t` the atmosphere struct instance to be used
28712907 - `species::String` the name of the aerosol species to set
2872- - `mmr` the mixing ratio (profile or scalar) to set
2908+ - `mmr` the mixing ratio to assign (1D array, or Float, or species String)
28732909
28742910 Optional arguments
28752911 - `pmin::Float64` the minimum pressure [Pa]
28762912 - `pmax::Float64` the maximum pressure [Pa]
28772913
28782914 """
28792915 function set_aerosol! (atmos:: atmosphere.Atmos_t , species:: String ,
2880- mmr:: Union{Array{Float64, 1}, Float64} = 0.0 ;
2916+ mmr:: Union{Array{Float64, 1}, Float64, String } = 0.0 ;
28812917 pmin:: Float64 = 0.0 , pmax:: Float64 = 1e9 ):: Bool
28822918
2919+
2920+ # Reset
2921+ fill! (atmos. aerosol_arr_l[species], 0.0 )
2922+ fill! (atmos. aerosol_arr_r[species], 0.0 )
2923+
28832924 # Mask for pressure range
28842925 idx_mask = (atmos. p .>= pmin) .& (atmos. p .<= pmax)
28852926
28862927 # Set mixing ratio profile for aerosol
2887- if isa (mmr, Float64)
2928+ if isa (mmr, String)
2929+ # set by species mmr
2930+ for i in collect (1 : atmos. nlev_c)[idx_mask]
2931+ atmos. aerosol_arr_l[species][i] = atmosphere. calc_cond_mmr (atmos, mmr, i)
2932+ end
2933+ elseif isa (mmr, Float64)
28882934 # constant profile
28892935 atmos. aerosol_arr_l[species][idx_mask] .= mmr
28902936 else
0 commit comments