Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add promoting constructors for Dual number support #199

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/relations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,8 @@
p_v_sat = saturation_vapor_pressure(param_set, T, phase)
return q_vap_saturation_from_density(param_set, T, ρ, p_v_sat)
end
q_vap_saturation_generic(param_set::APS, T, ρ, phase::Phase) =

Check warning on line 1039 in src/relations.jl

View check run for this annotation

Codecov / codecov/patch

src/relations.jl#L1039

Added line #L1039 was not covered by tests
q_vap_saturation_generic(param_set, promote(T, ρ)..., phase)

"""
q_vap_saturation(param_set, T, ρ, phase_type[, q::PhasePartition])
Expand Down
48 changes: 48 additions & 0 deletions src/states.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
@inline PhasePartition(q_tot::FT) where {FT <: Real} =
PhasePartition(q_tot, zero(FT), zero(FT))

function promote_phase_partition(x1, x2, q_pt::PhasePartition)
(x1, x2, tot, liq, ice) = promote(x1, x2, q_pt.tot, q_pt.liq, q_pt.tot)
return (x1, x2, PhasePartition(tot, liq, ice))

Check warning on line 88 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L86-L88

Added lines #L86 - L88 were not covered by tests
end

const ITERTYPE = Union{Int, Nothing}
TOLTYPE(FT) = Union{FT, Nothing}

Expand Down Expand Up @@ -126,6 +131,8 @@
"""
PhaseDry_ρe(param_set::APS, ρ::FT, e_int::FT) where {FT} =
PhaseDry{FT}(e_int, ρ)
PhaseDry_ρe(param_set::APS, ρ, e_int) =

Check warning on line 134 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L134

Added line #L134 was not covered by tests
PhaseDry_ρe(param_set, promote(ρ, e_int)...)

"""
PhaseDry_pT(param_set, p, T)
Expand All @@ -141,6 +148,7 @@
ρ = air_density(param_set, T, p)
return PhaseDry{FT}(e_int, ρ)
end
PhaseDry_pT(param_set::APS, p, T) = PhaseDry_pT(param_set, promote(p, T)...)

Check warning on line 151 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L151

Added line #L151 was not covered by tests

"""
PhaseDry_pe(param_set, p, e_int)
Expand All @@ -160,6 +168,8 @@
ρ = air_density(param_set, T, p)
return PhaseDry{FT}(e_int, ρ)
end
PhaseDry_pe(param_set::APS, p, e_int) =

Check warning on line 171 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L171

Added line #L171 was not covered by tests
PhaseDry_pe(param_set, promote(p, e_int)...)

"""
PhaseDry_ph(param_set, p, h)
Expand All @@ -176,6 +186,7 @@
e_int = internal_energy(param_set, T)
return PhaseDry{FT}(e_int, ρ)
end
PhaseDry_ph(param_set::APS, p, h) = PhaseDry_ph(param_set, promote(p, h)...)

Check warning on line 189 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L189

Added line #L189 was not covered by tests

"""
PhaseDry_ρθ(param_set, ρ, θ_dry)
Expand All @@ -195,6 +206,8 @@
e_int = internal_energy(param_set, T)
return PhaseDry{FT}(e_int, ρ)
end
PhaseDry_ρθ(param_set::APS, ρ, θ_dry) =

Check warning on line 209 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L209

Added line #L209 was not covered by tests
PhaseDry_ρθ(param_set, promote(ρ, θ_dry)...)

"""
PhaseDry_pθ(param_set, p, θ_dry)
Expand All @@ -215,6 +228,8 @@
ρ = air_density(param_set, T, p)
return PhaseDry{FT}(e_int, ρ)
end
PhaseDry_pθ(param_set::APS, p, θ_dry) =

Check warning on line 231 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L231

Added line #L231 was not covered by tests
PhaseDry_pθ(param_set, promote(p, θ_dry)...)

"""
PhaseDry_ρT(param_set, ρ, T)
Expand All @@ -229,6 +244,8 @@
e_int = internal_energy(param_set, T)
return PhaseDry{FT}(e_int, ρ)
end
PhaseDry_ρT(param_set::APS, ρ, θ_dry) =

Check warning on line 247 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L247

Added line #L247 was not covered by tests
PhaseDry_ρT(param_set, promote(ρ, θ_dry)...)

"""
PhaseDry_ρp(param_set, ρ, p)
Expand All @@ -244,6 +261,7 @@
e_int = internal_energy(param_set, T)
return PhaseDry{FT}(e_int, ρ)
end
PhaseDry_ρp(param_set::APS, ρ, p) = PhaseDry_ρp(param_set, promote(ρ, p)...)

Check warning on line 264 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L264

Added line #L264 was not covered by tests

#####
##### Equilibrium states
Expand Down Expand Up @@ -327,6 +345,8 @@
p = air_pressure(param_set, T, ρ, q_pt)
return PhaseEquil{FT}(ρ, p, e_int, q_tot_safe, T)
end
PhaseEquil_ρeq(param_set::APS, ρ, e_int, q_tot, args...) =

Check warning on line 348 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L348

Added line #L348 was not covered by tests
PhaseEquil_ρeq(param_set, promote(ρ, e_int, q_tot)..., args...)

# Convenience method for comparing Numerical
# methods without having to specify maxiter
Expand Down Expand Up @@ -394,6 +414,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseEquil{FT}(ρ, p, e_int, q_tot, T)
end
PhaseEquil_ρθq(param_set::APS, ρ, θ_liq_ice, q_tot, args...) =

Check warning on line 417 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L417

Added line #L417 was not covered by tests
PhaseEquil_ρθq(param_set, promote(ρ, θ_liq_ice, q_tot)..., args...)

"""
PhaseEquil_ρTq(param_set, ρ, T, q_tot)
Expand All @@ -417,6 +439,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseEquil{FT}(ρ, p, e_int, q_tot, T)
end
PhaseEquil_ρTq(param_set::APS, ρ, T, q_tot) =

Check warning on line 442 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L442

Added line #L442 was not covered by tests
PhaseEquil_ρTq(param_set, promote(ρ, T, q_tot)...)

"""
PhaseEquil_pTq(param_set, p, T, q_tot)
Expand All @@ -441,6 +465,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseEquil{FT}(ρ, p, e_int, q_tot_safe, T)
end
PhaseEquil_pTq(param_set::APS, p, T, q_tot) =

Check warning on line 468 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L468

Added line #L468 was not covered by tests
PhaseEquil_pTq(param_set, promote(p, T, q_tot)...)

"""
PhaseEquil_peq(param_set, p, e_int, q_tot[, maxiter, relative_temperature_tol, sat_adjust_method, T_guess])
Expand Down Expand Up @@ -483,6 +509,8 @@
ρ = air_density(param_set, T, p, q_pt)
return PhaseEquil{FT}(ρ, p, e_int, q_tot_safe, T)
end
PhaseEquil_peq(param_set::APS, p, e_int, q_tot, args...) =

Check warning on line 512 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L512

Added line #L512 was not covered by tests
PhaseEquil_peq(param_set, promote(p, e_int, q_tot)..., args...)


"""
Expand Down Expand Up @@ -527,6 +555,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseEquil{FT}(ρ, p, e_int, q_tot_safe, T)
end
PhaseEquil_phq(param_set::APS, p, h, q_tot, args...) =

Check warning on line 558 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L558

Added line #L558 was not covered by tests
PhaseEquil_phq(param_set, promote(p, h, q_tot)..., args...)

"""
PhaseEquil_ρpq(param_set, ρ, p, q_tot[, perform_sat_adjust=true, maxiter, sat_adjust_method, T_guess])
Expand Down Expand Up @@ -581,6 +611,8 @@
end
return PhaseEquil{FT}(ρ, p, e_int, q_tot, T)
end
PhaseEquil_ρpq(param_set::APS, ρ, p, q_tot, args...) =

Check warning on line 614 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L614

Added line #L614 was not covered by tests
PhaseEquil_ρpq(param_set, promote(ρ, p, q_tot)..., args...)


"""
Expand Down Expand Up @@ -628,6 +660,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseEquil{FT}(ρ, p, e_int, q_tot_safe, T)
end
PhaseEquil_pθq(param_set::APS, p, θ_liq_ice, q_tot, args...) =

Check warning on line 663 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L663

Added line #L663 was not covered by tests
PhaseEquil_pθq(param_set, promote(p, θ_liq_ice, q_tot)..., args...)


#####
Expand Down Expand Up @@ -688,6 +722,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseNonEquil{FT}(e_int, ρ, q_pt)
end
PhaseNonEquil_ρTq(param_set::APS, ρ, T, q_pt) =

Check warning on line 725 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L725

Added line #L725 was not covered by tests
PhaseNonEquil_ρTq(param_set, promote_phase_partition(ρ, T, q_pt)...)

"""
PhaseNonEquil_ρθq(param_set, ρ, θ_liq_ice, q_pt)
Expand Down Expand Up @@ -723,6 +759,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseNonEquil{FT}(e_int, ρ, q_pt)
end
PhaseNonEquil_ρθq(param_set::APS, ρ, θ_liq_ice, q_pt) =

Check warning on line 762 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L762

Added line #L762 was not covered by tests
PhaseNonEquil_ρθq(param_set, promote_phase_partition(ρ, θ_liq_ice, q_pt)...)

"""
PhaseNonEquil_pθq(param_set, p, θ_liq_ice, q_pt)
Expand All @@ -745,6 +783,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseNonEquil{FT}(e_int, ρ, q_pt)
end
PhaseNonEquil_pθq(param_set::APS, p, θ_liq_ice, q_pt) =

Check warning on line 786 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L786

Added line #L786 was not covered by tests
PhaseNonEquil_pθq(param_set, promote_phase_partition(p, θ_liq_ice, q_pt)...)

"""
PhaseNonEquil_pTq(param_set, p, T, q_pt)
Expand All @@ -766,6 +806,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseNonEquil{FT}(e_int, ρ, q_pt)
end
PhaseNonEquil_pTq(param_set::APS, p, T, q_pt) =

Check warning on line 809 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L809

Added line #L809 was not covered by tests
PhaseNonEquil_pTq(param_set, promote_phase_partition(p, T, q_pt)...)

"""
PhaseNonEquil_peq(param_set, p, e_int, q_pt)
Expand All @@ -787,6 +829,8 @@
ρ = air_density(param_set, T, p, q_pt)
return PhaseNonEquil{FT}(e_int, ρ, q_pt)
end
PhaseNonEquil_peq(param_set::APS, p, e_int, q_pt) =

Check warning on line 832 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L832

Added line #L832 was not covered by tests
PhaseNonEquil_peq(param_set, promote_phase_partition(p, e_int, q_pt)...)

"""
PhaseNonEquil_phq(param_set, p, e_int, q_pt)
Expand All @@ -809,6 +853,8 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseNonEquil{FT}(e_int, ρ, q_pt)
end
PhaseNonEquil_phq(param_set::APS, p, h, q_pt) =

Check warning on line 856 in src/states.jl

View check run for this annotation

Codecov / codecov/patch

src/states.jl#L856

Added line #L856 was not covered by tests
PhaseNonEquil_phq(param_set, promote_phase_partition(p, h, q_pt)...)

"""
PhaseNonEquil_ρpq(param_set, ρ, p, q_pt)
Expand All @@ -830,3 +876,5 @@
e_int = internal_energy(param_set, T, q_pt)
return PhaseNonEquil{FT}(e_int, ρ, q_pt)
end
PhaseNonEquil_ρpq(param_set::APS, ρ, p, q_pt) =
PhaseNonEquil_ρpq(param_set, promote_phase_partition(ρ, p, q_pt)...)
Loading