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

Eliminate duplicate universal_func_type and generalize parameter extractor functions #149

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ docs/site/
# environment.
Manifest.toml
test/Artifacts.toml

# vim temporary files
*.swp
*.swo
37 changes: 21 additions & 16 deletions src/Parameters.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
module Parameters

import Thermodynamics
import ..UniversalFunctions
import ..UniversalFunctions: universal_func_type

const TD = Thermodynamics
const TDPS = TD.Parameters.ThermodynamicsParameters
import ..UniversalFunctions

const UF = UniversalFunctions

abstract type AbstractSurfaceFluxesParameters end
const ASFP = AbstractSurfaceFluxesParameters

Base.broadcastable(ps::ASFP) = tuple(ps)

Base.@kwdef struct SurfaceFluxesParameters{FT, AUFPS <: UF.AbstractUniversalFunctionParameters{FT}, TP} <:
AbstractSurfaceFluxesParameters
const AUFP{FT} = UF.AbstractUniversalFunctionParameters{FT} where FT

Base.@kwdef struct SurfaceFluxesParameters{FT, U<:AUFP{FT}, TP} <: ASFP
von_karman_const::FT
ufp::AUFPS
ufp::U
thermo_params::TP
end

thermodynamics_params(ps::SurfaceFluxesParameters) = ps.thermo_params
uf_params(ps::SurfaceFluxesParameters) = ps.ufp
von_karman_const(ps::SurfaceFluxesParameters) = ps.von_karman_const

universal_func_type(::SurfaceFluxesParameters{FT, AUFPS}) where {FT, AUFPS} = UF.universal_func_type(AUFPS)
universal_func_type(::SurfaceFluxesParameters{FT, UFP}) where {FT, UFP} =
universal_func_type(UFP)

for var in fieldnames(TDPS)
@eval $var(ps::ASFP) = TD.Parameters.$var(thermodynamics_params(ps))
Expand All @@ -33,16 +38,16 @@
R_d(ps::ASFP) = TD.Parameters.R_d(thermodynamics_params(ps))
cp_d(ps::ASFP) = TD.Parameters.cp_d(thermodynamics_params(ps))

Pr_0(ps::SurfaceFluxesParameters) = Pr_0(uf_params(ps))
a_m(ps::SurfaceFluxesParameters) = a_m(uf_params(ps))
a_h(ps::SurfaceFluxesParameters) = a_h(uf_params(ps))
b_m(ps::SurfaceFluxesParameters) = b_m(uf_params(ps))
b_h(ps::SurfaceFluxesParameters) = b_h(uf_params(ps))
c_m(ps::SurfaceFluxesParameters) = c_m(uf_params(ps))
c_h(ps::SurfaceFluxesParameters) = c_h(uf_params(ps))
d_m(ps::SurfaceFluxesParameters) = d_m(uf_params(ps))
d_h(ps::SurfaceFluxesParameters) = d_h(uf_params(ps))
ζ_a(ps::SurfaceFluxesParameters) = ζ_a(uf_params(ps))
γ(ps::SurfaceFluxesParameters) = γ(uf_params(ps))
Pr_0(ps::ASFP) = Pr_0(uf_params(ps))
a_m(ps::ASFP) = a_m(uf_params(ps))
a_h(ps::ASFP) = a_h(uf_params(ps))
b_m(ps::ASFP) = b_m(uf_params(ps))
b_h(ps::ASFP) = b_h(uf_params(ps))
c_m(ps::ASFP) = c_m(uf_params(ps))
c_h(ps::ASFP) = c_h(uf_params(ps))
d_m(ps::ASFP) = d_m(uf_params(ps))
d_h(ps::ASFP) = d_h(uf_params(ps))
ζ_a(ps::ASFP) = ζ_a(uf_params(ps))
γ(ps::ASFP) = γ(uf_params(ps))

Check warning on line 51 in src/Parameters.jl

View check run for this annotation

Codecov / codecov/patch

src/Parameters.jl#L41-L51

Added lines #L41 - L51 were not covered by tests

end
1 change: 0 additions & 1 deletion src/SurfaceFluxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""
module SurfaceFluxes


import RootSolvers
const RS = RootSolvers

Expand Down
Loading