Skip to content

Commit

Permalink
Merge pull request #935 from CliMA/js/nan-fixes
Browse files Browse the repository at this point in the history
some NaN fixes, longrun updates
  • Loading branch information
juliasloan25 authored Dec 4, 2024
2 parents 4f0ca04 + d383b7e commit 72c199a
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 122 deletions.
12 changes: 6 additions & 6 deletions .buildkite/longruns_gpu/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ agents:
slurm_mem: 8G
modules: climacommon/2024_10_09

timeout_in_minutes: 1440

steps:
- label: "init :GPU:"
key: "init_gpu_env"
Expand Down Expand Up @@ -34,10 +32,12 @@ steps:
- label: ":snow_capped_mountain: Snowy Land"
command:
- julia --color=yes --project=.buildkite experiments/long_runs/snowy_land.jl
artifact_paths: "snowy_land_longrun_gpu/*png"
artifact_paths:
- "snowy_land_longrun_gpu/*png"
- "snowy_land_longrun_gpu/*pdf"
agents:
slurm_gpus: 1
slurm_time: 03:30:00
slurm_time: 15:00:00
env:
CLIMACOMMS_DEVICE: "CUDA"

Expand All @@ -47,7 +47,7 @@ steps:
artifact_paths: "land_longrun_gpu/*pdf"
agents:
slurm_gpus: 1
slurm_time: 03:00:00
slurm_time: 15:00:00
env:
CLIMACOMMS_DEVICE: "CUDA"

Expand All @@ -67,7 +67,7 @@ steps:
artifact_paths: "soil_longrun_gpu/*pdf"
agents:
slurm_gpus: 1
slurm_time: 01:30:00
slurm_time: 15:00:00
env:
CLIMACOMMS_DEVICE: "CUDA"

Expand Down
23 changes: 1 addition & 22 deletions docs/Manifest-v1.11.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.11.1"
manifest_format = "2.0"
project_hash = "a5dc443666e7b6f001f45671e08cb0a420c01a66"
project_hash = "15fe7e962a3bea15852e19f92138be4db325cca0"

[[deps.ADTypes]]
git-tree-sha1 = "30bb95a372787af850addf28ac937f1be7b79173"
Expand All @@ -26,16 +26,6 @@ git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
version = "0.0.1"

[[deps.About]]
deps = ["InteractiveUtils", "JuliaSyntaxHighlighting", "PrecompileTools", "StyledStrings"]
git-tree-sha1 = "efbf5b623b7ee2a41ce5aed6299aa62ab7f2d5b9"
uuid = "69d22d85-9f48-4c46-bbbe-7ad8341ff72a"
version = "1.0.1"
weakdeps = ["Pkg"]

[deps.About.extensions]
PkgExt = "Pkg"

[[deps.AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "d92ad398961a3ed262d8bf04a1a2b8340f915fef"
Expand Down Expand Up @@ -1469,17 +1459,6 @@ git-tree-sha1 = "af433a10f3942e882d3c671aacb203e006a5808f"
uuid = "9c1d0b0a-7046-5b2e-a33f-ea22f176ac7e"
version = "0.2.1+0"

[[deps.JuliaSyntax]]
git-tree-sha1 = "937da4713526b96ac9a178e2035019d3b78ead4a"
uuid = "70703baa-626e-46a2-a12c-08ffd08c73b4"
version = "0.4.10"

[[deps.JuliaSyntaxHighlighting]]
deps = ["JuliaSyntax", "StyledStrings"]
git-tree-sha1 = "19ecee1ea81c60156486a92b062e443b6bba60b7"
uuid = "ac6e5ff7-fb65-4e79-a425-ec3bc9c03011"
version = "0.1.0"

[[deps.JuliaVariables]]
deps = ["MLStyle", "NameResolution"]
git-tree-sha1 = "49fb3cb53362ddadb4415e9b73926d6b40709e70"
Expand Down
29 changes: 1 addition & 28 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.5"
manifest_format = "2.0"
project_hash = "17901eb92a5662b053574516009767eae929e671"
project_hash = "0271f9782f48e923fcefcee2c42babb40262588c"

[[deps.ADTypes]]
git-tree-sha1 = "30bb95a372787af850addf28ac937f1be7b79173"
Expand All @@ -26,16 +26,6 @@ git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
version = "0.0.1"

[[deps.About]]
deps = ["InteractiveUtils", "JuliaSyntaxHighlighting", "PrecompileTools", "StyledStrings"]
git-tree-sha1 = "efbf5b623b7ee2a41ce5aed6299aa62ab7f2d5b9"
uuid = "69d22d85-9f48-4c46-bbbe-7ad8341ff72a"
version = "1.0.1"
weakdeps = ["Pkg"]

[deps.About.extensions]
PkgExt = "Pkg"

[[deps.AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "d92ad398961a3ed262d8bf04a1a2b8340f915fef"
Expand Down Expand Up @@ -1461,17 +1451,6 @@ git-tree-sha1 = "af433a10f3942e882d3c671aacb203e006a5808f"
uuid = "9c1d0b0a-7046-5b2e-a33f-ea22f176ac7e"
version = "0.2.1+0"

[[deps.JuliaSyntax]]
git-tree-sha1 = "937da4713526b96ac9a178e2035019d3b78ead4a"
uuid = "70703baa-626e-46a2-a12c-08ffd08c73b4"
version = "0.4.10"

[[deps.JuliaSyntaxHighlighting]]
deps = ["JuliaSyntax", "StyledStrings"]
git-tree-sha1 = "19ecee1ea81c60156486a92b062e443b6bba60b7"
uuid = "ac6e5ff7-fb65-4e79-a425-ec3bc9c03011"
version = "0.1.0"

[[deps.JuliaVariables]]
deps = ["MLStyle", "NameResolution"]
git-tree-sha1 = "49fb3cb53362ddadb4415e9b73926d6b40709e70"
Expand Down Expand Up @@ -2742,12 +2721,6 @@ weakdeps = ["Adapt", "GPUArraysCore", "SparseArrays", "StaticArrays"]
StructArraysSparseArraysExt = "SparseArrays"
StructArraysStaticArraysExt = "StaticArrays"

[[deps.StyledStrings]]
deps = ["PrecompileTools", "TOML"]
git-tree-sha1 = "711c9650010c95814911c2005ea04e70e70e65ed"
uuid = "f489334b-da3d-4c2e-b8f0-e476e12c162b"
version = "1.0.3"

[[deps.SuiteSparse]]
deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"]
uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
Expand Down
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[deps]
About = "69d22d85-9f48-4c46-bbbe-7ad8341ff72a"
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Expand Down
32 changes: 23 additions & 9 deletions experiments/long_runs/land_region.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# # Global run of land model
# # Regional run of full land model

# The code sets up and runs the soil/canopy model for 6 hours on a small region of the globe in Southern California,
# The code sets up and runs the soil/canopy/snow model for 6 hours on a small
# region of the globe in Southern California,
# using ERA5 data. In this simulation, we have
# turned lateral flow off because horizontal boundary conditions and the
# land/sea mask are not yet supported by ClimaCore.

# Simulation Setup
# Number of spatial elements: 10x10 in horizontal, 15 in vertical
# Soil depth: 50 m
# Simulation duration: 365 d
# Timestep: 900 s
# Simulation duration: 4 years
# Timestep: 450 s
# Timestepper: ARS111
# Fixed number of iterations: 1
# Fixed number of iterations: 3
# Jacobian update: every new timestep
# Atmos forcing update: every 3 hours
import SciMLBase
Expand All @@ -32,6 +33,7 @@ import ClimaUtilities.ClimaArtifacts: @clima_artifact
import ClimaParams as CP

using ClimaLand
using ClimaLand.Snow
using ClimaLand.Soil
using ClimaLand.Canopy
import ClimaLand
Expand Down Expand Up @@ -284,15 +286,21 @@ function setup_prob(t0, tf, Δt; outdir = outdir, nelements = (10, 10, 15))
parameters = shared_params,
domain = ClimaLand.obtain_surface_domain(domain),
)
# Snow model
snow_parameters = SnowParameters{FT}(Δt; earth_param_set = earth_param_set)
snow_args = (;
parameters = snow_parameters,
domain = ClimaLand.obtain_surface_domain(domain),
)
snow_model_type = Snow.SnowModel

# Integrated plant hydraulics and soil model
land_input = (
atmos = atmos,
radiation = radiation,
runoff = runoff_model,
soil_organic_carbon = Csom,
)
land = SoilCanopyModel{FT}(;
land = LandModel{FT}(;
soilco2_type = soilco2_type,
soilco2_args = soilco2_args,
land_args = land_input,
Expand All @@ -301,11 +309,17 @@ function setup_prob(t0, tf, Δt; outdir = outdir, nelements = (10, 10, 15))
canopy_component_types = canopy_component_types,
canopy_component_args = canopy_component_args,
canopy_model_args = canopy_model_args,
snow_args = snow_args,
snow_model_type = snow_model_type,
)

Y, p, cds = initialize(land)

init_soil(ν, θ_r) = θ_r +- θ_r) / 2

Y.snow.S .= 0.0
Y.snow.U .= 0.0

Y.soil.ϑ_l .= init_soil.(ν, θ_r)
Y.soil.θ_i .= FT(0.0)
T = FT(276.85)
Expand Down Expand Up @@ -381,10 +395,10 @@ function setup_and_solve_problem(; greet = false)

t0 = 0.0
tf = 60 * 60.0 * 24 * 365
Δt = 900.0
Δt = 450.0
nelements = (10, 10, 15)
if greet
@info "Run: Regional Soil-Canopy Model"
@info "Run: Regional Soil-Canopy-Snow Model"
@info "Resolution: $nelements"
@info "Timestep: $Δt s"
@info "Duration: $(tf - t0) s"
Expand Down
40 changes: 38 additions & 2 deletions experiments/long_runs/snowy_land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Timestep: 450 s
# Timestepper: ARS111
# Fixed number of iterations: 3
# Jacobian update: every Newton iteration
# Jacobian update: every new Newton iteration
# Atmos forcing update: every 3 hours
import SciMLBase
import ClimaComms
Expand All @@ -29,6 +29,7 @@ import ClimaUtilities

import ClimaUtilities.TimeVaryingInputs:
TimeVaryingInput, LinearInterpolation, PeriodicCalendar
import ClimaUtilities.SpaceVaryingInputs: SpaceVaryingInput
import ClimaUtilities.ClimaArtifacts: @clima_artifact
import ClimaParams as CP

Expand All @@ -45,6 +46,8 @@ import GeoMakie
using Dates
import NCDatasets

using Poppler_jll: pdfunite

const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
context = ClimaComms.context()
Expand Down Expand Up @@ -386,7 +389,7 @@ end
function setup_and_solve_problem(; greet = false)

t0 = 0.0
tf = 60 * 60.0 * 24 * 365
tf = 60 * 60.0 * 24 * 365 * 1
Δt = 450.0
nelements = (101, 15)
if greet
Expand Down Expand Up @@ -460,3 +463,36 @@ for (group_id, group) in

CairoMakie.save(joinpath(root_path, "$(group_name).png"), fig)
end

short_names = ["gpp", "swc", "et", "ct", "swe", "si"]

mktempdir(root_path) do tmpdir
for short_name in short_names
var = get(simdir; short_name)
times = [ClimaAnalysis.times(var)[end]]
for t in times
fig = CairoMakie.Figure(size = (600, 400))
kwargs = ClimaAnalysis.has_altitude(var) ? Dict(:z => 1) : Dict()
viz.heatmap2D_on_globe!(
fig,
ClimaAnalysis.slice(var, time = t; kwargs...),
mask = viz.oceanmask(),
more_kwargs = Dict(
:mask => ClimaAnalysis.Utils.kwargs(color = :white),
:plot => ClimaAnalysis.Utils.kwargs(rasterize = true),
),
)
CairoMakie.save(joinpath(tmpdir, "$(short_name)_$t.pdf"), fig)
end
end
figures = readdir(tmpdir, join = true)
pdfunite() do unite
run(
Cmd([
unite,
figures...,
joinpath(root_path, "last_year_figures.pdf"),
]),
)
end
end
43 changes: 4 additions & 39 deletions experiments/long_runs/soil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Number of spatial elements: 101 1in horizontal, 15 in vertical
# Soil depth: 50 m
# Simulation duration: 365 d
# Timestep: 900 s
# Timestep: 450 s
# Timestepper: ARS111
# Fixed number of iterations: 1
# Jacobian update: every new timestep
Expand Down Expand Up @@ -148,44 +148,9 @@ function setup_prob(t0, tf, Δt; outdir = outdir, nelements = (101, 15))
soil_args...,
)


Y, p, cds = initialize(soil)
z = ClimaCore.Fields.coordinate_field(cds.subsurface).z
lat = ClimaCore.Fields.coordinate_field(cds.subsurface).lat
# This function approximates the hydrostatic equilibrium solution in
# the vadose and unsaturated regimes by solving for ∂(ψ+z)/∂z = 0,
# assuming the transition between the two is at a coordinate of z_∇.

# The approximation arises because the porosity, residual water fraction,
# and van Genuchtem parameters are spatially varying but treated constant
# in solving for equilibrium. Finally, we make a plausible but total guess
# for the water table depth using the TOPMODEL parameters.
function hydrostatic_profile(
lat::FT,
z::FT,
ν::FT,
θ_r::FT,
α::FT,
n::FT,
S_s::FT,
fmax,
) where {FT}
m = 1 - 1 / n
zmin = FT(-50.0)
zmax = FT(0.0)

z_∇ = FT(zmin / 5.0 + (zmax - zmin) / 2.5 * (fmax - 0.35) / 0.7)
if z > z_∇
S = FT((FT(1) +* (z - z_∇))^n)^(-m))
ϑ_l = S *- θ_r) + θ_r
else
ϑ_l = -S_s * (z - z_∇) + ν
end
return FT(ϑ_l)
end
vg_α = hydrology_cm.α
vg_n = hydrology_cm.n
Y.soil.ϑ_l .= hydrostatic_profile.(lat, z, ν, θ_r, vg_α, vg_n, S_s, f_max)
init_soil(ν, θ_r) = θ_r +- θ_r) / 2
Y.soil.ϑ_l .= init_soil.(ν, θ_r)
Y.soil.θ_i .= FT(0.0)
T = FT(276.85)
ρc_s =
Expand Down Expand Up @@ -256,7 +221,7 @@ function setup_and_solve_problem(; greet = false)

t0 = 0.0
tf = 60 * 60.0 * 24 * 365
Δt = 900.0
Δt = 450.0
nelements = (101, 15)
if greet
@info "Run: Global Soil Model"
Expand Down
Loading

0 comments on commit 72c199a

Please sign in to comment.