Skip to content

Commit 34cadc8

Browse files
committed
fix constructors for soilco2
1 parent 6520dd6 commit 34cadc8

File tree

5 files changed

+129
-393
lines changed

5 files changed

+129
-393
lines changed

src/integrated/land.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ function LandModel{FT}(;
320320

321321
soilco2_boundary_conditions =
322322
(; top = soilco2_top_bc, bottom = soilco2_bot_bc)
323-
soilco2 = soilco2_type(;
323+
soilco2 = soilco2_type(
324+
soilco2_args.domain,
325+
soilco2_drivers;
324326
boundary_conditions = soilco2_boundary_conditions,
325327
sources = soilco2_sources,
326-
soilco2_args..., # adds domain, params
328+
parameters = soilco2_args.parameters,
327329
drivers = soilco2_drivers,
328330
)
329331

src/integrated/soil_canopy_model.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,12 @@ function SoilCanopyModel{FT}(;
270270

271271
soilco2_boundary_conditions =
272272
(; top = soilco2_top_bc, bottom = soilco2_bot_bc)
273-
soilco2 = soilco2_type(;
273+
soilco2 = soilco2_type(
274+
soilco2_args.domain,
275+
soilco2_drivers;
274276
boundary_conditions = soilco2_boundary_conditions,
275277
sources = soilco2_sources,
276-
soilco2_args...,
278+
parameters = soilco2_args.parameters,
277279
drivers = soilco2_drivers,
278280
)
279281

src/integrated/soil_energy_hydrology_biogeochemistry.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ function LandSoilBiogeochemistry{FT}(;
5353
soil_organic_carbon,
5454
atmos,
5555
)
56-
soilco2 = Soil.Biogeochemistry.SoilCO2Model{FT}(;
57-
soilco2_args...,
58-
drivers = soil_co2_drivers,
56+
soilco2 = Soil.Biogeochemistry.SoilCO2Model{FT}(
57+
soilco2_args.domain,
58+
soil_co2_drivers;
59+
boundary_conditions = soilco2_args.boundary_conditions,
60+
parameters = soilco2_args.parameters,
5961
)
6062
args = (soil, soilco2)
6163
return LandSoilBiogeochemistry{FT, typeof.(args)...}(args...)

test/integrated/full_land.jl

Lines changed: 116 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -83,58 +83,133 @@ for FT in (Float32, Float64)
8383
end
8484
end
8585

86-
include("full_land_utils.jl");
86+
"""
87+
check_ocean_values_p(p, binary_mask; val = 0.0)
88+
89+
This function tests that every field stored in `p` has all of
90+
its values (where binary_mask == 1) equal to `val`. Note that
91+
this is meant to be used with the full land model (canopy,
92+
snow, soil, soilco2).
93+
94+
Useful for checking if land model functions are updating the
95+
values over the ocean.
96+
"""
97+
function check_ocean_values_p(p, binary_mask; val = 0.0)
98+
properties = [
99+
p.drivers,
100+
p.soil,
101+
p.soilco2,
102+
p.snow,
103+
p.canopy.energy,
104+
p.canopy.hydraulics,
105+
p.canopy.radiative_transfer,
106+
p.canopy.photosynthesis,
107+
p.canopy.sif,
108+
p.canopy.turbulent_fluxes,
109+
p.canopy.autotrophic_respiration,
110+
p.canopy.conductance,
111+
]
112+
for property in properties
113+
for var in propertynames(property)
114+
field_values = Array(parent(getproperty(property, var)))
115+
if length(size(field_values)) == 5 # 3d var
116+
@test extrema(field_values[:, 1, 1, :, Array(binary_mask)]) ==
117+
(val, val)
118+
else
119+
@test extrema(field_values[1, 1, :, Array(binary_mask)]) ==
120+
(val, val)
121+
end
122+
end
123+
end
124+
125+
field_pn_p = [
126+
pn for pn in propertynames(p) if pn != :soil &&
127+
pn != :canopy &&
128+
pn != :snow &&
129+
pn != :soilco2 &&
130+
pn != :drivers &&
131+
~occursin("dss", String(pn))
132+
]
133+
134+
for var in field_pn_p
135+
field_values = Array(parent(getproperty(p, var)))
136+
if length(size(field_values)) == 5 # 3d var
137+
@test extrema(field_values[:, 1, 1, :, Array(binary_mask)]) ==
138+
(val, val)
139+
else
140+
@test extrema(field_values[1, 1, :, Array(binary_mask)]) ==
141+
(val, val)
142+
143+
end
144+
end
145+
end
146+
147+
"""
148+
check_ocean_values_Y(Y, binary_mask; val = 0.0)
149+
150+
This function tests that every field stored in `Y` has all of
151+
its values (where binary_mask == 1) equal to `val`. Note that
152+
this is meant to be used with the full land model (canopy,
153+
snow, soil, soilco2).
154+
155+
Useful for checking if land model functions are updating the
156+
values over the ocean.
157+
"""
158+
function check_ocean_values_Y(Y, binary_mask; val = 0.0)
159+
@test extrema(Array(parent(Y.soil.ϑ_l))[:, 1, 1, 1, Array(binary_mask)]) ==
160+
(val, val)
161+
@test extrema(Array(parent(Y.soil.θ_i))[:, 1, 1, 1, Array(binary_mask)]) ==
162+
(val, val)
163+
@test extrema(
164+
Array(parent(Y.soil.ρe_int))[:, 1, 1, 1, Array(binary_mask)],
165+
) == (val, val)
166+
@test extrema(Array(parent(Y.snow.U))[1, 1, 1, Array(binary_mask)]) ==
167+
(val, val)
168+
@test extrema(Array(parent(Y.snow.S))[1, 1, 1, Array(binary_mask)]) ==
169+
(val, val)
170+
@test extrema(Array(parent(Y.snow.S_l))[1, 1, 1, Array(binary_mask)]) ==
171+
(val, val)
172+
@test extrema(
173+
Array(parent(Y.canopy.energy.T))[1, 1, 1, Array(binary_mask)],
174+
) == (val, val)
175+
@test extrema(
176+
Array(parent(Y.canopy.hydraulics.ϑ_l.:1))[1, 1, 1, Array(binary_mask)],
177+
) == (val, val)
178+
end
179+
87180

88181
context = ClimaComms.context()
89182
nelements = (101, 15)
90-
start_date = DateTime(2008)
91183
Δt = 450.0
92-
t0 = 0.0
93-
tf = t0 + Δt
94-
95184
FT = Float64
96185
earth_param_set = LP.LandParameters(FT)
97186

98-
f_over = FT(3.28) # 1/m
99-
R_sb = FT(1.484e-4 / 1000) # m/s
100-
scalar_soil_params = (; f_over, R_sb)
101-
102-
α_snow = Snow.ConstantAlbedoModel(FT(0.67))
103-
scalar_snow_params = (; α_snow, Δt)
104-
105-
# Energy Balance model
106-
ac_canopy = FT(2.5e3)
107-
K_sat_plant = FT(5e-9) # m/s # seems much too small?
108-
ψ63 = FT(-4 / 0.0098) # / MPa to m, Holtzman's original parameter value is -4 MPa
109-
Weibull_param = FT(4) # unitless, Holtzman's original c param value
110-
a = FT(0.05 * 0.0098) # Holtzman's original parameter for the bulk modulus of elasticity
111-
plant_ν = FT(1.44e-4)
112-
plant_S_s = FT(1e-2 * 0.0098) # m3/m3/MPa to m3/m3/m
113-
h_leaf = FT(1.0)
114-
115-
scalar_canopy_params = (;
116-
ac_canopy,
117-
K_sat_plant,
118-
a,
119-
ψ63,
120-
Weibull_param,
121-
plant_ν,
122-
plant_S_s,
123-
h_leaf,
124-
);
125-
126187
domain = ClimaLand.Domains.global_domain(FT; nelements = nelements);
127188
surface_space = domain.space.surface;
128189
start_date = DateTime(2008);
129-
land = global_land_model(
130-
FT,
131-
scalar_soil_params,
132-
scalar_canopy_params,
133-
scalar_snow_params,
134-
earth_param_set;
135-
context = context,
136-
domain = domain,
190+
stop_date = start_date + Second(Δt)
191+
era5_ncdata_path = ClimaLand.Artifacts.era5_land_forcing_data2008_path(;
192+
context,
193+
lowres = true,
194+
)
195+
forcing = ClimaLand.prescribed_forcing_era5(
196+
era5_ncdata_path,
197+
domain.space.surface,
198+
start_date,
199+
earth_param_set,
200+
FT;
201+
)
202+
modis_lai_ncdata_path = ClimaLand.Artifacts.modis_lai_multiyear_paths(;
203+
start_date,
204+
end_date = stop_date,
205+
)
206+
LAI = ClimaLand.prescribed_lai_modis(
207+
modis_lai_ncdata_path,
208+
domain.space.surface,
209+
start_date,
137210
);
211+
land_model = LandModel{FT}(forcing, LAI, earth_param_set, domain, Δt);
212+
138213
@test domain == ClimaLand.get_domain(land)
139214
@test ClimaComms.context(land) == ClimaComms.context()
140215
@test ClimaComms.device(land) == ClimaComms.device()

0 commit comments

Comments
 (0)