-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3d396b
commit a0fabee
Showing
2 changed files
with
123 additions
and
41 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
experiments/ClimaEarth/components/ocean/prescr_ocean.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# import ClimaUtilities.TimeVaryingInputs: TimeVaryingInput, evaluate! | ||
# import ClimaUtilities.ClimaArtifacts: @clima_artifact | ||
import Thermodynamics as TD | ||
import ClimaCoupler: Checkpointer, FluxCalculator, Interfacer, Utilities | ||
|
||
""" | ||
PrescribedOceanSimulation{P, Y, D, I} | ||
Sea surface temperature (SST) is prescribed and read in directly from a file | ||
at each timestep. | ||
Ocean roughness follows the https://github.com/NOAA-GFDL/ice_param/blob/main/ocean_rough.F90#L47. | ||
The cache is expected to contain the following variables: | ||
- `T_sfc` (surface temperature [K]) | ||
- `ρ_sfc` (surface air density [kg / m3]) | ||
- `z0m` (roughness length for momentum [m]) | ||
- `z0b` (roughness length for tracers [m]) | ||
- `beta` (evaporation scaling factor) | ||
- `α_direct` (direct albedo) | ||
- `α_diffuse` (diffuse albedo) | ||
- `area_fraction` (fraction of the grid cell covered by the ocean) | ||
- `phase` (phase of the water used to calculate surface humidity) | ||
- `thermo_params` (thermodynamic parameters) | ||
- `SST_timevaryinginput` (TimeVaryingInput object containing SST data) | ||
""" | ||
struct PrescribedOceanSimulation{I} <: Interfacer.SurfaceStub | ||
cache::I | ||
end | ||
Interfacer.name(::PrescribedOceanSimulation) = "PrescribedOceanSimulation" | ||
|
||
""" | ||
PrescribedOceanSimulation( | ||
::Type{FT}, | ||
space, | ||
date0, | ||
area_fraction, | ||
thermo_params, | ||
comms_ctx; | ||
z0m = FT(5.8e-5), | ||
z0b = FT(5.8e-5), | ||
beta = FT(1), | ||
α_direct_val = FT(0.06), | ||
α_diffuse_val = FT(0.06), | ||
phase = TD.Liquid(), | ||
) | ||
Initialize the `PrescribedOceanSimulation` object with all required cache fields, | ||
and reading in prescribed SST data. | ||
""" | ||
function PrescribedOceanSimulation( | ||
::Type{FT}, | ||
space, | ||
date0, | ||
area_fraction, | ||
thermo_params, | ||
comms_ctx; | ||
z0m = FT(5.8e-5), | ||
z0b = FT(5.8e-5), | ||
beta = FT(1), | ||
α_direct_val = FT(0.06), | ||
α_diffuse_val = FT(0.06), | ||
phase = TD.Liquid(), | ||
) where {FT} | ||
# Read in initial SST data | ||
sst_data = try | ||
joinpath(@clima_artifact("historical_sst_sic", comms_ctx), "MODEL.SST.HAD187001-198110.OI198111-202206.nc") | ||
catch error | ||
@warn "Using lowres SST. If you want the higher resolution version, you have to obtain it from ClimaArtifacts" | ||
joinpath( | ||
@clima_artifact("historical_sst_sic_lowres", comms_ctx), | ||
"MODEL.SST.HAD187001-198110.OI198111-202206_lowres.nc", | ||
) | ||
end | ||
|
||
SST_timevaryinginput = TimeVaryingInput( | ||
sst_data, | ||
"SST", | ||
space, | ||
reference_date = date0, | ||
file_reader_kwargs = (; preprocess_func = (data) -> data + FT(273.15),), ## convert to Kelvin | ||
) | ||
|
||
SST_init = zeros(space) | ||
evaluate!(SST_init, SST_timevaryinginput, t_start) | ||
|
||
# Create the cache | ||
cache = (; | ||
T_sfc = SST_init, | ||
ρ_sfc = zeros(space), | ||
z0m = z0m, | ||
z0b = z0b, | ||
beta = beta, | ||
α_direct = ones(space) .* α_direct_val, | ||
α_diffuse = ones(space) .* α_diffuse_val, | ||
area_fraction = area_fraction, | ||
phase = phase, | ||
thermo_params = thermo_params, | ||
SST_timevaryinginput = SST_timevaryinginput, | ||
) | ||
return PrescribedOceanSimulation(cache) | ||
end | ||
|
||
""" | ||
step!(sim::PrescribedOceanSimulation, t) | ||
Update the cached surface temperature field using the prescribed data | ||
at each timestep. | ||
This is the only function we extend explicitly for the `PrescribedOceanSimulation`; | ||
all other functions are inherited from `SurfaceStub`. | ||
""" | ||
function step!(sim::PrescribedOceanSimulation, t) | ||
evaluate!(sim.cache.T_sfc, sim.cache.SST_timevaryinginput, t) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters