From f227d3098fcf6888473b4b0997dd443fa4e772d6 Mon Sep 17 00:00:00 2001 From: kmdeck Date: Wed, 13 Sep 2023 13:47:32 -0700 Subject: [PATCH] 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