Skip to content

Commit

Permalink
renaming jacobian methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kmdeck committed Jul 2, 2024
1 parent cfa1030 commit 332a73b
Show file tree
Hide file tree
Showing 28 changed files with 99 additions and 132 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Add base global soil canopy run to benchmark and experiments
- PR [#669] adds topmodel runoff
Soil implicit solver
- PR [#678] updates Jacobian for soil energy

Misc
- PR [#685] Renames jacobian update functions to align with our convention
for tendency functions
v0.12.4
--------
- Fix various canopy flux bugs
Expand Down
4 changes: 2 additions & 2 deletions docs/src/APIs/shared_utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ ClimaLand.diffusive_flux
ClimaLand.boundary_vars
ClimaLand.boundary_var_domain_names
ClimaLand.boundary_var_types
ClimaLand.make_tendency_jacobian
ClimaLand.make_update_jacobian
ClimaLand.make_jacobian
ClimaLand.make_compute_jacobian
ClimaLand.set_dfluxBCdY!
ClimaLand.get_drivers
```
Expand Down
8 changes: 3 additions & 5 deletions docs/tutorials/integrated/soil_canopy_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,9 @@ land = SoilCanopyModel{FT}(;
Y, p, coords = initialize(land);
exp_tendency! = make_exp_tendency(land);
imp_tendency! = make_imp_tendency(land);
tendency_jacobian! = make_tendency_jacobian(land);
jac_kwargs = (;
jac_prototype = ClimaLand.ImplicitEquationJacobian(Y),
Wfact = tendency_jacobian!,
);
jacobian! = make_jacobian(land);
jac_kwargs =
(; jac_prototype = ClimaLand.ImplicitEquationJacobian(Y), Wfact = jacobian!);

# We need to provide initial conditions for the soil and canopy hydraulics
# models:
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/standalone/Soil/evaporation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ set_initial_cache!(p, Y, t0);
# Define the tendency functions
exp_tendency! = make_exp_tendency(soil)
imp_tendency! = make_imp_tendency(soil);
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil);
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!);
jacobian! = ClimaLand.make_jacobian(soil);
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!);

timestepper = CTS.ARS111();
ode_algo = CTS.IMEXAlgorithm(
Expand Down
15 changes: 6 additions & 9 deletions docs/tutorials/standalone/Soil/evaporation_gilat_loess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ set_initial_cache!(p, Y, t0);
# Timestepping:
exp_tendency! = make_exp_tendency(soil)
imp_tendency! = make_imp_tendency(soil);
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil);
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!);
jacobian! = ClimaLand.make_jacobian(soil);
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!);

timestepper = CTS.ARS111();
ode_algo = CTS.IMEXAlgorithm(
Expand Down Expand Up @@ -224,7 +223,7 @@ set_initial_cache!(p, Y, t0)
soil_exp_tendency! = make_exp_tendency(soil)
exp_tendency! = make_exp_tendency(soil)
imp_tendency! = make_imp_tendency(soil);
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil);
jacobian! = ClimaLand.make_jacobian(soil);
timestepper = CTS.ARS111();
ode_algo = CTS.IMEXAlgorithm(
timestepper,
Expand All @@ -233,8 +232,7 @@ ode_algo = CTS.IMEXAlgorithm(
update_j = CTS.UpdateEvery(CTS.NewNewtonIteration),
),
);
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!);
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!);
prob = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(
T_exp! = exp_tendency!,
Expand Down Expand Up @@ -290,7 +288,7 @@ set_initial_cache! = make_set_initial_cache(soil)
set_initial_cache!(p, Y, t0)
exp_tendency! = make_exp_tendency(soil)
imp_tendency! = make_imp_tendency(soil);
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil);
jacobian! = ClimaLand.make_jacobian(soil);
timestepper = CTS.ARS111();
ode_algo = CTS.IMEXAlgorithm(
timestepper,
Expand All @@ -299,8 +297,7 @@ ode_algo = CTS.IMEXAlgorithm(
update_j = CTS.UpdateEvery(CTS.NewNewtonIteration),
),
);
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!);
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!);
prob = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(
T_exp! = exp_tendency!,
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/standalone/Soil/freezing_front.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,8 @@ set_initial_cache!(p, Y, t0);
# Create the tendency function, and choose a timestep, and timestepper:
exp_tendency! = make_exp_tendency(soil)
imp_tendency! = make_imp_tendency(soil);
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil);
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!);
jacobian! = ClimaLand.make_jacobian(soil);
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!);

dt = Float64(100)

Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/standalone/Soil/layered_soil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ ode_algo = CTS.IMEXAlgorithm(
)
exp_tendency! = make_exp_tendency(soil)
imp_tendency! = make_imp_tendency(soil)
tendency_jacobian! = make_tendency_jacobian(soil)
jacobian! = make_jacobian(soil)

jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!)
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!)
prob = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(
T_exp! = exp_tendency!,
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/standalone/Soil/richards_equation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ soil = Soil.RichardsModel{FT}(;
# We also create the function which is used to update our Jacobian.
exp_tendency! = make_exp_tendency(soil);
imp_tendency! = ClimaLand.make_imp_tendency(soil);
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil);
jacobian! = ClimaLand.make_jacobian(soil);

# # Set up the simulation
# We can now initialize the prognostic and auxiliary variable vectors, and take
Expand Down Expand Up @@ -185,8 +185,7 @@ ode_algo = CTS.IMEXAlgorithm(
);

# Here we set up the information used for our Jacobian.
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!);
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!);

# And then we can solve the system of equations, using
# [SciMLBase.jl](https://github.com/SciML/SciMLBase.jl) and
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/standalone/Soil/soil_energy_hydrology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ soil = Soil.EnergyHydrology{FT}(;
# We also create the function which is used to update our Jacobian.
exp_tendency! = make_exp_tendency(soil);
imp_tendency! = make_imp_tendency(soil);
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil);
jacobian! = ClimaLand.make_jacobian(soil);

# # Set up the simulation
# We can now initialize the prognostic and auxiliary variable vectors, and take
Expand Down Expand Up @@ -261,8 +261,7 @@ ode_algo = CTS.IMEXAlgorithm(
),
);

jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!);
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!);

prob = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/standalone/Soil/sublimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ set_initial_cache!(p, Y, t0);
# Timestepping functions:
exp_tendency! = make_exp_tendency(soil)
imp_tendency! = make_imp_tendency(soil)
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil)
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!)
jacobian! = ClimaLand.make_jacobian(soil)
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!)

timestepper = CTS.ARS111()
ode_algo = CTS.IMEXAlgorithm(
Expand Down
8 changes: 3 additions & 5 deletions experiments/benchmarks/land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,12 @@ function setup_prob(t0, tf, Δt; nelements = (101, 15))
set_initial_cache! = make_set_initial_cache(land)
exp_tendency! = make_exp_tendency(land)
imp_tendency! = ClimaLand.make_imp_tendency(land)
tendency_jacobian! = ClimaLand.make_tendency_jacobian(land)
jacobian! = ClimaLand.make_jacobian(land)
set_initial_cache!(p, Y, t0)

# set up jacobian info
jac_kwargs = (;
jac_prototype = ImplicitEquationJacobian(Y),
Wfact = tendency_jacobian!,
)
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!)

prob = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(
Expand Down
6 changes: 3 additions & 3 deletions experiments/benchmarks/richards.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ using ClimaLand:
make_update_aux,
make_exp_tendency,
make_imp_tendency,
make_tendency_jacobian,
make_jacobian,
make_set_initial_cache

import Profile, ProfileCanvas
Expand Down Expand Up @@ -256,14 +256,14 @@ function setup_prob(t0, tf, Δt; nelements = (101, 15))
set_initial_cache! = make_set_initial_cache(model)
exp_tendency! = make_exp_tendency(model)
imp_tendency! = make_imp_tendency(model)
tendency_jacobian! = make_tendency_jacobian(model)
jacobian! = make_jacobian(model)

set_initial_cache!(p, Y, t0)

# set up jacobian info
jac_kwargs = (;
jac_prototype = ClimaLand.Soil.ImplicitEquationJacobian(Y),
Wfact = tendency_jacobian!,
Wfact = jacobian!,
)

prob = SciMLBase.ODEProblem(
Expand Down
8 changes: 3 additions & 5 deletions experiments/integrated/fluxnet/ozark_pft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,9 @@ land = SoilCanopyModel{FT}(;
Y, p, cds = initialize(land)
exp_tendency! = make_exp_tendency(land)
imp_tendency! = make_imp_tendency(land);
tendency_jacobian! = make_tendency_jacobian(land);
jac_kwargs = (;
jac_prototype = ClimaLand.ImplicitEquationJacobian(Y),
Wfact = tendency_jacobian!,
);
jacobian! = make_jacobian(land);
jac_kwargs =
(; jac_prototype = ClimaLand.ImplicitEquationJacobian(Y), Wfact = jacobian!);

#Initial conditions
Y.soil.ϑ_l =
Expand Down
8 changes: 3 additions & 5 deletions experiments/integrated/fluxnet/run_fluxnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,9 @@ land = SoilCanopyModel{FT}(;
Y, p, cds = initialize(land)
exp_tendency! = make_exp_tendency(land)
imp_tendency! = make_imp_tendency(land)
tendency_jacobian! = make_tendency_jacobian(land);
jac_kwargs = (;
jac_prototype = ClimaLand.ImplicitEquationJacobian(Y),
Wfact = tendency_jacobian!,
);
jacobian! = make_jacobian(land);
jac_kwargs =
(; jac_prototype = ClimaLand.ImplicitEquationJacobian(Y), Wfact = jacobian!);

#Initial conditions
Y.soil.ϑ_l =
Expand Down
5 changes: 2 additions & 3 deletions experiments/integrated/global/global_soil_canopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ evaluate!(Y.canopy.energy.T, atmos.T, t0)
set_initial_cache! = make_set_initial_cache(land)
exp_tendency! = make_exp_tendency(land);
imp_tendency! = ClimaLand.make_imp_tendency(land);
tendency_jacobian! = ClimaLand.make_tendency_jacobian(land);
jacobian! = ClimaLand.make_jacobian(land);
set_initial_cache!(p, Y, t0)
stepper = CTS.ARS343()
ode_algo = CTS.IMEXAlgorithm(
Expand All @@ -350,8 +350,7 @@ ode_algo = CTS.IMEXAlgorithm(
)

# set up jacobian info
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!)
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!)

prob = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,11 @@ land = SoilCanopyModel{FT}(;
)
exp_tendency! = make_exp_tendency(land)
imp_tendency! = make_imp_tendency(land);
tendency_jacobian! = make_tendency_jacobian(land);
jacobian! = make_jacobian(land);
set_initial_cache! = make_set_initial_cache(land)
Y, p, cds = initialize(land)
jac_kwargs = (;
jac_prototype = ClimaLand.ImplicitEquationJacobian(Y),
Wfact = tendency_jacobian!,
);
jac_kwargs =
(; jac_prototype = ClimaLand.ImplicitEquationJacobian(Y), Wfact = jacobian!);

#Initial conditions
Y.soil.ϑ_l = drivers.SWC.values[1 + Int(round(t0 / 1800))] # Get soil water content at t0
Expand Down
8 changes: 3 additions & 5 deletions experiments/integrated/performance/profile_allocations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ land = SoilCanopyModel{FT}(;
# Define explicit and implicit tendencies, and the jacobian
exp_tendency! = make_exp_tendency(land)
imp_tendency! = make_imp_tendency(land);
tendency_jacobian! = make_tendency_jacobian(land);
jacobian! = make_jacobian(land);

# Set up timestepping and simulation callbacks
dt = Float64(150)
Expand All @@ -352,10 +352,8 @@ driver_cb = ClimaLand.DriverUpdateCallback(updateat, updatefunc)
Y, p = set_initial_conditions(land, t0)

# Set up jacobian info
jac_kwargs = (;
jac_prototype = ClimaLand.ImplicitEquationJacobian(Y),
Wfact = tendency_jacobian!,
);
jac_kwargs =
(; jac_prototype = ClimaLand.ImplicitEquationJacobian(Y), Wfact = jacobian!);

# Solve simulation
prob = SciMLBase.ODEProblem(
Expand Down
16 changes: 6 additions & 10 deletions experiments/standalone/Soil/richards_comparison.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ outdir = joinpath(
Y.soil.ϑ_l .= FT(0.24)
exp_tendency! = make_exp_tendency(soil)
imp_tendency! = ClimaLand.make_imp_tendency(soil)
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil)
jacobian! = ClimaLand.make_jacobian(soil)
set_initial_cache!(p, Y, t0)

stepper = CTS.ARS111()
Expand All @@ -93,10 +93,8 @@ outdir = joinpath(
)

# set up jacobian info
jac_kwargs = (;
jac_prototype = ImplicitEquationJacobian(Y),
Wfact = tendency_jacobian!,
)
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!)

prob = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(
Expand Down Expand Up @@ -173,7 +171,7 @@ end
Y.soil.ϑ_l .= FT(0.1)
exp_tendency! = make_exp_tendency(soil)
imp_tendency! = ClimaLand.make_imp_tendency(soil)
tendency_jacobian! = ClimaLand.make_tendency_jacobian(soil)
jacobian! = ClimaLand.make_jacobian(soil)
set_initial_cache!(p, Y, t0)

stepper = CTS.ARS111()
Expand All @@ -188,10 +186,8 @@ end
),
)
# set up jacobian info
jac_kwargs = (;
jac_prototype = ImplicitEquationJacobian(Y),
Wfact = tendency_jacobian!,
)
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!)

prob = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(
Expand Down
5 changes: 2 additions & 3 deletions experiments/standalone/Soil/richards_runoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Y.soil.ϑ_l .= hydrostatic_profile.(lat, z, ν, θ_r, vg_α, vg_n, S_s, f_max)
set_initial_cache! = make_set_initial_cache(model)
exp_tendency! = make_exp_tendency(model);
imp_tendency! = ClimaLand.make_imp_tendency(model);
tendency_jacobian! = ClimaLand.make_tendency_jacobian(model);
jacobian! = ClimaLand.make_jacobian(model);

set_initial_cache!(p, Y, t0)
stepper = CTS.ARS111()
Expand All @@ -229,8 +229,7 @@ ode_algo = CTS.IMEXAlgorithm(
)

# set up jacobian info
jac_kwargs =
(; jac_prototype = ImplicitEquationJacobian(Y), Wfact = tendency_jacobian!)
jac_kwargs = (; jac_prototype = ImplicitEquationJacobian(Y), Wfact = jacobian!)

prob = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(
Expand Down
Loading

0 comments on commit 332a73b

Please sign in to comment.