Skip to content

Commit

Permalink
Merge pull request #507 from CliMA/ne/bucket_model
Browse files Browse the repository at this point in the history
Refactor bucket parameters
  • Loading branch information
nefrathenrici authored Mar 8, 2024
2 parents d0a1258 + 7db910b commit 410307a
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 172 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CreateParametersExt = "ClimaParams"
Adapt = "3, 4"
ArtifactWrappers = "0.2"
CFTime = "0.1"
ClimaParams = "0.10"
ClimaParams = "0.10.2"
CSV = "0.10"
CUDA = "5"
ClimaComms = "0.5.6"
Expand Down
12 changes: 6 additions & 6 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ weakdeps = ["ClimaParams"]

[[deps.ClimaParams]]
deps = ["DocStringExtensions", "TOML", "Test"]
git-tree-sha1 = "284afdfa1e8a3d42809ffaab8e411d20d4804560"
git-tree-sha1 = "323dd6c5423caf31f0da81bb9c288683cbdafb01"
uuid = "5c42b081-d73a-476f-9059-fd94b934656c"
version = "0.10.1"
version = "0.10.2"

[[deps.ClimaTimeSteppers]]
deps = ["ClimaComms", "Colors", "DataStructures", "DiffEqBase", "DiffEqCallbacks", "KernelAbstractions", "Krylov", "LinearAlgebra", "LinearOperators", "NVTX", "SciMLBase", "StaticArrays"]
Expand Down Expand Up @@ -700,9 +700,9 @@ version = "0.8.4"

[[deps.Flux]]
deps = ["Adapt", "ChainRulesCore", "Compat", "Functors", "LinearAlgebra", "MLUtils", "MacroTools", "NNlib", "OneHotArrays", "Optimisers", "Preferences", "ProgressLogging", "Random", "Reexport", "SparseArrays", "SpecialFunctions", "Statistics", "Zygote"]
git-tree-sha1 = "fd7b23aa8013a7528563d429f6eaf406f60364ed"
git-tree-sha1 = "5a626d6ef24ae0a8590c22dc12096fb65eb66325"
uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c"
version = "0.14.12"
version = "0.14.13"

[deps.Flux.extensions]
FluxAMDGPUExt = "AMDGPU"
Expand Down Expand Up @@ -1389,9 +1389,9 @@ version = "0.2.4"

[[deps.NCDatasets]]
deps = ["CFTime", "CommonDataModel", "DataStructures", "Dates", "DiskArrays", "NetCDF_jll", "NetworkOptions", "Printf"]
git-tree-sha1 = "98ca95cf41116a24e46dc9a06fa22b923e8411b7"
git-tree-sha1 = "d40d24d12f710c39d3a66be99c567ce0032f28a7"
uuid = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
version = "0.14.2"
version = "0.14.3"

[[deps.NLSolversBase]]
deps = ["DiffResults", "Distributed", "FiniteDiff", "ForwardDiff"]
Expand Down
12 changes: 1 addition & 11 deletions docs/tutorials/standalone/Bucket/bucket_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,7 @@ t0 = 0.0;
tf = 7 * 86400;
Δt = 3600.0;

bucket_parameters = BucketModelParameters(
κ_soil,
ρc_soil,
albedo,
σS_c,
W_f,
z_0m,
z_0b,
τc,
earth_param_set,
);
bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc);


# The PrescribedAtmosphere and PrescribedRadiation need to take in a reference
Expand Down
14 changes: 7 additions & 7 deletions experiments/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.1"
manifest_format = "2.0"
project_hash = "fa68ae5ff1b320df9bb9d1834d62589b82185252"
project_hash = "960bdc0a1ed4b3f2aee66ed2e0c02065769614a9"

[[deps.ADTypes]]
git-tree-sha1 = "41c37aa88889c171f1300ceac1313c06e891d245"
Expand Down Expand Up @@ -354,9 +354,9 @@ weakdeps = ["ClimaParams"]

[[deps.ClimaParams]]
deps = ["DocStringExtensions", "TOML", "Test"]
git-tree-sha1 = "284afdfa1e8a3d42809ffaab8e411d20d4804560"
git-tree-sha1 = "323dd6c5423caf31f0da81bb9c288683cbdafb01"
uuid = "5c42b081-d73a-476f-9059-fd94b934656c"
version = "0.10.1"
version = "0.10.2"

[[deps.ClimaTimeSteppers]]
deps = ["ClimaComms", "Colors", "DataStructures", "DiffEqBase", "DiffEqCallbacks", "KernelAbstractions", "Krylov", "LinearAlgebra", "LinearOperators", "NVTX", "SciMLBase", "StaticArrays"]
Expand Down Expand Up @@ -832,9 +832,9 @@ version = "0.8.4"

[[deps.Flux]]
deps = ["Adapt", "ChainRulesCore", "Compat", "Functors", "LinearAlgebra", "MLUtils", "MacroTools", "NNlib", "OneHotArrays", "Optimisers", "Preferences", "ProgressLogging", "Random", "Reexport", "SparseArrays", "SpecialFunctions", "Statistics", "Zygote"]
git-tree-sha1 = "fd7b23aa8013a7528563d429f6eaf406f60364ed"
git-tree-sha1 = "5a626d6ef24ae0a8590c22dc12096fb65eb66325"
uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c"
version = "0.14.12"
version = "0.14.13"

[deps.Flux.extensions]
FluxAMDGPUExt = "AMDGPU"
Expand Down Expand Up @@ -1676,9 +1676,9 @@ version = "1.4.1"

[[deps.NCDatasets]]
deps = ["CFTime", "CommonDataModel", "DataStructures", "Dates", "DiskArrays", "NetCDF_jll", "NetworkOptions", "Printf"]
git-tree-sha1 = "98ca95cf41116a24e46dc9a06fa22b923e8411b7"
git-tree-sha1 = "d40d24d12f710c39d3a66be99c567ce0032f28a7"
uuid = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
version = "0.14.2"
version = "0.14.3"

[[deps.NLSolversBase]]
deps = ["DiffResults", "Distributed", "FiniteDiff", "ForwardDiff"]
Expand Down
12 changes: 1 addition & 11 deletions experiments/standalone/Bucket/global_bucket_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,7 @@ t0 = 0.0;
tf = 7 * 86400;
Δt = 3600.0;

bucket_parameters = BucketModelParameters(
κ_soil,
ρc_soil,
albedo,
σS_c,
W_f,
z_0m,
z_0b,
τc,
earth_param_set,
);
bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc);
ref_time = DateTime(2005);

# Precipitation:
Expand Down
12 changes: 1 addition & 11 deletions experiments/standalone/Bucket/global_bucket_staticmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,7 @@ surface_space = bucket_domain.space.surface
α_snow = FT(0.8)
albedo = PrescribedBaregroundAlbedo{FT}(α_snow, regrid_dir, surface_space);

bucket_parameters = BucketModelParameters(
κ_soil,
ρc_soil,
albedo,
σS_c,
W_f,
z_0m,
z_0b,
τc,
earth_param_set,
);
bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc);

# Precipitation:
precip = (t) -> 0;
Expand Down
12 changes: 1 addition & 11 deletions experiments/standalone/Bucket/global_bucket_temporalmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,7 @@ regrid_dir = joinpath(
surface_space = bucket_domain.space.surface
albedo = PrescribedSurfaceAlbedo{FT}(regrid_dir, ref_time, t0, surface_space);

bucket_parameters = BucketModelParameters(
κ_soil,
ρc_soil,
albedo,
σS_c,
W_f,
z_0m,
z_0b,
τc,
earth_param_set,
);
bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc);

# Precipitation:
precip = (t) -> 0;
Expand Down
82 changes: 82 additions & 0 deletions ext/CreateParametersExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ClimaLand.Parameters.LandParameters
import ClimaLand.Canopy.AutotrophicRespirationParameters
import ClimaLand.Canopy.FarquharParameters
import ClimaLand.Canopy.OptimalityFarquharParameters
import ClimaLand.Bucket.BucketModelParameters

import ClimaLand.Soil
import ClimaLand.Parameters as LP
Expand Down Expand Up @@ -375,4 +376,85 @@ function EnergyHydrologyParameters(
)
end


"""
BucketModelParameters(
::Type{FT};
albedo,
z_0m,
z_0b,
τc,
kwargs...,
)
BucketModelParameters(
toml_dict::CP.AbstractTOMLDict;
albedo,
z_0m,
z_0b,
τc,
kwargs...,
)
BucketModelParameters has a float-type and a toml-dict based constructor.
Keyword arguments can be used to manually override any of the values in the struct.
```julia
BucketModelParameters(Float64; albedo, z_0m, z_0b, τc)
BucketModelParameters(toml_dict; albedo, z_0m, z_0b, τc)
```
"""
function BucketModelParameters(
::Type{FT};
albedo,
z_0m,
z_0b,
τc,
kwargs...,
) where {FT <: AbstractFloat}
return BucketModelParameters(
CP.create_toml_dict(FT);
albedo,
z_0m,
z_0b,
τc,
kwargs...,
)
end

function BucketModelParameters(
toml_dict::CP.AbstractTOMLDict;
albedo,
z_0m,
z_0b,
τc,
kwargs...,
)

name_map = (;
:soil_conductivity => :κ_soil,
:soil_heat_capacity => :ρc_soil,
:critical_snow_water_equivalent => :σS_c,
:land_bucket_capacity => :W_f,
:critical_snow_fraction => :f_snow,
:bucket_capacity_fraction => :f_bucket,
:bucket_beta_decay_exponent => :p,
)
parameters = CP.get_parameter_values(toml_dict, name_map, "Land")

AAM = typeof(albedo)
earth_param_set = LandParameters(toml_dict)
PSE = typeof(earth_param_set)
FT = CP.float_type(toml_dict)
BucketModelParameters{FT, AAM, PSE}(;
albedo,
z_0m,
z_0b,
τc,
earth_param_set,
parameters...,
kwargs...,
)
end


end
31 changes: 1 addition & 30 deletions src/standalone/Bucket/Bucket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Container for holding the parameters of the bucket model.
$(DocStringExtensions.FIELDS)
"""
struct BucketModelParameters{
Base.@kwdef struct BucketModelParameters{
FT <: AbstractFloat,
AAM <: AbstractBucketAlbedoModel,
PSE,
Expand Down Expand Up @@ -244,35 +244,6 @@ struct BucketModelParameters{
earth_param_set::PSE
end

BucketModelParameters(
κ_soil::FT,
ρc_soil::FT,
albedo::AAM,
σS_c::FT,
W_f::FT,
z_0m::FT,
z_0b::FT,
τc::FT,
earth_param_set::PSE;
f_snow = FT(0.0),
f_bucket = FT(0.75),
p = FT(1),
) where {FT, AAM, PSE} = BucketModelParameters{FT, AAM, PSE}(
κ_soil,
ρc_soil,
albedo,
σS_c,
f_snow,
W_f,
f_bucket,
p,
z_0m,
z_0b,
τc,
earth_param_set,
)


"""
struct BucketModel{
Expand Down
23 changes: 5 additions & 18 deletions test/standalone/Bucket/albedo_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ if !Sys.iswindows()
for bucket_domain in bucket_domains
if bucket_domain isa SphericalShell
surface_space = bucket_domain.space.surface
albedo_model = PrescribedBaregroundAlbedo{FT}(
albedo = PrescribedBaregroundAlbedo{FT}(
α_snow,
regrid_dirpath,
surface_space,
Expand Down Expand Up @@ -237,17 +237,8 @@ if !Sys.iswindows()
h_atmos,
)
τc = FT(1.0)
bucket_parameters = BucketModelParameters(
κ_soil,
ρc_soil,
albedo_model,
σS_c,
W_f,
z_0m,
z_0b,
τc,
earth_param_set,
)
bucket_parameters =
BucketModelParameters(FT; albedo, z_0m, z_0b, τc)

model = BucketModel(
parameters = bucket_parameters,
Expand Down Expand Up @@ -382,15 +373,11 @@ if !Sys.iswindows()
)
τc = FT(1.0)
bucket_parameters = BucketModelParameters(
κ_soil,
ρc_soil,
albedo_model,
σS_c,
W_f,
FT;
albedo = albedo_model,
z_0m,
z_0b,
τc,
earth_param_set,
)

model = BucketModel(
Expand Down
Loading

0 comments on commit 410307a

Please sign in to comment.