@@ -13,11 +13,17 @@ generates the function
13
13
14
14
function compute_soil_net_radiation!(out, Y, p, t, land_model::SoilCanopyModel)
15
15
if isnothing(out)
16
- return copy(p.soil.R_n)
16
+ out = zeros(axes(p.soil.R_n)) # Allocates
17
+ fill!(field_values(out), NaN) # fill with NaNs, even over the ocean
18
+ out .= p.soil.R_n # set the land values only since this type of broadcasting respects the mask
19
+ return out
17
20
else
18
21
out .= p.soil.R_n
19
22
end
20
23
end
24
+
25
+ Please note that if a land/sea mask is employed, the values
26
+ over the ocean are set to NaN.
21
27
"""
22
28
macro diagnostic_compute (name, model, compute)
23
29
function_name = Symbol (" compute_" , name, " !" )
@@ -31,7 +37,10 @@ macro diagnostic_compute(name, model, compute)
31
37
land_model:: $model ,
32
38
)
33
39
if isnothing (out)
34
- return copy ($ compute)
40
+ out = zeros (axes ($ compute)) # Allocates
41
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
42
+ out .= $ compute # set the land values only since this type of broadcasting respects the mask
43
+ return out
35
44
else
36
45
out .= $ compute
37
46
end
@@ -95,7 +104,9 @@ function compute_stomatal_conductance!(
95
104
thermo_params = LP. thermodynamic_parameters (earth_param_set)
96
105
97
106
if isnothing (out)
98
- return medlyn_conductance .(
107
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
108
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
109
+ @. out = medlyn_conductance (
99
110
g0,
100
111
Drel,
101
112
medlyn_term .(
@@ -108,8 +119,7 @@ function compute_stomatal_conductance!(
108
119
p. canopy. photosynthesis. An,
109
120
p. drivers. c_co2,
110
121
)
111
-
112
-
122
+ return out
113
123
else
114
124
@. out = medlyn_conductance (
115
125
g0,
@@ -137,7 +147,10 @@ function compute_canopy_transpiration!(
137
147
# Convert to a mass flux by multiplying by the density of liquid
138
148
# water
139
149
if isnothing (out)
140
- return p. canopy. turbulent_fluxes. transpiration .* 1000
150
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
151
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
152
+ @. out = p. canopy. turbulent_fluxes. transpiration * 1000
153
+ return out
141
154
else
142
155
@. out = p. canopy. turbulent_fluxes. transpiration * 1000
143
156
end
@@ -163,7 +176,10 @@ function compute_leaf_water_potential!(
163
176
n_leaf = hydraulics. n_leaf
164
177
n = n_stem + n_leaf
165
178
if isnothing (out)
166
- return p. canopy. hydraulics. ψ.:($ n)
179
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
180
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
181
+ out .= p. canopy. hydraulics. ψ.:($ n)
182
+ return out
167
183
else
168
184
out .= p. canopy. hydraulics. ψ.:($ n)
169
185
end
@@ -196,7 +212,10 @@ function compute_moisture_stress_factor!(
196
212
(; sc, pc) = canopy. photosynthesis. parameters
197
213
ψ = p. canopy. hydraulics. ψ
198
214
if isnothing (out)
199
- return @. moisture_stress (ψ.:($$ n) * ρ_l * grav, sc, pc)
215
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
216
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
217
+ @. out = moisture_stress (ψ.:($$ n) * ρ_l * grav, sc, pc)
218
+ return out
200
219
else
201
220
@. out = moisture_stress (ψ.:($$ n) * ρ_l * grav, sc, pc)
202
221
end
@@ -301,7 +320,10 @@ function compute_10cm_water_mass!(
301
320
column_integral_definite! (∫Hdz, H)
302
321
303
322
if isnothing (out)
304
- return ∫Hθdz ./ ∫Hdz .* FT (0.1 )
323
+ out = zeros (land_model. soil. domain. space. surface) # Allocates
324
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
325
+ @. out = ∫Hθdz / ∫Hdz * FT (0.1 )
326
+ return out
305
327
else
306
328
@. out = ∫Hθdz / ∫Hdz * FT (0.1 )
307
329
end
@@ -314,7 +336,10 @@ function compute_soil_albedo!(
314
336
land_model:: SoilCanopyModel{FT} ,
315
337
) where {FT}
316
338
if isnothing (out)
317
- return (p. soil. PAR_albedo .+ p. soil. NIR_albedo) ./ 2
339
+ out = zeros (land_model. soil. domain. space. surface) # Allocates
340
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
341
+ @. out = (p. soil. PAR_albedo + p. soil. NIR_albedo) / 2
342
+ return out
318
343
else
319
344
@. out = (p. soil. PAR_albedo + p. soil. NIR_albedo) / 2
320
345
end
@@ -334,7 +359,10 @@ function compute_heterotrophic_respiration!(
334
359
land_model:: Union{SoilCanopyModel{FT}, LandModel{FT}} ,
335
360
) where {FT}
336
361
if isnothing (out)
337
- return p. soilco2. top_bc .* FT (83.26 )
362
+ out = zeros (land_model. soil. domain. space. surface) # Allocates
363
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
364
+ @. out = p. soilco2. top_bc * FT (83.26 )
365
+ return out
338
366
else
339
367
out .= p. soilco2. top_bc .* FT (83.26 )
340
368
end
@@ -360,11 +388,15 @@ function compute_evapotranspiration!(
360
388
land_model:: SoilCanopyModel{FT} ,
361
389
) where {FT}
362
390
if isnothing (out)
363
- return (
364
- p. soil. turbulent_fluxes. vapor_flux_liq .+
365
- p. soil. turbulent_fluxes. vapor_flux_ice .+
366
- p. canopy. turbulent_fluxes. transpiration
367
- ) .* 1000 # density of liquid water (1000kg/m^3)
391
+ out = zeros (land_model. soil. domain. space. surface) # Allocates
392
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
393
+ @. out =
394
+ (
395
+ p. soil. turbulent_fluxes. vapor_flux_liq +
396
+ p. soil. turbulent_fluxes. vapor_flux_ice +
397
+ p. canopy. turbulent_fluxes. transpiration
398
+ ) * 1000 # density of liquid water (1000kg/m^3)
399
+ return out
368
400
else
369
401
out .=
370
402
(
@@ -383,14 +415,18 @@ function compute_evapotranspiration!(
383
415
land_model:: LandModel{FT} ,
384
416
) where {FT}
385
417
if isnothing (out)
386
- return @. (
387
- (1 - p. snow. snow_cover_fraction) *
388
- p. soil. turbulent_fluxes. vapor_flux_liq +
389
- (1 - p. snow. snow_cover_fraction) *
390
- p. soil. turbulent_fluxes. vapor_flux_ice +
391
- p. canopy. turbulent_fluxes. transpiration +
392
- p. snow. snow_cover_fraction * p. snow. turbulent_fluxes. vapor_flux
393
- ) * 1000 # density of liquid water (1000kg/m^3)
418
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
419
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
420
+ @. out =
421
+ (
422
+ (1 - p. snow. snow_cover_fraction) *
423
+ p. soil. turbulent_fluxes. vapor_flux_liq +
424
+ (1 - p. snow. snow_cover_fraction) *
425
+ p. soil. turbulent_fluxes. vapor_flux_ice +
426
+ p. canopy. turbulent_fluxes. transpiration +
427
+ p. snow. snow_cover_fraction * p. snow. turbulent_fluxes. vapor_flux
428
+ ) * 1000 # density of liquid water (1000kg/m^3)
429
+ return out
394
430
else
395
431
@. out =
396
432
(
@@ -412,8 +448,11 @@ function compute_total_respiration!(
412
448
land_model:: Union{SoilCanopyModel{FT}, LandModel{FT}} ,
413
449
) where {FT}
414
450
if isnothing (out)
415
- return p. soilco2. top_bc .* FT (83.26 ) .+ # [3.664 kg CO2/ kg C] x [10^3 g CO2/ kg CO2] x [1 mol CO2/44.009 g CO2] = 83.26 mol CO2/kg C
416
- p. canopy. autotrophic_respiration. Ra
451
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
452
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
453
+ @. out =
454
+ p. soilco2. top_bc * FT (83.26 ) + p. canopy. autotrophic_respiration. Ra # [3.664 kg CO2/ kg C] x [10^3 g CO2/ kg CO2] x [1 mol CO2/44.009 g CO2] = 83.26 mol CO2/kg C
455
+ return out
417
456
else
418
457
out .=
419
458
p. soilco2. top_bc .* FT (83.26 ) .+ p. canopy. autotrophic_respiration. Ra
@@ -428,7 +467,10 @@ function compute_latent_heat_flux!(
428
467
land_model:: SoilCanopyModel{FT} ,
429
468
) where {FT}
430
469
if isnothing (out)
431
- return p. soil. turbulent_fluxes. lhf .+ p. canopy. turbulent_fluxes. lhf
470
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
471
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
472
+ @. out = p. soil. turbulent_fluxes. lhf + p. canopy. turbulent_fluxes. lhf
473
+ return out
432
474
else
433
475
out .= p. soil. turbulent_fluxes. lhf .+ p. canopy. turbulent_fluxes. lhf
434
476
end
@@ -442,7 +484,10 @@ function compute_sensible_heat_flux!(
442
484
land_model:: SoilCanopyModel{FT} ,
443
485
) where {FT}
444
486
if isnothing (out)
445
- return p. soil. turbulent_fluxes. shf .+ p. canopy. turbulent_fluxes. shf
487
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
488
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
489
+ @. out = p. soil. turbulent_fluxes. shf + p. canopy. turbulent_fluxes. shf
490
+ return out
446
491
else
447
492
out .= p. soil. turbulent_fluxes. shf .+ p. canopy. turbulent_fluxes. shf
448
493
end
@@ -456,10 +501,13 @@ function compute_latent_heat_flux!(
456
501
land_model:: LandModel{FT} ,
457
502
) where {FT}
458
503
if isnothing (out)
459
- return @. p. soil. turbulent_fluxes. lhf *
460
- (1 - p. snow. snow_cover_fraction) +
461
- p. canopy. turbulent_fluxes. lhf +
462
- p. snow. snow_cover_fraction * p. snow. turbulent_fluxes. lhf
504
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
505
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
506
+ @. out =
507
+ p. soil. turbulent_fluxes. lhf * (1 - p. snow. snow_cover_fraction) +
508
+ p. canopy. turbulent_fluxes. lhf +
509
+ p. snow. snow_cover_fraction * p. snow. turbulent_fluxes. lhf
510
+ return out
463
511
else
464
512
@. out =
465
513
p. soil. turbulent_fluxes. lhf * (1 - p. snow. snow_cover_fraction) +
@@ -476,10 +524,13 @@ function compute_sensible_heat_flux!(
476
524
land_model:: LandModel{FT} ,
477
525
) where {FT}
478
526
if isnothing (out)
479
- return @. p. soil. turbulent_fluxes. shf *
480
- (1 - p. snow. snow_cover_fraction) +
481
- p. canopy. turbulent_fluxes. shf +
482
- p. snow. snow_cover_fraction * p. snow. turbulent_fluxes. shf
527
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
528
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
529
+ @. out =
530
+ p. soil. turbulent_fluxes. shf * (1 - p. snow. snow_cover_fraction) +
531
+ p. canopy. turbulent_fluxes. shf +
532
+ p. snow. snow_cover_fraction * p. snow. turbulent_fluxes. shf
533
+ return out
483
534
else
484
535
@. out =
485
536
p. soil. turbulent_fluxes. shf * (1 - p. snow. snow_cover_fraction) +
@@ -496,31 +547,17 @@ function compute_net_radiation!(
496
547
land_model:: Union{SoilCanopyModel{FT}, LandModel{FT}} ,
497
548
) where {FT}
498
549
if isnothing (out)
499
- return p. drivers. LW_d .- p. LW_u .+ p. drivers. SW_d .- p. SW_u
550
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
551
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
552
+ @. out = p. drivers. LW_d - p. LW_u + p. drivers. SW_d - p. SW_u
553
+ return out
500
554
501
555
else
502
556
out .= p. drivers. LW_d .- p. LW_u .+ p. drivers. SW_d .- p. SW_u
503
557
504
558
end
505
559
end
506
560
507
- function compute_ground_heat_flux! (
508
- out,
509
- Y,
510
- p,
511
- t,
512
- land_model:: Union{SoilCanopyModel{FT}, LandModel{FT}} ,
513
- ) where {FT}
514
- if isnothing (out)
515
- return p. soil. turbulent_fluxes. shf .+ p. canopy. turbulent_fluxes. shf .-
516
- p. soil. R_n
517
- else
518
- out .=
519
- p. soil. turbulent_fluxes. shf .+ p. canopy. turbulent_fluxes. shf .-
520
- p. soil. R_n
521
- end
522
- end
523
-
524
561
# variables stored in Y (prognostic or state variables)
525
562
nan_if_no_canopy (T:: FT , AI:: FT ) where {FT <: Real } = AI > 0 ? T : FT (NaN )
526
563
function compute_canopy_temperature! (
@@ -535,7 +572,10 @@ function compute_canopy_temperature!(
535
572
p. canopy. hydraulics. area_index. leaf +
536
573
p. canopy. hydraulics. area_index. stem
537
574
if isnothing (out)
538
- return nan_if_no_canopy .(Y. canopy. energy. T, AI)
575
+ out = zeros (land_model. canopy. domain. space. surface) # Allocates
576
+ fill! (field_values (out), NaN ) # fill with NaNs, even over the ocean
577
+ @. out = nan_if_no_canopy (Y. canopy. energy. T, AI)
578
+ return out
539
579
else
540
580
out .= nan_if_no_canopy .(Y. canopy. energy. T, AI)
541
581
end
0 commit comments