Skip to content

Commit

Permalink
rm bycolumn
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasloan25 committed Jun 24, 2024
1 parent 3733eaf commit d0d677e
Show file tree
Hide file tree
Showing 15 changed files with 693 additions and 738 deletions.
910 changes: 460 additions & 450 deletions .buildkite/pipeline.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/src/fluxcalculator.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Fluxes over a heterogeneous surface (e.g., from a gridpoint where atmospheric ce
ClimaCoupler.FluxCalculator.get_surface_params
ClimaCoupler.FluxCalculator.partitioned_turbulent_fluxes!
ClimaCoupler.FluxCalculator.differentiate_turbulent_fluxes!
ClimaCoupler.FluxCalculator.get_surface_fluxes_point!
ClimaCoupler.FluxCalculator.update_turbulent_fluxes_point!
ClimaCoupler.FluxCalculator.get_surface_fluxes!
ClimaCoupler.FluxCalculator.update_turbulent_fluxes!
ClimaCoupler.FluxCalculator.extrapolate_ρ_to_sfc
ClimaCoupler.FluxCalculator.surface_thermo_state
ClimaCoupler.FluxCalculator.water_albedo_from_atmosphere!
Expand Down
2 changes: 1 addition & 1 deletion docs/src/interfacer.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ following properties:
| `surface_diffuse albedo` | bulk diffuse surface albedo; needed if calculated externally of the surface model (e.g. ocean albedo from the atmospheric state) | |

### SurfaceModelSimulation - optional functions
- `update_turbulent_fluxes_point!(::ComponentModelSimulation, fields::NamedTuple, colidx)`:
- `update_turbulent_fluxes!(::ComponentModelSimulation, fields::NamedTuple)`:
This function updates the turbulent fluxes of the component model simulation
at this point in horizontal space. The values are updated using the energy
and moisture turbulent fluxes stored in fields which are calculated by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,9 @@ CAD.add_diagnostic_variable!(
(; C_E) = cache.atmos.vert_diff
interior_uₕ = CC.Fields.level(state.c.uₕ, 1)
ᶠp = ᶠK_E = cache.scratch.ᶠtemp_scalar
CC.Fields.bycolumn(axes(ᶜp)) do colidx
@. ᶠp[colidx] = CAD.ᶠinterp(ᶜp[colidx])
ᶜΔz_surface = CC.Fields.Δz_field(interior_uₕ)
@. ᶠK_E[colidx] = CA.eddy_diffusivity_coefficient(
C_E,
CA.norm(interior_uₕ[colidx]),
ᶜΔz_surface[colidx] / 2,
ᶠp[colidx],
)
end
@. ᶠp = CAD.ᶠinterp(ᶜp)
ᶜΔz_surface = CC.Fields.Δz_field(interior_uₕ)
@. ᶠK_E = CA.eddy_diffusivity_coefficient(C_E, CA.norm(interior_uₕ), ᶜΔz_surface / 2, ᶠp)
if isnothing(out)
return CAD.ᶜinterp.(ᶠK_E)
else
Expand Down
21 changes: 8 additions & 13 deletions experiments/ClimaEarth/components/land/climaland_bucket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Interfacer.name(::BucketSimulation) = "BucketSimulation"
"""
get_new_cache(p, Y, energy_check)
Returns a new `p` with an updated field to store e_per_area if energy conservation
checks are turned on.
Returns a new `p` with an updated field to store e_per_area if energy conservation
checks are turned on.
"""
function get_new_cache(p, Y, energy_check)
if energy_check
Expand Down Expand Up @@ -216,16 +216,12 @@ Interfacer.step!(sim::BucketSimulation, t) = Interfacer.step!(sim.integrator, t
Interfacer.reinit!(sim::BucketSimulation) = Interfacer.reinit!(sim.integrator)

# extensions required by FluxCalculator (partitioned fluxes)
function FluxCalculator.update_turbulent_fluxes_point!(
sim::BucketSimulation,
fields::NamedTuple,
colidx::CC.Fields.ColumnIndex,
)
function FluxCalculator.update_turbulent_fluxes!(sim::BucketSimulation, fields::NamedTuple)
(; F_turb_energy, F_turb_moisture) = fields
turbulent_fluxes = sim.integrator.p.bucket.turbulent_fluxes
turbulent_fluxes.shf[colidx] .= F_turb_energy
turbulent_fluxes.shf .= F_turb_energy
earth_params = sim.model.parameters.earth_param_set
turbulent_fluxes.vapor_flux[colidx] .= F_turb_moisture ./ LP.ρ_cloud_liq(earth_params)
turbulent_fluxes.vapor_flux .= F_turb_moisture ./ LP.ρ_cloud_liq(earth_params)
return nothing
end

Expand All @@ -234,15 +230,14 @@ function FluxCalculator.surface_thermo_state(
sim::BucketSimulation,
thermo_params::TD.Parameters.ThermodynamicsParameters,
thermo_state_int,
colidx::CC.Fields.ColumnIndex,
)

T_sfc = Interfacer.get_field(sim, Val(:surface_temperature), colidx)
T_sfc = Interfacer.get_field(sim, Val(:surface_temperature))
# Note that the surface air density, ρ_sfc, is computed using the atmospheric state at the first level and making ideal gas
# and hydrostatic balance assumptions. The land model does not compute the surface air density so this is
# a reasonable stand-in.
ρ_sfc = Interfacer.get_field(sim, Val(:air_density), colidx)
q_sfc = Interfacer.get_field(sim, Val(:surface_humidity), colidx) # already calculated in rhs! (cache)
ρ_sfc = Interfacer.get_field(sim, Val(:air_density))
q_sfc = Interfacer.get_field(sim, Val(:surface_humidity)) # already calculated in rhs! (cache)
@. TD.PhaseEquil_ρTq.(thermo_params, ρ_sfc, T_sfc, q_sfc)
end

Expand Down
25 changes: 9 additions & 16 deletions experiments/ClimaEarth/components/ocean/eisenman_seaice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ end
function Interfacer.update_field!(sim::EisenmanIceSimulation, ::Val{:area_fraction}, field::CC.Fields.Field)
sim.integrator.p.area_fraction .= field
end
function Interfacer.update_field!(sim::EisenmanIceSimulation, ::Val{:∂F_turb_energy∂T_sfc}, field, colidx)
sim.integrator.p.Ya.∂F_turb_energy∂T_sfc[colidx] .= field
function Interfacer.update_field!(sim::EisenmanIceSimulation, ::Val{:∂F_turb_energy∂T_sfc}, field)
sim.integrator.p.Ya.∂F_turb_energy∂T_sfc .= field
end
function Interfacer.update_field!(sim::EisenmanIceSimulation, ::Val{:radiative_energy_flux_sfc}, field)
parent(sim.integrator.p.Ya.F_rad) .= parent(field)
Expand All @@ -155,13 +155,9 @@ Interfacer.step!(sim::EisenmanIceSimulation, t) = Interfacer.step!(sim.integrato
Interfacer.reinit!(sim::EisenmanIceSimulation) = Interfacer.reinit!(sim.integrator)

# extensions required by FluxCalculator (partitioned fluxes)
function FluxCalculator.update_turbulent_fluxes_point!(
sim::EisenmanIceSimulation,
fields::NamedTuple,
colidx::CC.Fields.ColumnIndex,
)
function FluxCalculator.update_turbulent_fluxes!(sim::EisenmanIceSimulation, fields::NamedTuple)
(; F_turb_energy) = fields
@. sim.integrator.p.Ya.F_turb[colidx] = F_turb_energy
@. sim.integrator.p.Ya.F_turb = F_turb_energy
end

"""
Expand Down Expand Up @@ -194,23 +190,22 @@ function FluxCalculator.differentiate_turbulent_fluxes!(
fluxes;
δT_sfc = 0.1,
)
(; thermo_state_int, surface_params, surface_scheme, colidx) = input_args
thermo_state_sfc_dT =
FluxCalculator.surface_thermo_state(sim, thermo_params, thermo_state_int, colidx, δT_sfc = δT_sfc)
(; thermo_state_int, surface_params, surface_scheme) = input_args
thermo_state_sfc_dT = FluxCalculator.surface_thermo_state(sim, thermo_params, thermo_state_int, δT_sfc = δT_sfc)
input_args = merge(input_args, (; thermo_state_sfc = thermo_state_sfc_dT))

# set inputs based on whether the surface_scheme is `MoninObukhovScheme` or `BulkScheme`
inputs = surface_inputs(surface_scheme, input_args)

# calculate the surface fluxes
_, _, F_shf_δT_sfc, F_lhf_δT_sfc, _ = get_surface_fluxes_point!(inputs, surface_params)
_, _, F_shf_δT_sfc, F_lhf_δT_sfc, _ = get_surface_fluxes!(inputs, surface_params)

(; F_shf, F_lhf) = fluxes

# calculate the derivative
∂F_turb_energy∂T_sfc = @. (F_shf_δT_sfc + F_lhf_δT_sfc - F_shf - F_lhf) / δT_sfc

Interfacer.update_field!(sim, Val(:∂F_turb_energy∂T_sfc), ∂F_turb_energy∂T_sfc, colidx)
Interfacer.update_field!(sim, Val(:∂F_turb_energy∂T_sfc), ∂F_turb_energy∂T_sfc)
end

###
Expand Down Expand Up @@ -354,9 +349,7 @@ function ∑tendencies(dY, Y, cache, _)
@. dY.T_sfc = -Y.T_sfc / Δt
@. dY.q_sfc = -Y.q_sfc / Δt

CC.Fields.bycolumn(axes(Y.T_sfc)) do colidx
solve_eisenman_model!(Y[colidx], Ya[colidx], p, thermo_params, Δt)
end
solve_eisenman_model!(Y, Ya, p, thermo_params, Δt)

# Get dY/dt
@. dY.T_ml += Y.T_ml / Δt
Expand Down
8 changes: 2 additions & 6 deletions experiments/ClimaEarth/components/ocean/prescr_seaice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,9 @@ Interfacer.step!(sim::PrescribedIceSimulation, t) = Interfacer.step!(sim.integra
Interfacer.reinit!(sim::PrescribedIceSimulation) = Interfacer.reinit!(sim.integrator)

# extensions required by FluxCalculator (partitioned fluxes)
function FluxCalculator.update_turbulent_fluxes_point!(
sim::PrescribedIceSimulation,
fields::NamedTuple,
colidx::CC.Fields.ColumnIndex,
)
function FluxCalculator.update_turbulent_fluxes!(sim::PrescribedIceSimulation, fields::NamedTuple)
(; F_turb_energy) = fields
@. sim.integrator.p.F_turb_energy[colidx] = F_turb_energy
@. sim.integrator.p.F_turb_energy = F_turb_energy
end

"""
Expand Down
8 changes: 2 additions & 6 deletions experiments/ClimaEarth/components/ocean/slab_ocean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,9 @@ Interfacer.step!(sim::SlabOceanSimulation, t) = Interfacer.step!(sim.integrator,
Interfacer.reinit!(sim::SlabOceanSimulation) = Interfacer.reinit!(sim.integrator)

# extensions required by FluxCalculator (partitioned fluxes)
function FluxCalculator.update_turbulent_fluxes_point!(
sim::SlabOceanSimulation,
fields::NamedTuple,
colidx::CC.Fields.ColumnIndex,
)
function FluxCalculator.update_turbulent_fluxes!(sim::SlabOceanSimulation, fields::NamedTuple)
(; F_turb_energy) = fields
@. sim.integrator.p.F_turb_energy[colidx] = F_turb_energy
@. sim.integrator.p.F_turb_energy = F_turb_energy
end

"""
Expand Down
Loading

0 comments on commit d0d677e

Please sign in to comment.