Skip to content

Commit

Permalink
add dss_state! function
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasloan25 committed Sep 29, 2023
1 parent 9cad2b8 commit 94a93ac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions experiments/AMIP/modular/coupler_driver_modular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ import_combined_surface_fields!(cs.fields, cs.model_sims, cs.boundary_space, tur
import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, turbulent_fluxes)
update_model_sims!(cs.model_sims, cs.fields, turbulent_fluxes)

# 2) call DSS on each of the simulation states to ensure our initial conditions are continuous fields
dss_state!(land_sim)
dss_state!(ocean_sim)
dss_state!(ice_sim)
dss_state!(atmos_sim)

# 2) each surface component model calculates its own vapor specific humidity (q_sfc)
# TODO: the q_sfc calculation follows the design of the bucket q_sfc, but it would be neater to abstract this from step!
step!(land_sim, Δt_cpl)
Expand Down
39 changes: 39 additions & 0 deletions src/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,43 @@ function swap_space!(field_out, field_in::Fields.Field)
return field_out
end

"""
dss_state!(sim::SlabOceanSimulation)
Perform DSS on the state of a component simulation, intended to be used
before the initial step of a run. This method acts on ocean simulations.
"""
function dss_state!(sim::Union{SlabOceanSimulation, PrescribedIceSimulation})
weighted_dss_slab!(sim.integrator.u, sim.integrator.p)
end

"""
dss_state!(sim::BucketSimulation)
Perform DSS on the state of a component simulation, intended to be used
before the initial step of a run. This method acts on bucket land simulations.
The `dss!` function of ClimaLSM must be called because it uses either the 2D
or 3D dss buffer stored in the cache depending on space of each variable in
`sim.integrator.u`.
"""
function dss_state!(sim::BucketSimulation)
ClimaLSM.dss!(sim.integrator.u, sim.integrator.p, sim.integrator.t)
end

"""
dss_state!(sim::ClimaAtmosSimulation)
Perform DSS on the state of a component simulation, intended to be used
before the initial step of a run. This method acts on ClimaAtmos simulations.
These sims don't store a dss buffer in their cache, so we must allocate
one here.
"""
function dss_state!(sim::ClimaAtmosSimulation)
# TODO do we want face or center space here?
buffer = ClimaCore.Spaces.create_dss_buffer(sim.integrator.face_space)
for key in propertynames(Y)
field = getproperty(Y, key)
ClimaCore.Spaces.weighted_dss!(field, buffer)
end
end
end # module

0 comments on commit 94a93ac

Please sign in to comment.