This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1869: Make swapping sat adjust numerical methods easier r=charleskawczynski a=charleskawczynski ### Description This PR is a step towards fixing #1831 by using the numerical method type, rather than a function, as an input to `saturation_adjustment`. This should help us more rigorously test/compare the performance and robustness of numerical methods in saturation adjustment for `ρ, e_int, q_tot` and `ρ, p, q_tot` thermo variables, which are the only two cases that are potentially used beyond initialization. I've also battled the formatter a bit in the `@print` statements, and added a test section for performance with BenchmarkTools. This also adds a convenience method, `PhaseEquil_dev_only`, _for development only_ so that we can more easily toggle one option at a time while maintaining synchronization with all other arguments. Co-authored-by: Charles Kawczynski <[email protected]>
- Loading branch information
Showing
7 changed files
with
280 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# These functions (variants of sa_numerical_method) | ||
# return an instance of a numerical method to solve | ||
# saturation adjustment, for different combinations | ||
# of thermodynamic variable inputs. | ||
|
||
##### | ||
##### Thermodynamic variable inputs: ρ, e_int, q_tot | ||
##### | ||
function sa_numerical_method( | ||
::Type{NM}, | ||
param_set::APS, | ||
ρ::FT, | ||
e_int::FT, | ||
q_tot::FT, | ||
phase_type::Type{<:PhaseEquil}, | ||
) where {FT, NM <: NewtonsMethod} | ||
_T_min::FT = T_min(param_set) | ||
T_init = | ||
max(_T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor | ||
return NewtonsMethod( | ||
T_init, | ||
T_ -> ∂e_int_∂T(param_set, heavisided(T_), e_int, ρ, q_tot, phase_type), | ||
) | ||
end | ||
|
||
function sa_numerical_method( | ||
::Type{NM}, | ||
param_set::APS, | ||
ρ::FT, | ||
e_int::FT, | ||
q_tot::FT, | ||
phase_type::Type{<:PhaseEquil}, | ||
) where {FT, NM <: NewtonsMethodAD} | ||
_T_min::FT = T_min(param_set) | ||
T_init = | ||
max(_T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor | ||
return NewtonsMethodAD(T_init) | ||
end | ||
|
||
function sa_numerical_method( | ||
::Type{NM}, | ||
param_set::APS, | ||
ρ::FT, | ||
e_int::FT, | ||
q_tot::FT, | ||
phase_type::Type{<:PhaseEquil}, | ||
) where {FT, NM <: SecantMethod} | ||
_T_min::FT = T_min(param_set) | ||
q_pt = PhasePartition(q_tot, FT(0), q_tot) # Assume all ice | ||
T_2 = air_temperature(param_set, e_int, q_pt) | ||
T_1 = max(_T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor | ||
T_2 = bound_upper_temperature(T_1, T_2) | ||
return SecantMethod(T_1, T_2) | ||
end | ||
|
||
function sa_numerical_method( | ||
::Type{NM}, | ||
param_set::APS, | ||
ρ::FT, | ||
e_int::FT, | ||
q_tot::FT, | ||
phase_type::Type{<:PhaseEquil}, | ||
) where {FT, NM <: RegulaFalsiMethod} | ||
_T_min::FT = T_min(param_set) | ||
q_pt = PhasePartition(q_tot, FT(0), q_tot) # Assume all ice | ||
T_2 = air_temperature(param_set, e_int, q_pt) | ||
T_1 = max(_T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor | ||
T_2 = bound_upper_temperature(T_1, T_2) | ||
return RegulaFalsiMethod(T_1, T_2) | ||
end | ||
|
||
##### | ||
##### Thermodynamic variable inputs: ρ, p, q_tot | ||
##### | ||
|
||
function sa_numerical_method_ρpq( | ||
::Type{NM}, | ||
param_set::APS, | ||
ρ::FT, | ||
p::FT, | ||
q_tot::FT, | ||
phase_type::Type{<:PhaseEquil}, | ||
) where {FT, NM <: NewtonsMethodAD} | ||
q_pt = PhasePartition(q_tot) | ||
T_init = air_temperature_from_ideal_gas_law(param_set, p, ρ, q_pt) | ||
return NewtonsMethodAD(T_init) | ||
end |
Oops, something went wrong.