Skip to content

Commit

Permalink
Merge pull request #3224 from CliMA/cc/cfsite_spec
Browse files Browse the repository at this point in the history
Add cfsite identifier to toml
  • Loading branch information
costachris authored Aug 5, 2024
2 parents 407a993 + 882e4dd commit c9b7d73
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 29 deletions.
3 changes: 3 additions & 0 deletions config/default_configs/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ external_forcing:
external_forcing_file:
help: "External forcing file containing large-scale forcings, initial conditions, and boundary conditions [`nothing` (default), `path/to/file`]"
value: ~
cfsite_number:
help: "cfsite identifier for single column forcing from `external_forcing_file`, specified as siteN. For site details see Shen et al. 2022 `https://doi.org/10.1029/2021MS002631`. [`site23` (default), `siteN`]"
value: "site23"
subsidence:
help: "Subsidence [`nothing` (default), `Bomex`, `LifeCycleTan2018`, `Rico`, `DYCOMS`]"
value: ~
Expand Down
1 change: 1 addition & 0 deletions config/model_configs/prognostic_edmfx_gcmdriven_column.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
initial_condition: "GCM"
external_forcing: "GCM"
external_forcing_file: "/central/groups/esm/zhaoyi/GCMForcedLES/forcing/corrected/HadGEM2-A_amip.2004-2008.07.nc"
cfsite_number : "site23"
surface_setup: "GCM"
turbconv: "prognostic_edmfx"
implicit_diffusion: true
Expand Down
20 changes: 10 additions & 10 deletions src/initial_conditions/initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1147,17 +1147,18 @@ The `InitialCondition` from a provided GCM forcing file, with data type `DType`.
"""
struct GCMDriven <: InitialCondition
external_forcing_file::String
cfsite_number::String
end

function (initial_condition::GCMDriven)(params)
(; external_forcing_file) = initial_condition
(; external_forcing_file, cfsite_number) = initial_condition
thermo_params = CAP.thermodynamics_params(params)

# Read forcing file
z_gcm = NC.NCDataset(external_forcing_file) do ds
vec(gcm_height(ds.group["site23"]))
vec(gcm_height(ds.group[cfsite_number]))
end
vars = gcm_initial_conditions(external_forcing_file)
vars = gcm_initial_conditions(external_forcing_file, cfsite_number)
T, u, v, q_tot, ρ₀ = map(vars) do value
Intp.extrapolate(
Intp.interpolate((z_gcm,), value, Intp.Gridded(Intp.Linear())),
Expand All @@ -1184,15 +1185,14 @@ function (initial_condition::GCMDriven)(params)
return local_state
end

# function gcm_initial_conditions(external_forcing_file, FT)
function gcm_initial_conditions(external_forcing_file)
function gcm_initial_conditions(external_forcing_file, cfsite_number)
NC.NCDataset(external_forcing_file) do ds
( # TODO: Cast to CuVector for GPU compatibility
gcm_driven_profile_tmean(ds.group["site23"], "ta"),
gcm_driven_profile_tmean(ds.group["site23"], "ua"),
gcm_driven_profile_tmean(ds.group["site23"], "va"),
gcm_driven_profile_tmean(ds.group["site23"], "hus"),
vec(mean(1 ./ ds.group["site23"]["alpha"][:, :], dims = 2)), # convert alpha to rho using rho=1/alpha, take average profile
gcm_driven_profile_tmean(ds.group[cfsite_number], "ta"),
gcm_driven_profile_tmean(ds.group[cfsite_number], "ua"),
gcm_driven_profile_tmean(ds.group[cfsite_number], "va"),
gcm_driven_profile_tmean(ds.group[cfsite_number], "hus"),
vec(mean(1 ./ ds.group[cfsite_number]["alpha"][:, :], dims = 2)), # convert alpha to rho using rho=1/alpha, take average profile
)
end
end
18 changes: 9 additions & 9 deletions src/prognostic_equations/forcing/external_forcing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ function external_forcing_cache(Y, external_forcing::GCMForcing, params)
insolation = similar(Fields.level(Y.c.ρ, 1), FT)
cos_zenith = similar(Fields.level(Y.c.ρ, 1), FT)

(; external_forcing_file) = external_forcing
(; external_forcing_file, cfsite_number) = external_forcing

NC.Dataset(external_forcing_file, "r") do ds

function setvar!(cc_field, varname, colidx, zc_gcm, zc_forcing)
parent(cc_field[colidx]) .= interp_vertical_prof(
zc_gcm,
zc_forcing,
gcm_driven_profile_tmean(ds.group["site23"], varname),
gcm_driven_profile_tmean(ds.group[cfsite_number], varname),
)
end

Expand All @@ -79,24 +79,24 @@ function external_forcing_cache(Y, external_forcing::GCMForcing, params)
parent(cc_field[colidx]) .= interp_vertical_prof(
zc_gcm,
zc_forcing,
gcm_driven_profile_tmean(ds.group["site23"], varname) .*
.-(gcm_driven_profile_tmean(ds.group["site23"], "alpha")) ./
CAP.grav(params),
gcm_driven_profile_tmean(ds.group[cfsite_number], varname) .* .-(
gcm_driven_profile_tmean(ds.group[cfsite_number], "alpha"),
) ./ CAP.grav(params),
)
end

function set_insolation!(cc_field)
parent(cc_field) .= mean(
ds.group["site23"]["rsdt"][:] ./
ds.group["site23"]["coszen"][:],
ds.group[cfsite_number]["rsdt"][:] ./
ds.group[cfsite_number]["coszen"][:],
)
end

function set_cos_zenith!(cc_field)
parent(cc_field) .= ds.group["site23"]["coszen"][1]
parent(cc_field) .= ds.group[cfsite_number]["coszen"][1]
end

zc_forcing = gcm_height(ds.group["site23"])
zc_forcing = gcm_height(ds.group[cfsite_number])
Fields.bycolumn(axes(Y.c)) do colidx

zc_gcm = Fields.coordinate_field(Y.c).z[colidx]
Expand Down
5 changes: 4 additions & 1 deletion src/solver/model_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ function get_external_forcing_model(parsed_args)
nothing
elseif external_forcing == "GCM"
DType = Float64 # TODO: Read from `parsed_args`
GCMForcing{DType}(parsed_args["external_forcing_file"])
GCMForcing{DType}(
parsed_args["external_forcing_file"],
parsed_args["cfsite_number"],
)
end
end

Expand Down
11 changes: 8 additions & 3 deletions src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ function get_initial_condition(parsed_args)
return getproperty(ICs, Symbol(parsed_args["initial_condition"]))()
elseif parsed_args["initial_condition"] == "GCM"
@assert parsed_args["prognostic_tke"] == true
return ICs.GCMDriven(parsed_args["external_forcing_file"])
return ICs.GCMDriven(
parsed_args["external_forcing_file"],
parsed_args["cfsite_number"],
)
else
error(
"Unknown `initial_condition`: $(parsed_args["initial_condition"])",
Expand All @@ -363,8 +366,10 @@ function get_initial_condition(parsed_args)
end

function get_surface_setup(parsed_args)
parsed_args["surface_setup"] == "GCM" &&
return SurfaceConditions.GCMDriven(parsed_args["external_forcing_file"])
parsed_args["surface_setup"] == "GCM" && return SurfaceConditions.GCMDriven(
parsed_args["external_forcing_file"],
parsed_args["cfsite_number"],
)

return getproperty(SurfaceConditions, Symbol(parsed_args["surface_setup"]))()
end
Expand Down
1 change: 1 addition & 0 deletions src/solver/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ end
# maybe need to <: AbstractForcing
struct GCMForcing{FT}
external_forcing_file::String
cfsite_number::String
end

struct EDMFCoriolis{U, V, FT}
Expand Down
14 changes: 8 additions & 6 deletions src/surface_conditions/surface_setups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,22 +253,24 @@ end

struct GCMDriven
external_forcing_file::String
cfsite_number::String
end
function (surface_setup::GCMDriven)(params)
FT = eltype(params)
(; external_forcing_file) = surface_setup
T, lhf, shf = FT.(gcm_surface_conditions(external_forcing_file))
(; external_forcing_file, cfsite_number) = surface_setup
T, lhf, shf =
FT.(gcm_surface_conditions(external_forcing_file, cfsite_number))
z0 = FT(1e-4) # zrough
parameterization = MoninObukhov(; z0, fluxes = HeatFluxes(; lhf, shf))
return SurfaceState(; parameterization, T)
end

function gcm_surface_conditions(external_forcing_file)
function gcm_surface_conditions(external_forcing_file, cfsite_number)
NC.NCDataset(external_forcing_file) do ds
(
mean(gcm_driven_timeseries(ds.group["site23"], "ts")),
mean(gcm_driven_timeseries(ds.group["site23"], "hfls")),
mean(gcm_driven_timeseries(ds.group["site23"], "hfss")),
mean(gcm_driven_timeseries(ds.group[cfsite_number], "ts")),
mean(gcm_driven_timeseries(ds.group[cfsite_number], "hfls")),
mean(gcm_driven_timeseries(ds.group[cfsite_number], "hfss")),
)
end
end

0 comments on commit c9b7d73

Please sign in to comment.