Skip to content

Commit

Permalink
Merge pull request #152 from CliMA/ne/update_cp
Browse files Browse the repository at this point in the history
Move parameter constructor to a package extension, use name maps
  • Loading branch information
nefrathenrici authored Jan 20, 2024
2 parents b60ffa4 + 378af12 commit 90343fb
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 398 deletions.
12 changes: 9 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
name = "SurfaceFluxes"
uuid = "49b00bb7-8bd4-4f2b-b78c-51cd0450215f"
authors = ["Climate Modeling Alliance"]
version = "0.8.1"
version = "0.9.0"

[deps]
CLIMAParameters = "6eacf6c3-8458-43b9-ae03-caf5306d3d53"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
RootSolvers = "7181ea78-2dcb-4de3-ab41-2b8ab5a31e74"
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
CLIMAParameters = "6eacf6c3-8458-43b9-ae03-caf5306d3d53"

[weakdeps]
CLIMAParameters = "6eacf6c3-8458-43b9-ae03-caf5306d3d53"

[extensions]
CreateParametersExt = "CLIMAParameters"

[compat]
CLIMAParameters = "0.7"
CLIMAParameters = "0.8"
DocStringExtensions = "0.8, 0.9"
RootSolvers = "0.2, 0.3, 0.4"
Thermodynamics = "0.11"
Expand Down
26 changes: 26 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ SurfaceFluxes.surface_conditions
SurfaceFluxes.recover_profile
```

# Parameters
Convenience constructors are provided for the `SurfaceFluxesParameters` and the various `UniversalFunctions` parameter structs.
To use them, you must first import CLIMAParameters:
```julia
import CLIMAParameters as CP
import SurfaceFluxes.Parameters as SFP
import SurfaceFluxes.UniversalFunctions as UF

FT = Float64

# SurfaceFluxesParameters requires a float type and a UniversalFunctionsParameters type
SFP.SurfaceFluxesParameters(FT, UF.BusingerParams)

# Or a TOML dict instead of a float type
toml_dict = CP.create_toml_dict(Float64)
SFP.SurfaceFluxesParameters(toml_dict, UF.GrachevParams)

# UniversalFunctionsParameters only require a float type or a TOML dict.
UF.BusingerParams(FT)
UF.GryanikParams(FT)
UF.GrachevParams(FT)
UF.BeljaarsParams(toml_dict)
UF.ChengParams(toml_dict)
UF.HoltslagParams(toml_dict)
```

## Universal Functions

```@docs
Expand Down
34 changes: 9 additions & 25 deletions docs/src/plot_bonan_profiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ if !("." in LOAD_PATH) # for ease of local testing
push!(LOAD_PATH, ".")
end

using SurfaceFluxes
using SurfaceFluxes.UniversalFunctions
import CLIMAParameters as CP
import SurfaceFluxes
import SurfaceFluxes as SF
import SurfaceFluxes.UniversalFunctions
using Thermodynamics
using SurfaceFluxes.Parameters
using CLIMAParameters
import SurfaceFluxes.Parameters.SurfaceFluxesParameters
import Plots


### Generate parameter functions
include(joinpath(pkgdir(SurfaceFluxes), "parameters", "create_parameters.jl"))
FT = Float32;
toml_dict = CLIMAParameters.create_toml_dict(FT; dict_type = "alias")
param_set = create_parameters(toml_dict, UF.BusingerType())
thermo_params = SurfaceFluxes.Parameters.thermodynamics_params(param_set)
uft = SurfaceFluxes.Parameters.universal_func_type(param_set)

FT = Float32
param_set = SurfaceFluxesParameters(FT, UniversalFunctions.BusingerParams)
thermo_params = param_set.thermo_params
uft = UniversalFunctions.universal_func_type(typeof(param_set.ufp))

# Define surface parameters. Note that recovery parameters purely depend on LMO, scale variables and Δ(interior - surface)
# for each variable
Expand Down Expand Up @@ -83,7 +79,6 @@ for il in 1:10
ustar,
FT(0),
UniversalFunctions.MomentumTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand All @@ -97,7 +92,6 @@ for il in 1:10
θstar,
θ_sfc,
UniversalFunctions.HeatTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand Down Expand Up @@ -128,7 +122,6 @@ for il in 1:10
ustar,
FT(0),
UniversalFunctions.MomentumTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand All @@ -142,7 +135,6 @@ for il in 1:10
θstar,
θ_sfc,
UniversalFunctions.HeatTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand Down Expand Up @@ -172,7 +164,6 @@ for il in 1:10
ustar,
FT(0),
UniversalFunctions.MomentumTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand All @@ -186,7 +177,6 @@ for il in 1:10
θstar,
θ_sfc,
UniversalFunctions.HeatTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand Down Expand Up @@ -240,7 +230,6 @@ for il in 1:10
ustar,
FT(0),
UniversalFunctions.MomentumTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand All @@ -254,7 +243,6 @@ for il in 1:10
θstar,
θ_sfc,
UniversalFunctions.HeatTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand Down Expand Up @@ -284,7 +272,6 @@ for il in 1:10
ustar,
FT(0),
UniversalFunctions.MomentumTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand All @@ -298,7 +285,6 @@ for il in 1:10
θstar,
θ_sfc,
UniversalFunctions.HeatTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand Down Expand Up @@ -328,7 +314,6 @@ for il in 1:10
ustar,
FT(0),
UniversalFunctions.MomentumTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand All @@ -342,7 +327,6 @@ for il in 1:10
θstar,
θ_sfc,
UniversalFunctions.HeatTransport(),
uft,
SurfaceFluxes.PointValueScheme(),
),
)
Expand Down
65 changes: 34 additions & 31 deletions docs/src/plot_universal_functions.jl
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
import SurfaceFluxes
const SF = SurfaceFluxes
const SFP = SF.Parameters
const UF = SF.UniversalFunctions

import CLIMAParameters
const CP = CLIMAParameters

include(joinpath(pkgdir(SurfaceFluxes), "parameters", "create_parameters.jl"))
const FT = Float32;
toml_dict = CP.create_toml_dict(FT; dict_type = "alias")

import Plots

import SurfaceFluxes as SF
import SurfaceFluxes.Parameters.SurfaceFluxesParameters as SFP
import SurfaceFluxes.UniversalFunctions as UF
import CLIMAParameters as CP

const FT = Float32

ζ = FT(-0.1):FT(0.001):FT(0.1);

L = FT(10);

ufts = (UF.GryanikType(), UF.BusingerType(), UF.GrachevType(), UF.BeljaarsType(), UF.ChengType(), UF.HoltslagType())

universal_functions(uft) = UF.universal_func(uft, L, create_uf_parameters(toml_dict, uft))
ufps = (
UF.GryanikParams(FT),
UF.BusingerParams(FT),
UF.GrachevParams(FT),
UF.BeljaarsParams(FT),
UF.ChengParams(FT),
UF.HoltslagParams(FT),
)

function save_ϕ_figs(ufts, ζ; ylims = nothing, fig_prefix = "", xaxis = :identity, yaxis = :identity)
function save_ϕ_figs(ufps, ζ; ylims = nothing, fig_prefix = "", xaxis = :identity, yaxis = :identity)
Plots.plot()
for uft in ufts
uf = universal_functions(uft)
for ufp in ufps
uft = UF.universal_func_type(typeof(ufp))
uf = UF.universal_func(uft, L, ufp)
ϕ_m = UF.phi.(uf, ζ, UF.MomentumTransport())
label = "$(typeof(uf).name)"
Plots.plot!(ζ, ϕ_m; xlabel = "ζ", ylabel = "ϕ_m", label, ylims, xaxis, yaxis)
end
Plots.savefig("$(fig_prefix)_phi_m.svg")
Plots.plot()
for uft in ufts
uf = universal_functions(uft)
for ufp in ufps
uft = UF.universal_func_type(typeof(ufp))
uf = UF.universal_func(uft, L, ufp)
ϕ_h = UF.phi.(uf, ζ, UF.HeatTransport())
label = "$(typeof(uf).name)"
Plots.plot!(ζ, ϕ_h; xlabel = "ζ", ylabel = "ϕ_h", label, ylims, xaxis, yaxis)
end
Plots.savefig("$(fig_prefix)_phi_h.svg")
end
function save_ψ_figs(ufts, ζ; ylims = nothing, fig_prefix = "", xaxis = :identity, yaxis = :identity)
function save_ψ_figs(ufps, ζ; ylims = nothing, fig_prefix = "", xaxis = :identity, yaxis = :identity)
Plots.plot()
for uft in ufts
uf = universal_functions(uft)
for ufp in ufps
uft = UF.universal_func_type(typeof(ufp))
uf = UF.universal_func(uft, L, ufp)
ψ_m = UF.psi.(uf, ζ, UF.MomentumTransport())
label = "$(typeof(uf).name)"
Plots.plot!(ζ, ψ_m; xlabel = "ζ", ylabel = "ψ_m", label, ylims, xaxis, yaxis)
end
Plots.savefig("$(fig_prefix)_psi_m.svg")
Plots.plot()
for uft in ufts
uf = universal_functions(uft)
for ufp in ufps
uft = UF.universal_func_type(typeof(ufp))
uf = UF.universal_func(uft, L, ufp)
ψ_h = UF.psi.(uf, ζ, UF.HeatTransport())
label = "$(typeof(uf).name)"
Plots.plot!(ζ, ψ_h; xlabel = "ζ", ylabel = "ψ_h", label, ylims, xaxis, yaxis)
Expand All @@ -60,11 +63,11 @@ end


# Gryanik Plots
save_ϕ_figs(ufts, FT(0):FT(0.01):FT(15); ylims = (0, 30), fig_prefix = "Gryanik12")
save_ψ_figs(ufts, FT(0):FT(0.01):FT(15); ylims = (-25, 0), fig_prefix = "Gryanik12")
save_ϕ_figs(ufps, FT(0):FT(0.01):FT(15); ylims = (0, 30), fig_prefix = "Gryanik12")
save_ψ_figs(ufps, FT(0):FT(0.01):FT(15); ylims = (-25, 0), fig_prefix = "Gryanik12")

save_ϕ_figs(
ufts,
ufps,
10 .^ (FT(-3):0.1:FT(2));
ylims = (0.1, 10^2),
xaxis = :log10,
Expand All @@ -74,8 +77,8 @@ save_ϕ_figs(


# Businger Plots
save_ϕ_figs(ufts, FT(-2.5):FT(0.01):FT(2); ylims = (-1, 8), fig_prefix = "Businger")
save_ϕ_figs(ufps, FT(-2.5):FT(0.01):FT(2); ylims = (-1, 8), fig_prefix = "Businger")

# Bonan Plots
save_ϕ_figs(ufts, FT(-2):FT(0.01):FT(1); ylims = (0, 6), fig_prefix = "Bonan")
save_ψ_figs(ufts, FT(-2):FT(0.01):FT(1); ylims = (-5, 4), fig_prefix = "Bonan")
save_ϕ_figs(ufps, FT(-2):FT(0.01):FT(1); ylims = (0, 6), fig_prefix = "Bonan")
save_ψ_figs(ufps, FT(-2):FT(0.01):FT(1); ylims = (-5, 4), fig_prefix = "Bonan")
Loading

2 comments on commit 90343fb

@nefrathenrici
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/99211

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.0 -m "<description of version>" 90343fb60b8dd84a57f144fe675f30ea3832c397
git push origin v0.9.0

Please sign in to comment.