Skip to content

Commit 5e99a55

Browse files
committed
explicit and implicit sources
1 parent 60fc129 commit 5e99a55

File tree

19 files changed

+303
-100
lines changed

19 files changed

+303
-100
lines changed

docs/tutorials/standalone/Usage/model_tutorial.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ import ClimaLand:
131131
make_exp_tendency,
132132
make_compute_exp_tendency,
133133
make_update_aux,
134-
make_update_boundary_fluxes,
134+
make_update_explicit_boundary_fluxes,
135135
prognostic_vars,
136136
prognostic_types,
137137
prognostic_domain_names,
@@ -257,7 +257,9 @@ function ClimaLand.make_update_aux(model::RichardsTutorialModel)
257257
return update_aux!
258258
end;
259259

260-
function ClimaLand.make_update_boundary_fluxes(model::RichardsTutorialModel)
260+
function ClimaLand.make_update_explicit_boundary_fluxes(
261+
model::RichardsTutorialModel,
262+
)
261263
function update_boundary_fluxes!(p, Y, t)
262264
FT = ClimaLand.FTfromY(Y)
263265
p.soil.top_flux .= model.F_sfc
@@ -271,7 +273,7 @@ end;
271273
# ```julia
272274
# function make_exp_tendency(model::AbstractModel)
273275
# update_aux! = make_update_aux(model)
274-
# update_boundary_fluxes! = make_update_boundary_fluxes(model)
276+
# update_boundary_fluxes! = make_update_explicit_boundary_fluxes(model)
275277
# compute_exp_tendency! = make_compute_exp_tendency(model)
276278
# function exp_tendency!(dY,Y,p,t)
277279
# update_aux!(p,Y,t)

src/ClimaLand.jl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function make_imp_tendency(land::AbstractLandModel)
142142
compute_imp_tendency_list =
143143
map(x -> make_compute_imp_tendency(getproperty(land, x)), components)
144144
update_aux! = make_update_aux(land)
145-
update_boundary_fluxes! = make_update_boundary_fluxes(land)
145+
update_boundary_fluxes! = make_update_implicit_boundary_fluxes(land)
146146
function imp_tendency!(dY, Y, p, t)
147147
update_aux!(p, Y, t)
148148
update_boundary_fluxes!(p, Y, t)
@@ -158,7 +158,7 @@ function make_exp_tendency(land::AbstractLandModel)
158158
compute_exp_tendency_list =
159159
map(x -> make_compute_exp_tendency(getproperty(land, x)), components)
160160
update_aux! = make_update_aux(land)
161-
update_boundary_fluxes! = make_update_boundary_fluxes(land)
161+
update_boundary_fluxes! = make_update_explicit_boundary_fluxes(land)
162162
function exp_tendency!(dY, Y, p, t)
163163
update_aux!(p, Y, t)
164164
update_boundary_fluxes!(p, Y, t)
@@ -181,16 +181,32 @@ function make_update_aux(land::AbstractLandModel)
181181
return update_aux!
182182
end
183183

184-
function make_update_boundary_fluxes(land::AbstractLandModel)
184+
function make_update_explicit_boundary_fluxes(land::AbstractLandModel)
185185
components = land_components(land)
186-
update_fluxes_function_list =
187-
map(x -> make_update_boundary_fluxes(getproperty(land, x)), components)
188-
function update_boundary_fluxes!(p, Y, t)
186+
update_fluxes_function_list = map(
187+
x -> make_update_explicit_boundary_fluxes(getproperty(land, x)),
188+
components,
189+
)
190+
function update_explicit_boundary_fluxes!(p, Y, t)
189191
for f! in update_fluxes_function_list
190192
f!(p, Y, t)
191193
end
192194
end
193-
return update_boundary_fluxes!
195+
return update_explicit_boundary_fluxes!
196+
end
197+
198+
function make_update_implicit_boundary_fluxes(land::AbstractLandModel)
199+
components = land_components(land)
200+
update_fluxes_function_list = map(
201+
x -> make_update_implicit_boundary_fluxes(getproperty(land, x)),
202+
components,
203+
)
204+
function update_implicit_boundary_fluxes!(p, Y, t)
205+
for f! in update_fluxes_function_list
206+
f!(p, Y, t)
207+
end
208+
end
209+
return update_implicit_boundary_fluxes!
194210
end
195211

196212
function make_compute_jacobian(land::AbstractLandModel)

src/integrated/land.jl

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ lsm_aux_domain_names(m::LandModel) = (
277277
:surface,
278278
)
279279

280+
280281
"""
281282
make_update_boundary_fluxes(
282283
land::LandModel{FT, MM, SM, RM, SnM},
@@ -296,7 +297,7 @@ models.
296297
This function is called each ode function evaluation, prior to the tendency function
297298
evaluation.
298299
"""
299-
function make_update_boundary_fluxes(
300+
function make_update_explicit_boundary_fluxes(
300301
land::LandModel{FT, MM, SM, RM, SnM},
301302
) where {
302303
FT,
@@ -305,16 +306,26 @@ function make_update_boundary_fluxes(
305306
RM <: Canopy.CanopyModel{FT},
306307
SnM <: Snow.SnowModel{FT},
307308
}
308-
update_soil_bf! = make_update_boundary_fluxes(land.soil)
309-
update_soilco2_bf! = make_update_boundary_fluxes(land.soilco2)
310-
update_canopy_bf! = make_update_boundary_fluxes(land.canopy)
311-
update_snow_bf! = make_update_boundary_fluxes(land.snow)
309+
update_soil_bf! = make_update_explicit_boundary_fluxes(land.soil)
310+
update_soilco2_bf! = make_update_explicit_boundary_fluxes(land.soilco2)
311+
update_canopy_bf! = make_update_explicit_boundary_fluxes(land.canopy)
312+
update_snow_bf! = make_update_explicit_boundary_fluxes(land.snow)
312313

313314
function update_boundary_fluxes!(p, Y, t)
314315
earth_param_set = land.soil.parameters.earth_param_set
315316
# update root extraction
316317
update_root_extraction!(p, Y, t, land) # defined in src/integrated/soil_canopy_root_interactions.jl
317318

319+
# Compute the ground heat flux in place:
320+
update_soil_snow_ground_heat_flux!(
321+
p,
322+
Y,
323+
land.soil.parameters,
324+
land.snow.parameters,
325+
land.soil.domain,
326+
FT,
327+
)
328+
318329
# Radiation - updates Rn for soil and snow also
319330
lsm_radiant_energy_fluxes!(
320331
p,
@@ -330,15 +341,6 @@ function make_update_boundary_fluxes(
330341
land.soil.parameters.earth_param_set,
331342
)
332343

333-
# Compute the ground heat flux in place:
334-
update_soil_snow_ground_heat_flux!(
335-
p,
336-
Y,
337-
land.soil.parameters,
338-
land.snow.parameters,
339-
land.soil.domain,
340-
FT,
341-
)
342344
#Now update snow boundary conditions, which rely on the ground heat flux
343345
update_snow_bf!(p, Y, t)
344346

@@ -355,34 +357,74 @@ function make_update_boundary_fluxes(
355357
update_canopy_bf!(p, Y, t)
356358
# Update soil CO2
357359
update_soilco2_bf!(p, Y, t)
360+
end
361+
return update_boundary_fluxes!
362+
end
363+
364+
365+
"""
366+
make_update_implicit_boundary_fluxes(
367+
land::LandModel{FT, MM, SM, RM, SnM},
368+
) where {
369+
FT,
370+
MM <: Soil.Biogeochemistry.SoilCO2Model{FT},
371+
SM <: Soil.RichardsModel{FT},
372+
RM <: Canopy.CanopyModel{FT}
373+
SnM <: Snow.SnowModel{FT}
374+
}
375+
376+
A method which makes a function; the returned function
377+
updates the additional auxiliary variables for the integrated model,
378+
as well as updates the boundary auxiliary variables for all component
379+
models.
380+
381+
This function is called each ode function evaluation, prior to the tendency function
382+
evaluation.
383+
"""
384+
function make_update_implicit_boundary_fluxes(
385+
land::LandModel{FT, MM, SM, RM, SnM},
386+
) where {
387+
FT,
388+
MM <: Soil.Biogeochemistry.SoilCO2Model{FT},
389+
SM <: Soil.EnergyHydrology{FT},
390+
RM <: Canopy.CanopyModel{FT},
391+
SnM <: Snow.SnowModel{FT},
392+
}
393+
update_soil_bf! = make_update_implicit_boundary_fluxes(land.soil)
394+
update_soilco2_bf! = make_update_implicit_boundary_fluxes(land.soilco2)
395+
update_canopy_bf! = make_update_implicit_boundary_fluxes(land.canopy)
396+
update_snow_bf! = make_update_implicit_boundary_fluxes(land.snow)
397+
398+
function update_boundary_fluxes!(p, Y, t)
399+
# Compute the ground heat flux in place:
400+
update_soil_snow_ground_heat_flux!(
401+
p,
402+
Y,
403+
land.soil.parameters,
404+
land.snow.parameters,
405+
land.soil.domain,
406+
FT,
407+
)
408+
409+
# Radiation - updates Rn for soil and snow also
410+
lsm_radiant_energy_fluxes!(
411+
p,
412+
land,
413+
land.canopy.radiative_transfer,
414+
Y,
415+
t,
416+
)
358417

359-
# compute net flux with atmosphere, this is useful for monitoring conservation
360-
_LH_f0 = FT(LP.LH_f0(earth_param_set))
361-
_ρ_liq = FT(LP.ρ_cloud_liq(earth_param_set))
362-
ρe_falling_snow = -_LH_f0 * _ρ_liq # per unit vol of liquid water
363-
@. p.atmos_energy_flux =
364-
(1 - p.snow.snow_cover_fraction) * (
365-
p.soil.turbulent_fluxes.lhf + p.soil.turbulent_fluxes.shf -
366-
p.soil.R_n
367-
) +
368-
p.snow.snow_cover_fraction * (
369-
p.snow.turbulent_fluxes.lhf + p.snow.turbulent_fluxes.shf -
370-
p.snow.R_n
371-
) +
372-
p.drivers.P_snow * ρe_falling_snow +
373-
p.canopy.turbulent_fluxes.shf +
374-
p.canopy.turbulent_fluxes.lhf - p.canopy.radiative_transfer.SW_n -
375-
p.canopy.radiative_transfer.LW_n
376-
@. p.atmos_water_flux =
377-
p.drivers.P_snow +
378-
p.drivers.P_liq +
379-
(1 - p.snow.snow_cover_fraction) * (
380-
p.soil.turbulent_fluxes.vapor_flux_liq +
381-
p.soil.turbulent_fluxes.vapor_flux_ice
382-
) +
383-
p.snow.snow_cover_fraction * p.snow.turbulent_fluxes.vapor_flux +
384-
p.canopy.turbulent_fluxes.transpiration
418+
# Effective (radiative) land properties
419+
set_eff_land_radiation_properties!(
420+
p,
421+
land.soil.parameters.earth_param_set,
422+
)
385423

424+
update_snow_bf!(p, Y, t)
425+
update_soil_bf!(p, Y, t)
426+
update_canopy_bf!(p, Y, t)
427+
update_soilco2_bf!(p, Y, t)
386428
end
387429
return update_boundary_fluxes!
388430
end

src/integrated/pond_soil_model.jl

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function infiltration_capacity(Y::ClimaCore.Fields.FieldVector, p::NamedTuple)
156156
end
157157

158158
"""
159-
make_update_boundary_fluxes(
159+
make_update_explicit_boundary_fluxes(
160160
land::LandHydrology{FT, SM, SW},
161161
) where {FT, SM <: Soil.RichardsModel{FT}, SW <: Pond.PondModel{FT}}
162162
@@ -167,11 +167,36 @@ term (runoff) for the surface water model.
167167
168168
This function is called each ode function evaluation.
169169
"""
170-
function make_update_boundary_fluxes(
170+
function make_update_explicit_boundary_fluxes(
171171
land::LandHydrology{FT, SM, SW},
172172
) where {FT, SM <: Soil.RichardsModel{FT}, SW <: Pond.PondModel{FT}}
173-
update_soil_bf! = make_update_boundary_fluxes(land.soil)
174-
update_pond_bf! = make_update_boundary_fluxes(land.surface_water)
173+
update_soil_bf! = make_update_explicit_boundary_fluxes(land.soil)
174+
update_pond_bf! = make_update_explicit_boundary_fluxes(land.surface_water)
175+
function update_boundary_fluxes!(p, Y, t)
176+
update_soil_bf!(p, Y, t)
177+
update_pond_bf!(p, Y, t)
178+
end
179+
return update_boundary_fluxes!
180+
end
181+
182+
183+
"""
184+
make_update_implicit_boundary_fluxes(
185+
land::LandHydrology{FT, SM, SW},
186+
) where {FT, SM <: Soil.RichardsModel{FT}, SW <: Pond.PondModel{FT}}
187+
188+
A method which makes a function; the returned function
189+
updates the auxiliary variable `p.soil_infiltration`, which
190+
is needed for both the boundary condition for the soil model and the source
191+
term (runoff) for the surface water model.
192+
193+
This function is called each ode function evaluation.
194+
"""
195+
function make_update_implicit_boundary_fluxes(
196+
land::LandHydrology{FT, SM, SW},
197+
) where {FT, SM <: Soil.RichardsModel{FT}, SW <: Pond.PondModel{FT}}
198+
update_soil_bf! = make_update_implicit_boundary_fluxes(land.soil)
199+
update_pond_bf! = make_update_implicit_boundary_fluxes(land.surface_water)
175200
function update_boundary_fluxes!(p, Y, t)
176201
i_c = infiltration_capacity(Y, p)
177202
@. p.soil_infiltration =

src/integrated/soil_canopy_model.jl

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ lsm_aux_domain_names(m::SoilCanopyModel) = (
209209
)
210210

211211
"""
212-
make_update_boundary_fluxes(
212+
make_update_explicit_boundary_fluxes(
213213
land::SoilCanopyModel{FT, MM, SM, RM},
214214
) where {
215215
FT,
@@ -226,20 +226,21 @@ models.
226226
This function is called each ode function evaluation, prior to the tendency function
227227
evaluation.
228228
"""
229-
function make_update_boundary_fluxes(
229+
function make_update_explicit_boundary_fluxes(
230230
land::SoilCanopyModel{FT, MM, SM, RM},
231231
) where {
232232
FT,
233233
MM <: Soil.Biogeochemistry.SoilCO2Model{FT},
234234
SM <: Soil.EnergyHydrology{FT},
235235
RM <: Canopy.CanopyModel{FT},
236236
}
237-
update_soil_bf! = make_update_boundary_fluxes(land.soil)
238-
update_soilco2_bf! = make_update_boundary_fluxes(land.soilco2)
239-
update_canopy_bf! = make_update_boundary_fluxes(land.canopy)
237+
update_soil_bf! = make_update_explicit_boundary_fluxes(land.soil)
238+
update_soilco2_bf! = make_update_explicit_boundary_fluxes(land.soilco2)
239+
update_canopy_bf! = make_update_explicit_boundary_fluxes(land.canopy)
240240
function update_boundary_fluxes!(p, Y, t)
241241
# update root extraction
242242
update_root_extraction!(p, Y, t, land)
243+
243244
# Radiation
244245
lsm_radiant_energy_fluxes!(
245246
p,
@@ -262,6 +263,45 @@ function make_update_boundary_fluxes(
262263
end
263264

264265

266+
267+
"""
268+
make_update_implicit_boundary_fluxes(
269+
land::SoilCanopyModel{FT, MM, SM, RM},
270+
) where {
271+
FT,
272+
MM <: Soil.Biogeochemistry.SoilCO2Model{FT},
273+
SM <: Soil.RichardsModel{FT},
274+
RM <: Canopy.CanopyModel{FT}
275+
}
276+
277+
A method which makes a function; the returned function
278+
updates the additional auxiliary variables for the integrated model,
279+
as well as updates the implicit_boundary auxiliary variables for all component
280+
models.
281+
282+
This function is called each ode function evaluation, prior to the tendency function
283+
evaluation.
284+
"""
285+
function make_update_implicit_boundary_fluxes(
286+
land::SoilCanopyModel{FT, MM, SM, RM},
287+
) where {
288+
FT,
289+
MM <: Soil.Biogeochemistry.SoilCO2Model{FT},
290+
SM <: Soil.EnergyHydrology{FT},
291+
RM <: Canopy.CanopyModel{FT},
292+
}
293+
update_soil_bf! = make_update_implicit_boundary_fluxes(land.soil)
294+
update_soilco2_bf! = make_update_implicit_boundary_fluxes(land.soilco2)
295+
update_canopy_bf! = make_update_implicit_boundary_fluxes(land.canopy)
296+
function update_boundary_fluxes!(p, Y, t)
297+
update_soil_bf!(p, Y, t)
298+
update_canopy_bf!(p, Y, t)
299+
update_soilco2_bf!(p, Y, t)
300+
end
301+
return update_boundary_fluxes!
302+
end
303+
304+
265305
"""
266306
lsm_radiant_energy_fluxes!(p, land::SoilCanopyModel{FT},
267307
canopy_radiation::Canopy.AbstractRadiationModel{FT},

0 commit comments

Comments
 (0)