From 0ae6c46b70184629b5967de65dc457980001b761 Mon Sep 17 00:00:00 2001 From: kmdeck Date: Tue, 5 Sep 2023 14:16:30 -0700 Subject: [PATCH 1/5] use dss in ClimaODEfunction; update docs Update richards_equation.jl remove spurious comma --- docs/tutorials/Bucket/bucket_tutorial.jl | 22 ++++++-- docs/tutorials/Canopy/canopy_tutorial.jl | 24 +++++--- docs/tutorials/Canopy/soil_canopy_tutorial.jl | 56 ++++++++++--------- docs/tutorials/Soil/freezing_front.jl | 28 +++++++--- docs/tutorials/Soil/richards_equation.jl | 55 +++++++++--------- docs/tutorials/Soil/soil_energy_hydrology.jl | 36 +++++++----- experiments/integrated/ozark/ozark.jl | 2 +- .../standalone/Biogeochemistry/experiment.jl | 2 +- 8 files changed, 138 insertions(+), 87 deletions(-) diff --git a/docs/tutorials/Bucket/bucket_tutorial.jl b/docs/tutorials/Bucket/bucket_tutorial.jl index 1bf85e5def..9fe27c38cc 100644 --- a/docs/tutorials/Bucket/bucket_tutorial.jl +++ b/docs/tutorials/Bucket/bucket_tutorial.jl @@ -301,18 +301,32 @@ set_initial_aux_state!(p, Y, t0); # of ordinary differential equations: exp_tendency! = make_exp_tendency(model); -# Now we choose our timestepping algorithm. +# Now we choose our (explicit) timestepping algorithm. timestepper = CTS.RK4() -ode_algo = CTS.ExplicitAlgorithm(timestepper) - +ode_algo = CTS.ExplicitAlgorithm(timestepper); + + +# We use the +# [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) +# interface for handling the specification of implicitly and explicitly +# treated terms. +# To set up the ClimaODEFunction, we must specify: +# - the ODE function/tendency which is treated explicitly in time +# - the ODE function/tendency which is treated implicitly in time (none here), +# - the ClimaLSM.dss! function, which does nothing for single column +# domains but carries out the dss step needed for domains with spectral +# element discretization (employed by Clima in the horizontal directions) +clima_ode_function = + CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!); # Then we can set up the simulation and solve it: prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = exp_tendency!), + clima_ode_function, Y, (t0, tf), p, ); + # We need a callback to get and store the auxiliary fields, as they # are not stored by default. saveat = collect(t0:Δt:tf); diff --git a/docs/tutorials/Canopy/canopy_tutorial.jl b/docs/tutorials/Canopy/canopy_tutorial.jl index fd262c6ab0..2e87be8a4e 100644 --- a/docs/tutorials/Canopy/canopy_tutorial.jl +++ b/docs/tutorials/Canopy/canopy_tutorial.jl @@ -248,12 +248,8 @@ canopy = ClimaLSM.Canopy.CanopyModel{FT}(; radiation = radiation, ); -# Initialize the state vectors and obtain the model coordinates, then get the -# explicit time stepping tendency that updates auxiliary and prognostic -# variables that are stepped explicitly. - +# Initialize the state vectors and obtain the model coordinates Y, p, coords = ClimaLSM.initialize(canopy) -exp_tendency! = make_exp_tendency(canopy); # Provide initial conditions for the canopy hydraulics model @@ -300,13 +296,25 @@ sv = (; ) cb = ClimaLSM.NonInterpSavingCallback(sv, saveat); -# Select a timestepping algorithm and setup the ODE problem. - +# Select an (explicit) timestepping algorithm and setup the ODE problem. timestepper = CTS.RK4(); ode_algo = CTS.ExplicitAlgorithm(timestepper) +# We use the +# [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) +# interface for handling the specification of implicitly and explicitly +# treated terms. +# To set up the ClimaODEFunction, we must specify: +# - the ODE function/tendency which is treated explicitly in time +# - the ODE function/tendency which is treated implicitly in time (none here), +# - the ClimaLSM.dss! function, which does nothing for single column +# domains but carries out the dss step needed for domains with spectral +# element discretization (employed by Clima in the horizontal directions) +exp_tendency! = make_exp_tendency(canopy); +clima_ode_function = + CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!); prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!), + clima_ode_function, Y, (t0, tf), p, diff --git a/docs/tutorials/Canopy/soil_canopy_tutorial.jl b/docs/tutorials/Canopy/soil_canopy_tutorial.jl index 06f40f4ee9..69155c1f62 100644 --- a/docs/tutorials/Canopy/soil_canopy_tutorial.jl +++ b/docs/tutorials/Canopy/soil_canopy_tutorial.jl @@ -316,13 +316,8 @@ land = SoilCanopyModel{FT}(; canopy_model_args = canopy_model_args, ); -# Now we can initialize the state vectors and model coordinates, and initialize -# the explicit/implicit tendencies as usual. The Richard's equation time -# stepping is done implicitly, while the canopy model may be explicitly stepped, -# so we use an IMEX (implicit-explicit) scheme for the combined model. - +# Now we can initialize the state vectors and model coordinates. Y, p, coords = initialize(land); -exp_tendency! = make_exp_tendency(land); # We need to provide initial conditions for the soil and canopy hydraulics # models: @@ -354,39 +349,48 @@ for i in 1:2 augmented_liquid_fraction.(plant_ν, S_l_ini[i]) end; -# Now set the initial conditions for the auxiliary variables for the combined soil and plant model. - -t0 = FT(0) -set_initial_aux_state! = make_set_initial_aux_state(land) -set_initial_aux_state!(p, Y, t0); - # Select the timestepper and solvers needed for the specific problem. Specify the time range and dt -# value over which to perform the simulation. - t0 = FT(150 * 3600 * 24)# start mid year N_days = 100 tf = t0 + FT(3600 * 24 * N_days) -dt = FT(30) -n = 120 -saveat = Array(t0:(n * dt):tf) +# Now set the initial conditions for the auxiliary variables for the combined soil and plant model. +set_initial_aux_state! = make_set_initial_aux_state(land) +set_initial_aux_state!(p, Y, t0); + +# Pick the timestepper, timestep. Here we choose an explicit algorithm, +# which is appropriate for this model. +dt = FT(30) timestepper = CTS.RK4() ode_algo = CTS.ExplicitAlgorithm(timestepper); -# And now perform the simulation as always. - +# By default, only the state Y is saved. We'd like to save `p` as well, +# so we can define a callback which does so here: +n = 120 +saveat = Array(t0:(n * dt):tf) sv = (; t = Array{FT}(undef, length(saveat)), saveval = Array{ClimaCore.Fields.NamedTuple}(undef, length(saveat)), ) -cb = ClimaLSM.NonInterpSavingCallback(sv, saveat) +cb = ClimaLSM.NonInterpSavingCallback(sv, saveat); + +# We use the +# [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) +# interface for handling the specification of implicitly and explicitly +# treated terms. +# To set up the ClimaODEFunction, we must specify: +# - the ODE function/tendency which is treated explicitly in time +# - the ODE function/tendency which is treated implicitly in time (none here), +# - the ClimaLSM.dss! function, which does nothing for single column +# domains but carries out the dss step needed for domains with spectral +# element discretization (employed by Clima in the horizontal directions) +exp_tendency! = make_exp_tendency(land); +clima_ode_function = + CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!) +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); -prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = exp_tendency!), - Y, - (t0, tf), - p, -); +# Now, wrap the problem, algorithm, timestep, and callback together +# to carry out the simulation. sol = SciMLBase.solve( prob, ode_algo; diff --git a/docs/tutorials/Soil/freezing_front.jl b/docs/tutorials/Soil/freezing_front.jl index b36091be17..913bda390b 100644 --- a/docs/tutorials/Soil/freezing_front.jl +++ b/docs/tutorials/Soil/freezing_front.jl @@ -200,26 +200,40 @@ end init_soil!(Y, coords.z, soil.parameters); -# We choose the initial and final simulation times: +# Here we choose the timestepping algorithm. For the energy & hydrology +# soil model, we currently only support explicit timestepping. +# Here, we use the explicit timestepping algorithm RK4, which is suitable +# for this model because it has no defined implicit tendendency function. +timestepper = CTS.RK4(); +ode_algo = CTS.ExplicitAlgorithm(timestepper); + +# Choose a timestep, integration timespan: t0 = FT(0) -tf = FT(60 * 60 * 50); +tf = FT(60 * 60 * 50) +dt = FT(60); # We set the aux state corresponding to the initial conditions # of the state Y: set_initial_aux_state! = make_set_initial_aux_state(soil); set_initial_aux_state!(p, Y, t0); -# Create the tendency function, and choose a timestep, and timestepper: +# To set up the ClimaODEFunction which will be executed to step the +# system explicitly in time, we must specify: +# - the ODE function/tendency which is treated explicitly in time +# - the ClimaLSM.dss! function, which does nothing for single column +# domains but carries out the dss step needed for domains with spectral +# element discretization (employed by Clima in the horizontal directions) exp_tendency! = make_exp_tendency(soil) -dt = FT(60) -timestepper = CTS.RK4() -ode_algo = CTS.ExplicitAlgorithm(timestepper) +clima_ode_function = + CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!); + prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!), + clima_ode_function, Y, (t0, tf), p, ); + # Now we can solve the problem. sol = SciMLBase.solve(prob, ode_algo; dt = dt, saveat = 0:3600:tf); diff --git a/docs/tutorials/Soil/richards_equation.jl b/docs/tutorials/Soil/richards_equation.jl index 14f337dd2e..a6d1e9fcfc 100644 --- a/docs/tutorials/Soil/richards_equation.jl +++ b/docs/tutorials/Soil/richards_equation.jl @@ -131,13 +131,6 @@ soil = Soil.RichardsModel{FT}(; sources = sources, ); -# Here we create the explicit and implicit tendencies, which update prognostic -# variable components that are stepped explicitly and implicitly, respectively. -# We also create the function which is used to update our Jacobian. -exp_tendency! = make_exp_tendency(soil); -imp_tendency! = ClimaLSM.make_imp_tendency(soil); -update_jacobian! = ClimaLSM.make_update_jacobian(soil); - # # Set up the simulation # We can now initialize the prognostic and auxiliary variable vectors, and take # a peek at what those variables are: @@ -162,12 +155,38 @@ tf = FT(60 * 60 * 24 * 36); set_initial_aux_state! = make_set_initial_aux_state(soil); set_initial_aux_state!(p, Y, t0); -# Next, we turn to timestepping. +# For solving Richards equation, the `RichardsModel` is set up to +# treat the vertical transport of water implicitly in time, +# and the horizontal transport (if applicable) explicitly in time. +# We use the +# [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) +# interface for handling the specification of implicitly and explicitly +# treated terms. +# To set up the ClimaODEFunction, we must specify: +# - the ODE function/tendency which is treated explicitly in time +# - the ODE function/tendency which is treated implicitly in time, +# along with information about the Jacobian of this function +# - the ClimaLSM.dss! function, which does nothing for single column +# domains but carries out the dss step needed for domains with spectral +# element discretization (employed by Clima in the horizontal directions) +# Here we set up the information used for the Jacobian of the implicit +exp_tendency! = ClimaLSM.make_exp_tendency(soil); +imp_tendency! = ClimaLSM.make_imp_tendency(soil); +update_jacobian! = ClimaLSM.make_update_jacobian(soil); +jac_kwargs = + (; jac_prototype = RichardsTridiagonalW(Y), Wfact = update_jacobian!); +clima_ode_function = + CTS.ClimaODEFunction( + T_exp! = exp_tendency!, + T_imp! = ODE.ODEFunction(imp_tendency!; jac_kwargs...), + dss! = ClimaLSM.dss!, + ) + + +# Now, we choose the imex timestepping algorithm we want to use and the timestep. # As usual, your timestep depends on the problem you are solving, the accuracy # of the solution required, and the timestepping algorithm you are using. dt = FT(1e3); - -# Now, we choose the timestepping algorithm we want to use. # We'll use the ARS111 algorithm with 1 Newton iteration per timestep; # you can also specify a convergence criterion and a maximum number # of Newton iterations. @@ -180,26 +199,12 @@ ode_algo = CTS.IMEXAlgorithm( ), ); -# Here we set up the information used for our Jacobian. -jac_kwargs = - (; jac_prototype = RichardsTridiagonalW(Y), Wfact = update_jacobian!); - # And then we can solve the system of equations, using # [SciMLBase.jl](https://github.com/SciML/SciMLBase.jl) and # [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl). -prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction( - T_exp! = exp_tendency!, - T_imp! = SciMLBase.ODEFunction(imp_tendency!; jac_kwargs...), - dss! = ClimaLSM.dss!, - ), - Y, - (t0, tf), - p, -); +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); sol = SciMLBase.solve(prob, ode_algo; dt = dt, adaptive = false); - # # Create some plots # We'll plot the moisture content vs depth in the soil, as well as # the expected profile of `ϑ_l` in hydrostatic equilibrium. diff --git a/docs/tutorials/Soil/soil_energy_hydrology.jl b/docs/tutorials/Soil/soil_energy_hydrology.jl index 27690982e5..72076227ea 100644 --- a/docs/tutorials/Soil/soil_energy_hydrology.jl +++ b/docs/tutorials/Soil/soil_energy_hydrology.jl @@ -201,7 +201,6 @@ soil = Soil.EnergyHydrology{FT}(; sources = sources, ); -exp_tendency! = make_exp_tendency(soil); # # Set up the simulation # We can now initialize the prognostic and auxiliary variable vectors, and take # a peek at what those variables are: @@ -242,6 +241,7 @@ function init_soil!(Y, z, params) end init_soil!(Y, coords.z, soil.parameters); +<<<<<<< HEAD # We choose the initial and final simulation times: t0 = FT(0) @@ -252,21 +252,27 @@ tf = FT(60 * 60 * 72); set_initial_aux_state! = make_set_initial_aux_state(soil); set_initial_aux_state!(p, Y, t0); -# We use [ClimaTimesteppers.jl](https://github.com/CliMA/ClimaTimesteppers.jl) for carrying out the time integration. - -# Choose a timestepper and set up the ODE problem: -dt = FT(30.0); +# Next we choose the timestepping algorithm. For the energy & hydrology +# soil model, we currently only support explicit timestepping. +# Here, we use the explicit timestepping algorithm RK4, which is suitable +# for this model because it has no defined implicit tendendency function. +# We use [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) +# for timestepping. timestepper = CTS.RK4(); -ode_algo = CTS.ExplicitAlgorithm(timestepper) -prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!), - Y, - (t0, tf), - p, -); - - -#By default, it +ode_algo = CTS.ExplicitAlgorithm(timestepper); +dt = FT(30.0); +# To set up the ClimaODEFunction which will be executed to step the +# system explicitly in time, we must specify: +# - the ODE function/tendency which is treated explicitly in time +# - the ClimaLSM.dss! function, which does nothing for single column +# domains but carries out the dss step needed for domains with spectral +# element discretization (employed by Clima in the horizontal directions) +exp_tendency! = make_exp_tendency(soil) +clima_ode_function = + CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!); +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); + +# By default, the `solve` command # only returns Y and t at each time we request output (`saveat`, below). We use # a callback in order to also get the auxiliary vector `p` back: saveat = collect(t0:FT(1000 * dt):tf) diff --git a/experiments/integrated/ozark/ozark.jl b/experiments/integrated/ozark/ozark.jl index c6848b0c55..4f382f684e 100644 --- a/experiments/integrated/ozark/ozark.jl +++ b/experiments/integrated/ozark/ozark.jl @@ -210,7 +210,7 @@ sv = (; cb = ClimaLSM.NonInterpSavingCallback(sv, saveat) prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = exp_tendency!), + CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!), Y, (t0, tf), p, diff --git a/experiments/standalone/Biogeochemistry/experiment.jl b/experiments/standalone/Biogeochemistry/experiment.jl index 5c95874ae3..47f524ef08 100644 --- a/experiments/standalone/Biogeochemistry/experiment.jl +++ b/experiments/standalone/Biogeochemistry/experiment.jl @@ -153,7 +153,7 @@ saved_values = (; cb = ClimaLSM.NonInterpSavingCallback(saved_values, saveat) prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = Soil_bio_exp_tendency!), + CTS.ClimaODEFunction(T_exp! = Soil_bio_exp_tendency!, dss! = ClimaLSM.dss!), Y, (t0, tf), p, From e3772567369c811627223524b942f8387f08494e Mon Sep 17 00:00:00 2001 From: kmdeck Date: Wed, 13 Sep 2023 12:19:51 -0700 Subject: [PATCH 2/5] Added default odefunction --- Project.toml | 1 + docs/Manifest.toml | 52 ++++++++-------- docs/Project.toml | 1 - docs/tutorials/Bucket/bucket_tutorial.jl | 26 ++------ docs/tutorials/Canopy/canopy_tutorial.jl | 25 ++------ docs/tutorials/Canopy/soil_canopy_tutorial.jl | 18 ++---- docs/tutorials/Soil/freezing_front.jl | 19 ++---- docs/tutorials/Soil/richards_equation.jl | 17 +----- docs/tutorials/Soil/soil_energy_hydrology.jl | 12 +--- experiments/Manifest.toml | 50 ++++++++-------- src/ClimaLSM.jl | 3 +- src/shared_utilities/implicit_tendencies.jl | 59 +++++++++---------- src/shared_utilities/models.jl | 32 +++++++++- src/standalone/Soil/Soil.jl | 1 + src/standalone/Soil/rre.jl | 5 ++ 15 files changed, 146 insertions(+), 175 deletions(-) diff --git a/Project.toml b/Project.toml index 198297fb18..adbb244dec 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ CFTime = "179af706-886a-5703-950a-314cd64e0468" ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d" ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884" ClimaCoreTempestRemap = "d934ef94-cdd4-4710-83d6-720549644b70" +ClimaTimeSteppers = "595c0a79-7f3d-439a-bc5a-b232dc3bde79" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" diff --git a/docs/Manifest.toml b/docs/Manifest.toml index e4c6e0e202..86e54c0486 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -2,12 +2,12 @@ julia_version = "1.9.1" manifest_format = "2.0" -project_hash = "14af05f91b5633dd5211334568bc346a7be1f927" +project_hash = "cf146a17e08c22c52d1d495030b4f2d39964861b" [[deps.ADTypes]] -git-tree-sha1 = "d68758475ff90600488eb975b5ac222709a7dd6f" +git-tree-sha1 = "f2b16fe1a3491b295105cae080c2a5f77a842718" uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b" -version = "0.2.2" +version = "0.2.3" [[deps.AMD]] deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse_jll"] @@ -69,9 +69,9 @@ version = "7.4.11" [[deps.ArrayLayouts]] deps = ["FillArrays", "LinearAlgebra"] -git-tree-sha1 = "dcda7e0ac618210eabf43751d5cafde100dd539b" +git-tree-sha1 = "0d61921af2799487b80453a44abb57db7a0c1381" uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" -version = "1.3.0" +version = "1.4.1" weakdeps = ["SparseArrays"] [deps.ArrayLayouts.extensions] @@ -153,9 +153,9 @@ version = "0.1.2" [[deps.CLIMAParameters]] deps = ["DocStringExtensions", "TOML", "Test"] -git-tree-sha1 = "91ba1a09c86300e814655914b120183ee16cdc53" +git-tree-sha1 = "7f3b89db2aabb81ec5750300a37d424f1f38240d" uuid = "6eacf6c3-8458-43b9-ae03-caf5306d3d53" -version = "0.7.15" +version = "0.7.18" [[deps.CPUSummary]] deps = ["CpuId", "IfElse", "PrecompileTools", "Static"] @@ -218,7 +218,7 @@ uuid = "d934ef94-cdd4-4710-83d6-720549644b70" version = "0.3.5" [[deps.ClimaLSM]] -deps = ["ArtifactWrappers", "CFTime", "ClimaComms", "ClimaCore", "ClimaCoreTempestRemap", "Dates", "DocStringExtensions", "IntervalSets", "JLD2", "LinearAlgebra", "NCDatasets", "SciMLBase", "StaticArrays", "SurfaceFluxes", "Thermodynamics", "UnPack"] +deps = ["ArtifactWrappers", "CFTime", "ClimaComms", "ClimaCore", "ClimaCoreTempestRemap", "ClimaTimeSteppers", "Dates", "DocStringExtensions", "IntervalSets", "JLD2", "LinearAlgebra", "NCDatasets", "SciMLBase", "StaticArrays", "SurfaceFluxes", "Thermodynamics", "UnPack"] path = ".." uuid = "7884a58f-fab6-4fd0-82bb-ecfedb2d8430" version = "0.3.2" @@ -303,9 +303,9 @@ version = "2.2.1" [[deps.ConstructionBase]] deps = ["LinearAlgebra"] -git-tree-sha1 = "fe2838a593b5f776e1597e086dcd47560d94e816" +git-tree-sha1 = "c53fc348ca4d40d7b371e71fd52251839080cbc9" uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9" -version = "1.5.3" +version = "1.5.4" weakdeps = ["IntervalSets", "StaticArrays"] [deps.ConstructionBase.extensions] @@ -369,9 +369,9 @@ version = "0.1.0+0" [[deps.DiffEqBase]] deps = ["ArrayInterface", "ChainRulesCore", "DataStructures", "DocStringExtensions", "EnumX", "FastBroadcast", "ForwardDiff", "FunctionWrappers", "FunctionWrappersWrappers", "LinearAlgebra", "Logging", "Markdown", "MuladdMacro", "Parameters", "PreallocationTools", "Printf", "RecursiveArrayTools", "Reexport", "Requires", "SciMLBase", "SciMLOperators", "Setfield", "SparseArrays", "Static", "StaticArraysCore", "Statistics", "Tricks", "TruncatedStacktraces", "ZygoteRules"] -git-tree-sha1 = "df8638dbfa03d1b336c410e23a9dfbf89cb53937" +git-tree-sha1 = "dee066b8dce741815729f5973b6db757416948b7" uuid = "2b5f629d-d688-5b77-993f-72d75c75574e" -version = "6.128.2" +version = "6.128.4" [deps.DiffEqBase.extensions] DiffEqBaseDistributionsExt = "Distributions" @@ -655,10 +655,10 @@ uuid = "88fa7841-ef32-4516-bb70-c6ec135699d9" version = "0.1.0" [[deps.Glib_jll]] -deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE2_jll", "Pkg", "Zlib_jll"] -git-tree-sha1 = "d3b3624125c1474292d0d8ed0f65554ac37ddb23" +deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE2_jll", "Zlib_jll"] +git-tree-sha1 = "e94c92c7bf4819685eb80186d51c43e71d4afa17" uuid = "7746bdde-850d-59dc-9ae8-88ece973131d" -version = "2.74.0+2" +version = "2.76.5+0" [[deps.Graphite2_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -685,9 +685,9 @@ version = "1.12.2+2" [[deps.HTTP]] deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"] -git-tree-sha1 = "cb56ccdd481c0dd7f975ad2b3b62d9eda088f7e2" +git-tree-sha1 = "19e974eced1768fb46fd6020171f2cec06b1edb5" uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "1.9.14" +version = "1.9.15" [[deps.HarfBuzz_jll]] deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"] @@ -1159,9 +1159,9 @@ version = "1.4.1" [[deps.OpenSSL_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl"] -git-tree-sha1 = "bbb5c2115d63c2f1451cb70e5ef75e8fe4707019" +git-tree-sha1 = "a12e56c72edee3ce6b96667745e6cbbe5498f200" uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" -version = "1.1.22+0" +version = "1.1.23+0" [[deps.OpenSpecFun_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] @@ -1347,17 +1347,19 @@ version = "0.6.12" [[deps.RecursiveArrayTools]] deps = ["Adapt", "ArrayInterface", "DocStringExtensions", "GPUArraysCore", "IteratorInterfaceExtensions", "LinearAlgebra", "RecipesBase", "Requires", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables"] -git-tree-sha1 = "7ed35fb5f831aaf09c2d7c8736d44667a1afdcb0" +git-tree-sha1 = "9dbbf698bdd943fbf380f81bb4c365bc76287dc3" uuid = "731186ca-8d62-57ce-b412-fbd966d074cd" -version = "2.38.7" +version = "2.38.9" [deps.RecursiveArrayTools.extensions] RecursiveArrayToolsMeasurementsExt = "Measurements" + RecursiveArrayToolsMonteCarloMeasurementsExt = "MonteCarloMeasurements" RecursiveArrayToolsTrackerExt = "Tracker" RecursiveArrayToolsZygoteExt = "Zygote" [deps.RecursiveArrayTools.weakdeps] Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" + MonteCarloMeasurements = "0987c9cc-fe09-11e8-30f0-b96dd679fdca" Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" @@ -1401,9 +1403,9 @@ version = "0.1.0" [[deps.SciMLBase]] deps = ["ADTypes", "ArrayInterface", "ChainRulesCore", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables", "TruncatedStacktraces", "ZygoteRules"] -git-tree-sha1 = "54b005258bb5ee4b6fd0f440b528e7b7af4c9975" +git-tree-sha1 = "c0781c7ebb65776e9770d333b5e191d20dd45fcf" uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462" -version = "1.96.2" +version = "1.97.0" [deps.SciMLBase.extensions] ZygoteExt = "Zygote" @@ -1489,9 +1491,9 @@ weakdeps = ["OffsetArrays", "StaticArrays"] [[deps.StaticArrays]] deps = ["LinearAlgebra", "Random", "StaticArraysCore"] -git-tree-sha1 = "9cabadf6e7cd2349b6cf49f1915ad2028d65e881" +git-tree-sha1 = "51621cca8651d9e334a659443a74ce50a3b6dfab" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.6.2" +version = "1.6.3" weakdeps = ["Statistics"] [deps.StaticArrays.extensions] diff --git a/docs/Project.toml b/docs/Project.toml index 7c7560ae97..7c709ec360 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -6,7 +6,6 @@ ClimaLSM = "7884a58f-fab6-4fd0-82bb-ecfedb2d8430" ClimaTimeSteppers = "595c0a79-7f3d-439a-bc5a-b232dc3bde79" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94" -DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" Insolation = "e98cc03f-d57e-4e3c-b70c-8d51efe9e0d8" diff --git a/docs/tutorials/Bucket/bucket_tutorial.jl b/docs/tutorials/Bucket/bucket_tutorial.jl index 9fe27c38cc..6d8afad138 100644 --- a/docs/tutorials/Bucket/bucket_tutorial.jl +++ b/docs/tutorials/Bucket/bucket_tutorial.jl @@ -301,30 +301,16 @@ set_initial_aux_state!(p, Y, t0); # of ordinary differential equations: exp_tendency! = make_exp_tendency(model); -# Now we choose our (explicit) timestepping algorithm. +# Now we choose our (explicit) timestepping algorithm from +# the selection available in [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl). timestepper = CTS.RK4() ode_algo = CTS.ExplicitAlgorithm(timestepper); - -# We use the -# [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) -# interface for handling the specification of implicitly and explicitly -# treated terms. -# To set up the ClimaODEFunction, we must specify: -# - the ODE function/tendency which is treated explicitly in time -# - the ODE function/tendency which is treated implicitly in time (none here), -# - the ClimaLSM.dss! function, which does nothing for single column -# domains but carries out the dss step needed for domains with spectral -# element discretization (employed by Clima in the horizontal directions) -clima_ode_function = - CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!); +# To set up the ClimaODEFunction which will be executed to step the +# system explicitly in time, we call `get_ClimaODEFunction`: +clima_ode_function = ClimaLSM.get_ClimaODEFunction(model) # Then we can set up the simulation and solve it: -prob = SciMLBase.ODEProblem( - clima_ode_function, - Y, - (t0, tf), - p, -); +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); # We need a callback to get and store the auxiliary fields, as they diff --git a/docs/tutorials/Canopy/canopy_tutorial.jl b/docs/tutorials/Canopy/canopy_tutorial.jl index 2e87be8a4e..d2d3025374 100644 --- a/docs/tutorials/Canopy/canopy_tutorial.jl +++ b/docs/tutorials/Canopy/canopy_tutorial.jl @@ -296,29 +296,14 @@ sv = (; ) cb = ClimaLSM.NonInterpSavingCallback(sv, saveat); -# Select an (explicit) timestepping algorithm and setup the ODE problem. +# Select an (explicit) timestepping algorithm from [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) timestepper = CTS.RK4(); ode_algo = CTS.ExplicitAlgorithm(timestepper) -# We use the -# [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) -# interface for handling the specification of implicitly and explicitly -# treated terms. -# To set up the ClimaODEFunction, we must specify: -# - the ODE function/tendency which is treated explicitly in time -# - the ODE function/tendency which is treated implicitly in time (none here), -# - the ClimaLSM.dss! function, which does nothing for single column -# domains but carries out the dss step needed for domains with spectral -# element discretization (employed by Clima in the horizontal directions) -exp_tendency! = make_exp_tendency(canopy); -clima_ode_function = - CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!); -prob = SciMLBase.ODEProblem( - clima_ode_function, - Y, - (t0, tf), - p, -); +# To set up the ClimaODEFunction which will be executed to step the +# system explicitly in time, we call `get_ClimaODEFunction`: +clima_ode_function = ClimaLSM.get_ClimaODEFunction(canopy) +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); # Now, we can solve the problem and store the model data in the saveat array, # using [`SciMLBase.jl`](https://github.com/SciML/SciMLBase.jl) and diff --git a/docs/tutorials/Canopy/soil_canopy_tutorial.jl b/docs/tutorials/Canopy/soil_canopy_tutorial.jl index 69155c1f62..ee20ed8c9e 100644 --- a/docs/tutorials/Canopy/soil_canopy_tutorial.jl +++ b/docs/tutorials/Canopy/soil_canopy_tutorial.jl @@ -359,7 +359,7 @@ set_initial_aux_state! = make_set_initial_aux_state(land) set_initial_aux_state!(p, Y, t0); # Pick the timestepper, timestep. Here we choose an explicit algorithm, -# which is appropriate for this model. +# which is appropriate for this model, from [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) dt = FT(30) timestepper = CTS.RK4() ode_algo = CTS.ExplicitAlgorithm(timestepper); @@ -374,19 +374,9 @@ sv = (; ) cb = ClimaLSM.NonInterpSavingCallback(sv, saveat); -# We use the -# [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) -# interface for handling the specification of implicitly and explicitly -# treated terms. -# To set up the ClimaODEFunction, we must specify: -# - the ODE function/tendency which is treated explicitly in time -# - the ODE function/tendency which is treated implicitly in time (none here), -# - the ClimaLSM.dss! function, which does nothing for single column -# domains but carries out the dss step needed for domains with spectral -# element discretization (employed by Clima in the horizontal directions) -exp_tendency! = make_exp_tendency(land); -clima_ode_function = - CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!) +# To set up the ClimaODEFunction which will be executed to step the +# system explicitly in time, we call `get_ClimaODEFunction`: +clima_ode_function = ClimaLSM.get_ClimaODEFunction(land) prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); # Now, wrap the problem, algorithm, timestep, and callback together diff --git a/docs/tutorials/Soil/freezing_front.jl b/docs/tutorials/Soil/freezing_front.jl index 913bda390b..13eeef2ccf 100644 --- a/docs/tutorials/Soil/freezing_front.jl +++ b/docs/tutorials/Soil/freezing_front.jl @@ -204,6 +204,7 @@ init_soil!(Y, coords.z, soil.parameters); # soil model, we currently only support explicit timestepping. # Here, we use the explicit timestepping algorithm RK4, which is suitable # for this model because it has no defined implicit tendendency function. +# More options are available at [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl). timestepper = CTS.RK4(); ode_algo = CTS.ExplicitAlgorithm(timestepper); @@ -217,21 +218,9 @@ dt = FT(60); set_initial_aux_state! = make_set_initial_aux_state(soil); set_initial_aux_state!(p, Y, t0); # To set up the ClimaODEFunction which will be executed to step the -# system explicitly in time, we must specify: -# - the ODE function/tendency which is treated explicitly in time -# - the ClimaLSM.dss! function, which does nothing for single column -# domains but carries out the dss step needed for domains with spectral -# element discretization (employed by Clima in the horizontal directions) -exp_tendency! = make_exp_tendency(soil) -clima_ode_function = - CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!); - -prob = SciMLBase.ODEProblem( - clima_ode_function, - Y, - (t0, tf), - p, -); +# system explicitly in time, we call `get_ClimaODEFunction`: +clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil) +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); # Now we can solve the problem. diff --git a/docs/tutorials/Soil/richards_equation.jl b/docs/tutorials/Soil/richards_equation.jl index a6d1e9fcfc..a4c3e7780f 100644 --- a/docs/tutorials/Soil/richards_equation.jl +++ b/docs/tutorials/Soil/richards_equation.jl @@ -162,26 +162,15 @@ set_initial_aux_state!(p, Y, t0); # [ClimaTimeSteppers.jl](https://github.com/CliMA/ClimaTimeSteppers.jl) # interface for handling the specification of implicitly and explicitly # treated terms. -# To set up the ClimaODEFunction, we must specify: +# To set up the ClimaODEFunction, we just need to call +# `get_ClimaODEFunction`. Under the hood, this is specifying # - the ODE function/tendency which is treated explicitly in time # - the ODE function/tendency which is treated implicitly in time, # along with information about the Jacobian of this function # - the ClimaLSM.dss! function, which does nothing for single column # domains but carries out the dss step needed for domains with spectral # element discretization (employed by Clima in the horizontal directions) -# Here we set up the information used for the Jacobian of the implicit -exp_tendency! = ClimaLSM.make_exp_tendency(soil); -imp_tendency! = ClimaLSM.make_imp_tendency(soil); -update_jacobian! = ClimaLSM.make_update_jacobian(soil); -jac_kwargs = - (; jac_prototype = RichardsTridiagonalW(Y), Wfact = update_jacobian!); -clima_ode_function = - CTS.ClimaODEFunction( - T_exp! = exp_tendency!, - T_imp! = ODE.ODEFunction(imp_tendency!; jac_kwargs...), - dss! = ClimaLSM.dss!, - ) - +clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil, Y) # Now, we choose the imex timestepping algorithm we want to use and the timestep. # As usual, your timestep depends on the problem you are solving, the accuracy diff --git a/docs/tutorials/Soil/soil_energy_hydrology.jl b/docs/tutorials/Soil/soil_energy_hydrology.jl index 72076227ea..9675752476 100644 --- a/docs/tutorials/Soil/soil_energy_hydrology.jl +++ b/docs/tutorials/Soil/soil_energy_hydrology.jl @@ -241,7 +241,7 @@ function init_soil!(Y, z, params) end init_soil!(Y, coords.z, soil.parameters); -<<<<<<< HEAD +<< << << < HEAD # We choose the initial and final simulation times: t0 = FT(0) @@ -262,14 +262,8 @@ timestepper = CTS.RK4(); ode_algo = CTS.ExplicitAlgorithm(timestepper); dt = FT(30.0); # To set up the ClimaODEFunction which will be executed to step the -# system explicitly in time, we must specify: -# - the ODE function/tendency which is treated explicitly in time -# - the ClimaLSM.dss! function, which does nothing for single column -# domains but carries out the dss step needed for domains with spectral -# element discretization (employed by Clima in the horizontal directions) -exp_tendency! = make_exp_tendency(soil) -clima_ode_function = - CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!); +# system explicitly in time, we call `get_ClimaODEFunction`: +clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil) prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); # By default, the `solve` command diff --git a/experiments/Manifest.toml b/experiments/Manifest.toml index 55ab091ae9..d899d20486 100644 --- a/experiments/Manifest.toml +++ b/experiments/Manifest.toml @@ -5,9 +5,9 @@ manifest_format = "2.0" project_hash = "91c95cc935dde3a0621fb4c1603668c6bc14afbc" [[deps.ADTypes]] -git-tree-sha1 = "d68758475ff90600488eb975b5ac222709a7dd6f" +git-tree-sha1 = "f2b16fe1a3491b295105cae080c2a5f77a842718" uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b" -version = "0.2.2" +version = "0.2.3" [[deps.AMD]] deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse_jll"] @@ -64,9 +64,9 @@ version = "7.4.11" [[deps.ArrayLayouts]] deps = ["FillArrays", "LinearAlgebra"] -git-tree-sha1 = "dcda7e0ac618210eabf43751d5cafde100dd539b" +git-tree-sha1 = "0d61921af2799487b80453a44abb57db7a0c1381" uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" -version = "1.3.0" +version = "1.4.1" weakdeps = ["SparseArrays"] [deps.ArrayLayouts.extensions] @@ -148,9 +148,9 @@ version = "0.1.2" [[deps.CLIMAParameters]] deps = ["DocStringExtensions", "TOML", "Test"] -git-tree-sha1 = "91ba1a09c86300e814655914b120183ee16cdc53" +git-tree-sha1 = "7f3b89db2aabb81ec5750300a37d424f1f38240d" uuid = "6eacf6c3-8458-43b9-ae03-caf5306d3d53" -version = "0.7.15" +version = "0.7.18" [[deps.CPUSummary]] deps = ["CpuId", "IfElse", "PrecompileTools", "Static"] @@ -213,7 +213,7 @@ uuid = "d934ef94-cdd4-4710-83d6-720549644b70" version = "0.3.5" [[deps.ClimaLSM]] -deps = ["ArtifactWrappers", "CFTime", "ClimaComms", "ClimaCore", "ClimaCoreTempestRemap", "Dates", "DocStringExtensions", "IntervalSets", "JLD2", "LinearAlgebra", "NCDatasets", "SciMLBase", "StaticArrays", "SurfaceFluxes", "Thermodynamics", "UnPack"] +deps = ["ArtifactWrappers", "CFTime", "ClimaComms", "ClimaCore", "ClimaCoreTempestRemap", "ClimaTimeSteppers", "Dates", "DocStringExtensions", "IntervalSets", "JLD2", "LinearAlgebra", "NCDatasets", "SciMLBase", "StaticArrays", "SurfaceFluxes", "Thermodynamics", "UnPack"] path = ".." uuid = "7884a58f-fab6-4fd0-82bb-ecfedb2d8430" version = "0.3.2" @@ -298,9 +298,9 @@ version = "2.2.1" [[deps.ConstructionBase]] deps = ["LinearAlgebra"] -git-tree-sha1 = "fe2838a593b5f776e1597e086dcd47560d94e816" +git-tree-sha1 = "c53fc348ca4d40d7b371e71fd52251839080cbc9" uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9" -version = "1.5.3" +version = "1.5.4" weakdeps = ["IntervalSets", "StaticArrays"] [deps.ConstructionBase.extensions] @@ -364,9 +364,9 @@ version = "0.1.0+0" [[deps.DiffEqBase]] deps = ["ArrayInterface", "ChainRulesCore", "DataStructures", "DocStringExtensions", "EnumX", "FastBroadcast", "ForwardDiff", "FunctionWrappers", "FunctionWrappersWrappers", "LinearAlgebra", "Logging", "Markdown", "MuladdMacro", "Parameters", "PreallocationTools", "Printf", "RecursiveArrayTools", "Reexport", "Requires", "SciMLBase", "SciMLOperators", "Setfield", "SparseArrays", "Static", "StaticArraysCore", "Statistics", "Tricks", "TruncatedStacktraces", "ZygoteRules"] -git-tree-sha1 = "df8638dbfa03d1b336c410e23a9dfbf89cb53937" +git-tree-sha1 = "dee066b8dce741815729f5973b6db757416948b7" uuid = "2b5f629d-d688-5b77-993f-72d75c75574e" -version = "6.128.2" +version = "6.128.4" [deps.DiffEqBase.extensions] DiffEqBaseDistributionsExt = "Distributions" @@ -644,10 +644,10 @@ uuid = "88fa7841-ef32-4516-bb70-c6ec135699d9" version = "0.1.0" [[deps.Glib_jll]] -deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE2_jll", "Pkg", "Zlib_jll"] -git-tree-sha1 = "d3b3624125c1474292d0d8ed0f65554ac37ddb23" +deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE2_jll", "Zlib_jll"] +git-tree-sha1 = "e94c92c7bf4819685eb80186d51c43e71d4afa17" uuid = "7746bdde-850d-59dc-9ae8-88ece973131d" -version = "2.74.0+2" +version = "2.76.5+0" [[deps.Graphite2_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -674,9 +674,9 @@ version = "1.12.2+2" [[deps.HTTP]] deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"] -git-tree-sha1 = "cb56ccdd481c0dd7f975ad2b3b62d9eda088f7e2" +git-tree-sha1 = "19e974eced1768fb46fd6020171f2cec06b1edb5" uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "1.9.14" +version = "1.9.15" [[deps.HarfBuzz_jll]] deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"] @@ -1136,9 +1136,9 @@ version = "1.4.1" [[deps.OpenSSL_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl"] -git-tree-sha1 = "bbb5c2115d63c2f1451cb70e5ef75e8fe4707019" +git-tree-sha1 = "a12e56c72edee3ce6b96667745e6cbbe5498f200" uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" -version = "1.1.22+0" +version = "1.1.23+0" [[deps.OpenSpecFun_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] @@ -1324,17 +1324,19 @@ version = "0.6.12" [[deps.RecursiveArrayTools]] deps = ["Adapt", "ArrayInterface", "DocStringExtensions", "GPUArraysCore", "IteratorInterfaceExtensions", "LinearAlgebra", "RecipesBase", "Requires", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables"] -git-tree-sha1 = "7ed35fb5f831aaf09c2d7c8736d44667a1afdcb0" +git-tree-sha1 = "9dbbf698bdd943fbf380f81bb4c365bc76287dc3" uuid = "731186ca-8d62-57ce-b412-fbd966d074cd" -version = "2.38.7" +version = "2.38.9" [deps.RecursiveArrayTools.extensions] RecursiveArrayToolsMeasurementsExt = "Measurements" + RecursiveArrayToolsMonteCarloMeasurementsExt = "MonteCarloMeasurements" RecursiveArrayToolsTrackerExt = "Tracker" RecursiveArrayToolsZygoteExt = "Zygote" [deps.RecursiveArrayTools.weakdeps] Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" + MonteCarloMeasurements = "0987c9cc-fe09-11e8-30f0-b96dd679fdca" Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" @@ -1378,9 +1380,9 @@ version = "0.1.0" [[deps.SciMLBase]] deps = ["ADTypes", "ArrayInterface", "ChainRulesCore", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables", "TruncatedStacktraces", "ZygoteRules"] -git-tree-sha1 = "54b005258bb5ee4b6fd0f440b528e7b7af4c9975" +git-tree-sha1 = "c0781c7ebb65776e9770d333b5e191d20dd45fcf" uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462" -version = "1.96.2" +version = "1.97.0" [deps.SciMLBase.extensions] ZygoteExt = "Zygote" @@ -1466,9 +1468,9 @@ weakdeps = ["OffsetArrays", "StaticArrays"] [[deps.StaticArrays]] deps = ["LinearAlgebra", "Random", "StaticArraysCore"] -git-tree-sha1 = "9cabadf6e7cd2349b6cf49f1915ad2028d65e881" +git-tree-sha1 = "51621cca8651d9e334a659443a74ce50a3b6dfab" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.6.2" +version = "1.6.3" weakdeps = ["Statistics"] [deps.StaticArrays.extensions] diff --git a/src/ClimaLSM.jl b/src/ClimaLSM.jl index 6bd9861f42..dd0758f302 100644 --- a/src/ClimaLSM.jl +++ b/src/ClimaLSM.jl @@ -4,7 +4,8 @@ using DocStringExtensions using ClimaCore import ClimaCore: Fields, Spaces - +import SciMLBase +import ClimaTimeSteppers as CTS include("shared_utilities/Parameters.jl") import .Parameters as LSMP diff --git a/src/shared_utilities/implicit_tendencies.jl b/src/shared_utilities/implicit_tendencies.jl index 104d44087b..5f727a9c5d 100644 --- a/src/shared_utilities/implicit_tendencies.jl +++ b/src/shared_utilities/implicit_tendencies.jl @@ -1,32 +1,7 @@ -export make_tendency_jacobian, - make_update_jacobian, AbstractTridiagonalW, ∂tendencyBC∂Y +export make_update_jacobian, make_jacobian, AbstractTridiagonalW, ∂tendencyBC∂Y - -""" - make_tendency_jacobian(model::AbstractModel) - -Creates and returns a function which updates the auxiliary -variables `p` in place and then updates the entries of the -Jacobian matrix `W` for the `model` in place. - -The default is that no updates are required, no implicit tendency is -present, and hence the timestepping is entirely explicit. - -Note that the returned function `tendency_jacobian!` should be -used as `Wfact!` in `ClimaTimeSteppers.jl` and `SciMLBase.jl`. """ -function make_tendency_jacobian(model::AbstractModel) - update_aux! = make_update_aux(model) - update_jacobian! = make_update_jacobian(model) - function tendency_jacobian!(W, Y, p, dtγ, t) - update_aux!(p, Y, t) - update_jacobian!(W, Y, p, dtγ, t) - end - return tendency_jacobian! -end - -""" - make_update_jacobian(model::AbstractModel) + make_update_jacobian(model::AbstractImExModel) Creates and returns a function which updates the entries of the Jacobian matrix `W` in place. @@ -37,12 +12,12 @@ should be given by `W_{i,j}! = ∂T!_i/∂Y_j`, where `Y_j` is the `j-th` state variable and `T!_i` is the implicit tendency of the `i-th` state variable. -The default is that no updates are required, no implicit tendency is -present, and hence the timestepping is entirely explicit. +This is a stub function to be extended for concrete instances of +AbstractImExModels. """ -function make_update_jacobian(model::AbstractModel) +function make_update_jacobian(model::AbstractImExModel) function update_jacobian!(W, Y, p, dtγ, t) end - return update_jacobian + return update_jacobian! end """ @@ -70,3 +45,25 @@ An abstract type for tridiagonal Jacobian matrices. abstract type AbstractTridiagonalW end Base.similar(w::AbstractTridiagonalW) = w + +""" + make_jacobian(model::AbstractImExModel, Y::ClimaCore.Fields.FieldVector; + transform::Bool = false)::Union{Nothing,AbstractTridiagonalW} + +Creates and returns a struct with allocated memory +for storing the Jacobian entries. + +If the implicit tendency function is given by +`T!(dY, Y, p, t) = make_implicit_tendency(model)`, the Jacobian +should be given by `W_{i,j}! = ∂T!_i/∂Y_j`, where `Y_j` is the +`j-th` state variable +and `T!_i` is the implicit tendency of the `i-th` state variable. + +This is a stub function to be extended for concrete instances of +AbstractImExModels. +""" +make_jacobian( + model::AbstractImExModel, + Y::ClimaCore.Fields.FieldVector; + transform::Bool = false, +)::Union{Nothing, AbstractTridiagonalW} = nothing diff --git a/src/shared_utilities/models.jl b/src/shared_utilities/models.jl index 4cad532ab4..0df1fee66b 100644 --- a/src/shared_utilities/models.jl +++ b/src/shared_utilities/models.jl @@ -16,7 +16,8 @@ export AbstractModel, auxiliary_types, make_set_initial_aux_state, name, - domain_name + domain_name, + get_ClimaODEFunction import .Domains: coordinates ## Default methods for all models - to be in a seperate module at some point. @@ -314,3 +315,32 @@ function initialize(model::AbstractModel{FT}) where {FT} p = initialize_auxiliary(model, coords) return Y, p, coords end + + +function get_ClimaODEFunction( + model::AbstractImExModel, + Y::ClimaCore.Fields.FieldVector; + transform = false, +) + imp_tendency! = make_imp_tendency(model) + exp_tendency! = make_exp_tendency(model) + dss! = ClimaLSM.dss! + update_jacobian! = ClimaLSM.make_update_jacobian(model) + jac_prototype = ClimaLSM.make_jacobian(model, Y; transform = transform) + jac_kwargs = (; jac_prototype = jac_prototype, Wfact = update_jacobian!) + return CTS.ClimaODEFunction( + T_exp! = exp_tendency!, + T_imp! = SciMLBase.ODEFunction(imp_tendency!; jac_kwargs...), + dss! = dss!, + ) +end + +function get_ClimaODEFunction(model::AbstractExpModel) + exp_tendency! = make_exp_tendency(model) + dss! = ClimaLSM.dss! + return CTS.ClimaODEFunction( + T_exp! = exp_tendency!, + T_imp! = nothing, + dss! = dss!, + ) +end diff --git a/src/standalone/Soil/Soil.jl b/src/standalone/Soil/Soil.jl index e392ecee16..d5bd2315de 100644 --- a/src/standalone/Soil/Soil.jl +++ b/src/standalone/Soil/Soil.jl @@ -71,6 +71,7 @@ import ClimaLSM: make_compute_exp_tendency, make_compute_imp_tendency, make_update_jacobian, + make_jacobian, prognostic_vars, auxiliary_vars, name, diff --git a/src/standalone/Soil/rre.jl b/src/standalone/Soil/rre.jl index 35c2bd0b73..ffdfb23f81 100644 --- a/src/standalone/Soil/rre.jl +++ b/src/standalone/Soil/rre.jl @@ -348,6 +348,11 @@ function RichardsTridiagonalW( ) end +ClimaLSM.make_jacobian( + model::RichardsModel, + Y::ClimaCore.Fields.FieldVector; + transform = false, +) = RichardsTridiagonalW(Y; transform = transform) """ ClimaLSM.make_update_jacobian(model::RichardsModel) From b80ca0ff40d1a2df9cf3ee89bb5af53d4f1901b2 Mon Sep 17 00:00:00 2001 From: kmdeck Date: Wed, 13 Sep 2023 12:32:25 -0700 Subject: [PATCH 3/5] updated experiments --- .../ozark/conservation/ozark_conservation.jl | 15 +------ .../integrated/ozark/hydrology_only/ozark.jl | 20 +-------- experiments/integrated/ozark/ozark.jl | 10 +---- .../standalone/Biogeochemistry/experiment.jl | 9 +--- experiments/standalone/Soil/evaporation.jl | 10 +---- .../standalone/Soil/richards_comparison.jl | 41 ++----------------- .../standalone/Soil/water_conservation.jl | 39 +++--------------- 7 files changed, 19 insertions(+), 125 deletions(-) diff --git a/experiments/integrated/ozark/conservation/ozark_conservation.jl b/experiments/integrated/ozark/conservation/ozark_conservation.jl index 29b0635eb7..34d948b0ab 100644 --- a/experiments/integrated/ozark/conservation/ozark_conservation.jl +++ b/experiments/integrated/ozark/conservation/ozark_conservation.jl @@ -168,8 +168,6 @@ land = SoilCanopyModel{FT}(; canopy_model_args = canopy_model_args, ) Y, p, cds = initialize(land) -exp_tendency! = make_exp_tendency(land) - #Initial conditions Y.soil.ϑ_l = SWC[1 + Int(round(t0 / 1800))] # Get soil water content at t0 # recalling that the data is in intervals of 1800 seconds. Both the data @@ -211,17 +209,8 @@ sv = (; saveval = Array{NamedTuple}(undef, length(saveat)), ) cb = ClimaLSM.NonInterpSavingCallback(sv, saveat) - -prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction( - T_exp! = exp_tendency!, - dss! = ClimaLSM.dss!, - T_imp! = nothing, - ), - Y, - (t0, tf), - p, -); +clima_ode_function = ClimaLSM.get_ClimaODEFunction(land) +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); sol = SciMLBase.solve( prob, ode_algo; diff --git a/experiments/integrated/ozark/hydrology_only/ozark.jl b/experiments/integrated/ozark/hydrology_only/ozark.jl index 13a7168a19..b1b0ceca5c 100644 --- a/experiments/integrated/ozark/hydrology_only/ozark.jl +++ b/experiments/integrated/ozark/hydrology_only/ozark.jl @@ -158,8 +158,6 @@ land = SoilPlantHydrologyModel{FT}(; canopy_model_args = canopy_model_args, ) Y, p, cds = initialize(land) -exp_tendency! = make_exp_tendency(land) -imp_tendency! = make_imp_tendency(land) #Initial conditions Y.soil.ϑ_l = SWC[Int(round(t0 / 1800))] # Get soil water content at t0 @@ -182,9 +180,6 @@ end set_initial_aux_state! = make_set_initial_aux_state(land) set_initial_aux_state!(p, Y, t0); -# Set up timestepper and jacobian for soil -update_jacobian! = make_update_jacobian(land.soil) - ode_algo = CTS.IMEXAlgorithm( timestepper, CTS.NewtonsMethod( @@ -194,8 +189,6 @@ ode_algo = CTS.IMEXAlgorithm( ), ) -W = RichardsTridiagonalW(Y) -jac_kwargs = (; jac_prototype = W, Wfact = update_jacobian!) # Simulation sv = (; @@ -203,17 +196,8 @@ sv = (; saveval = Array{NamedTuple}(undef, length(saveat)), ) cb = ClimaLSM.NonInterpSavingCallback(sv, saveat) - -prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction( - T_exp! = exp_tendency!, - T_imp! = SciMLBase.ODEFunction(imp_tendency!; jac_kwargs...), - dss! = ClimaLSM.dss!, - ), - Y, - (t0, tf), - p, -) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(land, Y) +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p) sol = SciMLBase.solve( prob, ode_algo; diff --git a/experiments/integrated/ozark/ozark.jl b/experiments/integrated/ozark/ozark.jl index 4f382f684e..83834a8917 100644 --- a/experiments/integrated/ozark/ozark.jl +++ b/experiments/integrated/ozark/ozark.jl @@ -165,7 +165,6 @@ land = SoilCanopyModel{FT}(; canopy_model_args = canopy_model_args, ) Y, p, cds = initialize(land) -exp_tendency! = make_exp_tendency(land) #Initial conditions Y.soil.ϑ_l = SWC[1 + Int(round(t0 / 1800))] # Get soil water content at t0 @@ -208,13 +207,8 @@ sv = (; saveval = Array{NamedTuple}(undef, length(saveat)), ) cb = ClimaLSM.NonInterpSavingCallback(sv, saveat) - -prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = ClimaLSM.dss!), - Y, - (t0, tf), - p, -); +clima_ode_function = ClimaLSM.get_ClimaODEFunction(land) +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); sol = SciMLBase.solve( prob, ode_algo; diff --git a/experiments/standalone/Biogeochemistry/experiment.jl b/experiments/standalone/Biogeochemistry/experiment.jl index 47f524ef08..20ad85292f 100644 --- a/experiments/standalone/Biogeochemistry/experiment.jl +++ b/experiments/standalone/Biogeochemistry/experiment.jl @@ -137,7 +137,7 @@ init_soil!(Y, z, model.soil.parameters) init_co2!(Y, z) t0 = FT(0.0) set_initial_aux_state!(p, Y, t0); -Soil_bio_exp_tendency! = make_exp_tendency(model) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(model) tf = FT(10000) dt = FT(10) @@ -152,12 +152,7 @@ saved_values = (; ) cb = ClimaLSM.NonInterpSavingCallback(saved_values, saveat) -prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = Soil_bio_exp_tendency!, dss! = ClimaLSM.dss!), - Y, - (t0, tf), - p, -) +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p) sol = SciMLBase.solve(prob, ode_algo; dt = dt, callback = cb) # Animation diff --git a/experiments/standalone/Soil/evaporation.jl b/experiments/standalone/Soil/evaporation.jl index 5444b04ee9..bf705f7b29 100644 --- a/experiments/standalone/Soil/evaporation.jl +++ b/experiments/standalone/Soil/evaporation.jl @@ -154,16 +154,10 @@ set_initial_aux_state!(p, Y, t0); # Timestepping: dt = FT(1) -soil_exp_tendency! = make_exp_tendency(soil) timestepper = CTS.RK4() ode_algo = CTS.ExplicitAlgorithm(timestepper) - -prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction(T_exp! = soil_exp_tendency!, dss! = ClimaLSM.dss!), - Y, - (t0, tf), - p, -) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil) +prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p) sol = SciMLBase.solve(prob, ode_algo; dt = dt, saveat = 3600) (; ν, θ_r, d_ds) = soil.parameters diff --git a/experiments/standalone/Soil/richards_comparison.jl b/experiments/standalone/Soil/richards_comparison.jl index 4d23c0199f..7099ef1349 100644 --- a/experiments/standalone/Soil/richards_comparison.jl +++ b/experiments/standalone/Soil/richards_comparison.jl @@ -50,10 +50,6 @@ include(joinpath(pkgdir(ClimaLSM), "parameters", "create_parameters.jl")) # specify ICs Y.soil.ϑ_l .= FT(0.24) - exp_tendency! = make_exp_tendency(soil) - imp_tendency! = ClimaLSM.make_imp_tendency(soil) - update_jacobian! = ClimaLSM.make_update_jacobian(soil) - t0 = FT(0) set_initial_aux_state!(p, Y, t0) tf = FT(1e6) @@ -70,21 +66,8 @@ include(joinpath(pkgdir(ClimaLSM), "parameters", "create_parameters.jl")) convergence_checker = conv_checker, ), ) - - # set up jacobian info - jac_kwargs = - (; jac_prototype = RichardsTridiagonalW(Y), Wfact = update_jacobian!) - - prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction( - T_exp! = exp_tendency!, - T_imp! = SciMLBase.ODEFunction(imp_tendency!; jac_kwargs...), - dss! = ClimaLSM.dss!, - ), - Y, - (t0, tf), - p, - ) + clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil, Y) + prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p) sol = SciMLBase.solve(prob, ode_algo; dt = dt, saveat = 10000) N = length(sol.t) @@ -144,10 +127,6 @@ end # specify ICs Y.soil.ϑ_l .= FT(0.1) - exp_tendency! = make_exp_tendency(soil) - imp_tendency! = ClimaLSM.make_imp_tendency(soil) - update_jacobian! = ClimaLSM.make_update_jacobian(soil) - t0 = FT(0) set_initial_aux_state!(p, Y, t0) tf = FT(60 * 60 * 0.8) @@ -165,20 +144,8 @@ end convergence_checker = conv_checker, ), ) - # set up jacobian info - jac_kwargs = - (; jac_prototype = RichardsTridiagonalW(Y), Wfact = update_jacobian!) - - prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction( - T_exp! = exp_tendency!, - T_imp! = SciMLBase.ODEFunction(imp_tendency!; jac_kwargs...), - dss! = ClimaLSM.dss!, - ), - Y, - (t0, tf), - p, - ) + clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil, Y) + prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p) sol = SciMLBase.solve(prob, ode_algo; dt = dt, saveat = 60 * dt) N = length(sol.t) diff --git a/experiments/standalone/Soil/water_conservation.jl b/experiments/standalone/Soil/water_conservation.jl index 02158be956..0cffd81ce4 100644 --- a/experiments/standalone/Soil/water_conservation.jl +++ b/experiments/standalone/Soil/water_conservation.jl @@ -84,11 +84,7 @@ soil = Soil.RichardsModel{FT}(; boundary_conditions = boundary_fluxes, sources = sources, ) - -exp_tendency! = make_exp_tendency(soil) set_initial_aux_state! = make_set_initial_aux_state(soil); -imp_tendency! = make_imp_tendency(soil) -update_jacobian! = make_update_jacobian(soil) rmses = Array{FT}(undef, length(dts)) mass_errors = Array{FT}(undef, length(dts)) @@ -99,19 +95,8 @@ for i in eachindex(dts) @. Y.soil.ϑ_l = FT(0.24) set_initial_aux_state!(p, Y, FT(0.0)) - jac_kwargs = - (; jac_prototype = RichardsTridiagonalW(Y), Wfact = update_jacobian!) - - prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction( - T_exp! = exp_tendency!, - T_imp! = SciMLBase.ODEFunction(imp_tendency!; jac_kwargs...), - dss! = ClimaLSM.dss!, - ), - Y, - (t_start, t_end), - p, - ) + clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil, Y) + prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t_start, t_end), p) sol = SciMLBase.solve(prob, ode_algo; dt = dt, saveat = dt) @@ -187,11 +172,7 @@ soil_dirichlet = Soil.RichardsModel{FT}(; sources = sources, ) -exp_tendency! = make_exp_tendency(soil_dirichlet) set_initial_aux_state! = make_set_initial_aux_state(soil_dirichlet); -imp_tendency! = make_imp_tendency(soil_dirichlet) -update_jacobian! = make_update_jacobian(soil_dirichlet) -update_aux! = make_update_aux(soil_dirichlet) rmses_dirichlet = Array{FT}(undef, length(dts)) mass_errors_dirichlet = Array{FT}(undef, length(dts)) @@ -202,19 +183,9 @@ for i in eachindex(dts) @. Y.soil.ϑ_l = FT(0.24) set_initial_aux_state!(p, Y, FT(0.0)) - jac_kwargs = - (; jac_prototype = RichardsTridiagonalW(Y), Wfact = update_jacobian!) - - prob = SciMLBase.ODEProblem( - CTS.ClimaODEFunction( - T_exp! = exp_tendency!, - T_imp! = SciMLBase.ODEFunction(imp_tendency!; jac_kwargs...), - dss! = ClimaLSM.dss!, - ), - Y, - (t_start, t_end), - p, - ) + clima_ode_function = ClimaLSM.get_ClimaODEFunction(soiil_dirichlet, Y) + + prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t_start, t_end), p) sol = SciMLBase.solve(prob, ode_algo; dt = dt, saveat = dt) # Calculate water mass balance over entire simulation From f227d3098fcf6888473b4b0997dd443fa4e772d6 Mon Sep 17 00:00:00 2001 From: kmdeck Date: Wed, 13 Sep 2023 13:47:32 -0700 Subject: [PATCH 4/5] unify arguments --- Project.toml | 1 + docs/tutorials/Bucket/bucket_tutorial.jl | 2 +- docs/tutorials/Canopy/canopy_tutorial.jl | 2 +- docs/tutorials/Canopy/soil_canopy_tutorial.jl | 2 +- docs/tutorials/Soil/freezing_front.jl | 2 +- docs/tutorials/Soil/soil_energy_hydrology.jl | 3 +-- .../ozark/conservation/ozark_conservation.jl | 2 +- experiments/integrated/ozark/ozark.jl | 2 +- .../standalone/Biogeochemistry/experiment.jl | 2 +- experiments/standalone/Soil/evaporation.jl | 2 +- src/shared_utilities/implicit_tendencies.jl | 8 ++++---- src/shared_utilities/models.jl | 16 ++++------------ 12 files changed, 18 insertions(+), 26 deletions(-) diff --git a/Project.toml b/Project.toml index adbb244dec..9aa59f472e 100644 --- a/Project.toml +++ b/Project.toml @@ -28,6 +28,7 @@ CFTime = "0.1" ClimaComms = "0.3, 0.4, 0.5" ClimaCore = "0.10.44" ClimaCoreTempestRemap = "0.3.5" +ClimaTimeSteppers = "0.7" DocStringExtensions = "0.8, 0.9" IntervalSets = "0.5, 0.6, 0.7" JLD2 = "0.4" diff --git a/docs/tutorials/Bucket/bucket_tutorial.jl b/docs/tutorials/Bucket/bucket_tutorial.jl index 6d8afad138..6793649706 100644 --- a/docs/tutorials/Bucket/bucket_tutorial.jl +++ b/docs/tutorials/Bucket/bucket_tutorial.jl @@ -308,7 +308,7 @@ ode_algo = CTS.ExplicitAlgorithm(timestepper); # To set up the ClimaODEFunction which will be executed to step the # system explicitly in time, we call `get_ClimaODEFunction`: -clima_ode_function = ClimaLSM.get_ClimaODEFunction(model) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(model, Y) # Then we can set up the simulation and solve it: prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); diff --git a/docs/tutorials/Canopy/canopy_tutorial.jl b/docs/tutorials/Canopy/canopy_tutorial.jl index d2d3025374..cd57f71786 100644 --- a/docs/tutorials/Canopy/canopy_tutorial.jl +++ b/docs/tutorials/Canopy/canopy_tutorial.jl @@ -302,7 +302,7 @@ ode_algo = CTS.ExplicitAlgorithm(timestepper) # To set up the ClimaODEFunction which will be executed to step the # system explicitly in time, we call `get_ClimaODEFunction`: -clima_ode_function = ClimaLSM.get_ClimaODEFunction(canopy) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(canopy, Y) prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); # Now, we can solve the problem and store the model data in the saveat array, diff --git a/docs/tutorials/Canopy/soil_canopy_tutorial.jl b/docs/tutorials/Canopy/soil_canopy_tutorial.jl index ee20ed8c9e..3a8b86fa02 100644 --- a/docs/tutorials/Canopy/soil_canopy_tutorial.jl +++ b/docs/tutorials/Canopy/soil_canopy_tutorial.jl @@ -376,7 +376,7 @@ cb = ClimaLSM.NonInterpSavingCallback(sv, saveat); # To set up the ClimaODEFunction which will be executed to step the # system explicitly in time, we call `get_ClimaODEFunction`: -clima_ode_function = ClimaLSM.get_ClimaODEFunction(land) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(land, Y) prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); # Now, wrap the problem, algorithm, timestep, and callback together diff --git a/docs/tutorials/Soil/freezing_front.jl b/docs/tutorials/Soil/freezing_front.jl index 13eeef2ccf..1e8c31ad86 100644 --- a/docs/tutorials/Soil/freezing_front.jl +++ b/docs/tutorials/Soil/freezing_front.jl @@ -219,7 +219,7 @@ set_initial_aux_state! = make_set_initial_aux_state(soil); set_initial_aux_state!(p, Y, t0); # To set up the ClimaODEFunction which will be executed to step the # system explicitly in time, we call `get_ClimaODEFunction`: -clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil, Y) prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); diff --git a/docs/tutorials/Soil/soil_energy_hydrology.jl b/docs/tutorials/Soil/soil_energy_hydrology.jl index 9675752476..9c963dd066 100644 --- a/docs/tutorials/Soil/soil_energy_hydrology.jl +++ b/docs/tutorials/Soil/soil_energy_hydrology.jl @@ -241,7 +241,6 @@ function init_soil!(Y, z, params) end init_soil!(Y, coords.z, soil.parameters); -<< << << < HEAD # We choose the initial and final simulation times: t0 = FT(0) @@ -263,7 +262,7 @@ ode_algo = CTS.ExplicitAlgorithm(timestepper); dt = FT(30.0); # To set up the ClimaODEFunction which will be executed to step the # system explicitly in time, we call `get_ClimaODEFunction`: -clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil, Y) prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); # By default, the `solve` command diff --git a/experiments/integrated/ozark/conservation/ozark_conservation.jl b/experiments/integrated/ozark/conservation/ozark_conservation.jl index 34d948b0ab..5046651bf8 100644 --- a/experiments/integrated/ozark/conservation/ozark_conservation.jl +++ b/experiments/integrated/ozark/conservation/ozark_conservation.jl @@ -209,7 +209,7 @@ sv = (; saveval = Array{NamedTuple}(undef, length(saveat)), ) cb = ClimaLSM.NonInterpSavingCallback(sv, saveat) -clima_ode_function = ClimaLSM.get_ClimaODEFunction(land) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(land, Y) prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); sol = SciMLBase.solve( prob, diff --git a/experiments/integrated/ozark/ozark.jl b/experiments/integrated/ozark/ozark.jl index 83834a8917..5ac7de580b 100644 --- a/experiments/integrated/ozark/ozark.jl +++ b/experiments/integrated/ozark/ozark.jl @@ -207,7 +207,7 @@ sv = (; saveval = Array{NamedTuple}(undef, length(saveat)), ) cb = ClimaLSM.NonInterpSavingCallback(sv, saveat) -clima_ode_function = ClimaLSM.get_ClimaODEFunction(land) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(land, Y) prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p); sol = SciMLBase.solve( prob, diff --git a/experiments/standalone/Biogeochemistry/experiment.jl b/experiments/standalone/Biogeochemistry/experiment.jl index 20ad85292f..51f738b63f 100644 --- a/experiments/standalone/Biogeochemistry/experiment.jl +++ b/experiments/standalone/Biogeochemistry/experiment.jl @@ -137,7 +137,7 @@ init_soil!(Y, z, model.soil.parameters) init_co2!(Y, z) t0 = FT(0.0) set_initial_aux_state!(p, Y, t0); -clima_ode_function = ClimaLSM.get_ClimaODEFunction(model) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(model, Y) tf = FT(10000) dt = FT(10) diff --git a/experiments/standalone/Soil/evaporation.jl b/experiments/standalone/Soil/evaporation.jl index bf705f7b29..1b5531074e 100644 --- a/experiments/standalone/Soil/evaporation.jl +++ b/experiments/standalone/Soil/evaporation.jl @@ -156,7 +156,7 @@ set_initial_aux_state!(p, Y, t0); dt = FT(1) timestepper = CTS.RK4() ode_algo = CTS.ExplicitAlgorithm(timestepper) -clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil) +clima_ode_function = ClimaLSM.get_ClimaODEFunction(soil, Y) prob = SciMLBase.ODEProblem(clima_ode_function, Y, (t0, tf), p) sol = SciMLBase.solve(prob, ode_algo; dt = dt, saveat = 3600) diff --git a/src/shared_utilities/implicit_tendencies.jl b/src/shared_utilities/implicit_tendencies.jl index 5f727a9c5d..b870a16861 100644 --- a/src/shared_utilities/implicit_tendencies.jl +++ b/src/shared_utilities/implicit_tendencies.jl @@ -1,7 +1,7 @@ export make_update_jacobian, make_jacobian, AbstractTridiagonalW, ∂tendencyBC∂Y """ - make_update_jacobian(model::AbstractImExModel) + make_update_jacobian(model::AbstractModel) Creates and returns a function which updates the entries of the Jacobian matrix `W` in place. @@ -15,7 +15,7 @@ and `T!_i` is the implicit tendency of the `i-th` state variable. This is a stub function to be extended for concrete instances of AbstractImExModels. """ -function make_update_jacobian(model::AbstractImExModel) +function make_update_jacobian(model::AbstractModel) function update_jacobian!(W, Y, p, dtγ, t) end return update_jacobian! end @@ -47,7 +47,7 @@ abstract type AbstractTridiagonalW end Base.similar(w::AbstractTridiagonalW) = w """ - make_jacobian(model::AbstractImExModel, Y::ClimaCore.Fields.FieldVector; + make_jacobian(model::AbstractModel, Y::ClimaCore.Fields.FieldVector; transform::Bool = false)::Union{Nothing,AbstractTridiagonalW} Creates and returns a struct with allocated memory @@ -63,7 +63,7 @@ This is a stub function to be extended for concrete instances of AbstractImExModels. """ make_jacobian( - model::AbstractImExModel, + model::AbstractModel, Y::ClimaCore.Fields.FieldVector; transform::Bool = false, )::Union{Nothing, AbstractTridiagonalW} = nothing diff --git a/src/shared_utilities/models.jl b/src/shared_utilities/models.jl index 0df1fee66b..02f69011b5 100644 --- a/src/shared_utilities/models.jl +++ b/src/shared_utilities/models.jl @@ -316,9 +316,11 @@ function initialize(model::AbstractModel{FT}) where {FT} return Y, p, coords end - +""" + eventually split into a method for AbstractImExModel, AbstractExpModel, and AbstractLandModel? +""" function get_ClimaODEFunction( - model::AbstractImExModel, + model::AbstractModel, Y::ClimaCore.Fields.FieldVector; transform = false, ) @@ -334,13 +336,3 @@ function get_ClimaODEFunction( dss! = dss!, ) end - -function get_ClimaODEFunction(model::AbstractExpModel) - exp_tendency! = make_exp_tendency(model) - dss! = ClimaLSM.dss! - return CTS.ClimaODEFunction( - T_exp! = exp_tendency!, - T_imp! = nothing, - dss! = dss!, - ) -end From 2249735efd1cf52566a8e4eda0d0dd2a1d3476c4 Mon Sep 17 00:00:00 2001 From: kmdeck Date: Wed, 13 Sep 2023 14:00:12 -0700 Subject: [PATCH 5/5] update test --- test/shared_utilities/implicit_timestepping/richards_model.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/shared_utilities/implicit_timestepping/richards_model.jl b/test/shared_utilities/implicit_timestepping/richards_model.jl index 350ee643ad..155c6b68d0 100644 --- a/test/shared_utilities/implicit_timestepping/richards_model.jl +++ b/test/shared_utilities/implicit_timestepping/richards_model.jl @@ -54,7 +54,7 @@ include(joinpath(pkgdir(ClimaLSM), "parameters", "create_parameters.jl")) # we want to test that it is updated correctly in # the jacobian correctly. W = RichardsTridiagonalW(Y) - Wfact! = make_tendency_jacobian(soil) + Wfact! = make_update_jacobian(soil) dtγ = FT(1.0) Wfact!(W, Y, p, dtγ, FT(0.0)) @@ -158,7 +158,7 @@ end # we want to test that it is updated correctly in # the jacobian correctly. W = RichardsTridiagonalW(Y) - Wfact! = make_tendency_jacobian(soil) + Wfact! = make_update_jacobian(soil) dtγ = FT(1.0) Wfact!(W, Y, p, dtγ, FT(0.0))