Skip to content

Commit

Permalink
soil moisture and vegetation
Browse files Browse the repository at this point in the history
  • Loading branch information
milankl committed Oct 19, 2023
1 parent bd732fb commit 0c44b11
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 80 deletions.
1 change: 1 addition & 0 deletions src/dynamics/diagnostic_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Base.@kwdef struct SurfaceVariables{NF<:AbstractFloat,Grid<:AbstractGrid{NF}}

precip_large_scale::Grid = zeros(Grid,nlat_half) # large scale precipitation (for output)
precip_convection::Grid = zeros(Grid,nlat_half) # convective precipitation (for output)
soil_moisture_availability::Grid = zeros(Grid,nlat_half)
end

# generator function based on a SpectralGrid
Expand Down
8 changes: 6 additions & 2 deletions src/dynamics/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Base.@kwdef struct PrimitiveDryModel{NF<:AbstractFloat, D<:AbstractDevice} <: Pr
# BOUNDARY CONDITIONS
land_sea_mask::AbstractLandSeaMask{NF} = LandSeaMask(spectral_grid)
ocean::AbstractOcean{NF} = SeasonalOceanClimatology(spectral_grid)
land::AbstractLand{NF} = SeasonalLandClimatology(spectral_grid)
land::AbstractLand{NF} = SeasonalLandTemperature(spectral_grid)

# PHYSICS/PARAMETERIZATIONS
physics::Bool = true
Expand Down Expand Up @@ -237,7 +237,9 @@ Base.@kwdef struct PrimitiveWetModel{NF<:AbstractFloat, D<:AbstractDevice} <: Pr
# BOUNDARY CONDITIONS
land_sea_mask::AbstractLandSeaMask{NF} = LandSeaMask(spectral_grid)
ocean::AbstractOcean{NF} = SeasonalOceanClimatology(spectral_grid)
land::AbstractLand{NF} = SeasonalLandClimatology(spectral_grid)
land::AbstractLand{NF} = SeasonalLandTemperature(spectral_grid)
soil::AbstractSoil{NF} = SeasonalSoilMoisture(spectral_grid)
vegetation::AbstractVegetation{NF} = VegetationClimatology(spectral_grid)

# PHYSICS/PARAMETERIZATIONS
physics::Bool = true
Expand Down Expand Up @@ -287,6 +289,8 @@ function initialize!(model::PrimitiveWet)
initialize!(model.land_sea_mask)
initialize!(model.ocean)
initialize!(model.land)
initialize!(model.soil)
initialize!(model.vegetation)

# parameterizations
initialize!(model.boundary_layer_drag,model)
Expand Down
34 changes: 23 additions & 11 deletions src/dynamics/ocean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Base.@kwdef struct SeasonalOceanClimatology{NF,Grid<:AbstractGrid{NF}} <: Abstra
"filename of sea surface temperatures"
file::String = "sea_surface_temperature.nc"

"Variable name in netcdf file"
varname::String = "sst"

"Grid the sea surface temperature file comes on"
file_Grid::Type{<:AbstractGrid} = FullGaussianGrid

Expand All @@ -39,33 +42,42 @@ function SeasonalOceanClimatology(SG::SpectralGrid;kwargs...)
end

function initialize!(ocean::SeasonalOceanClimatology{NF,Grid}) where {NF,Grid}
load_monthly_climatology!(ocean.monthly_temperature,ocean)
end

function load_monthly_climatology!(
monthly::Vector{Grid},
scheme;
varname::String = scheme.varname
) where {Grid<:AbstractGrid}

# LOAD NETCDF FILE
if ocean.path == "SpeedyWeather.jl/input_data"
path = joinpath(@__DIR__,"../../input_data",ocean.file)
if scheme.path == "SpeedyWeather.jl/input_data"
path = joinpath(@__DIR__,"../../input_data",scheme.file)
else
path = joinpath(ocean.path,ocean.file)
path = joinpath(scheme.path,scheme.file)
end
ncfile = NCDataset(path)

# create interpolator from grid in file to grid used in model
nx, ny = ncfile.dim["lon"], ncfile.dim["lat"]
npoints = nx*ny
NF_file = typeof(ncfile["sst"].attrib["_FillValue"])
sst = ocean.file_Grid(zeros(NF_file,npoints))
interp = RingGrids.interpolator(NF,ocean.monthly_temperature[1],sst)
NF_file = typeof(ncfile[varname].attrib["_FillValue"])
grid = scheme.file_Grid(zeros(NF_file,npoints))
interp = RingGrids.interpolator(Float32,monthly[1],grid)

# interpolate and store in ocean
# interpolate and store in monthly
for month in 1:12
sst_this_month = ncfile["sst"][:,:,month]
this_month = ncfile[varname][:,:,month]
ij = 0
for j in 1:ny
for i in 1:nx
ij += 1
x = sst_this_month[i,j]
sst[ij] = ismissing(x) ? ocean.missing_value : x
x = this_month[i,j]
grid[ij] = ismissing(x) ? scheme.missing_value : x
end
end
interpolate!(ocean.monthly_temperature[month],sst,interp)
interpolate!(monthly[month],grid,interp)
end
return nothing
end
Expand Down
8 changes: 4 additions & 4 deletions src/dynamics/prognostic_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ Base.@kwdef mutable struct PrognosticVariablesLand{NF<:AbstractFloat,Grid<:Abstr
"Snow depth [m]"
const snow_depth::Grid = zeros(Grid,nlat_half)

"Soil wetness layer 1, volume fraction [1]"
const soil_wetness_layer1::Grid = zeros(Grid,nlat_half)
"Soil moisture layer 1, volume fraction [1]"
const soil_moisture_layer1::Grid = zeros(Grid,nlat_half)

"Soil wetness layer 2, volume fraction [1]"
const soil_wetness_layer2::Grid = zeros(Grid,nlat_half)
"Soil moisture layer 2, volume fraction [1]"
const soil_moisture_layer2::Grid = zeros(Grid,nlat_half)
end

# generator function based on a SpectralGrid
Expand Down
17 changes: 11 additions & 6 deletions src/dynamics/time_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,17 @@ function timestep!( progn::PrognosticVariables{NF}, # all prognostic variables
model.feedback.nars_detected && return nothing # exit immediately if NaRs already present
(;time) = progn.clock # current time

ocean_timestep!(progn.ocean,time,model)
land_timestep!(progn.land,time,model)

# switch on/off all physics
model.physics && parameterization_tendencies!(diagn,progn,time,model)
model.physics || zero_tendencies!(diagn) # set tendencies to zero otherwise
if model.physics # switch on/off all physics parameterizations
# time step ocean (temperature and TODO sea ice) and land (temperature and soil moisture)
ocean_timestep!(progn.ocean,time,model)
land_timestep!(progn.land,time,model)
soil_moisture_availability!(diagn.surface,progn.land,model)

# calculate all parameterizations
parameterization_tendencies!(diagn,progn,time,model)
else # set tendencies to zero otherwise for accumulators
zero_tendencies!(diagn)
end

dynamics_tendencies!(diagn,progn,model,lf2) # dynamical core
implicit_correction!(diagn,model.implicit,progn) # semi-implicit time stepping corrections
Expand Down
1 change: 1 addition & 0 deletions src/physics/column_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function get_column!( C::ColumnVariables,
# TODO skin = surface approximation for now
C.skin_temperature_sea = P.ocean.sea_surface_temperature[ij]
C.skin_temperature_land = P.land.land_surface_temperature[ij]
C.soil_moisture_availability = D.surface.soil_moisture_availability[ij]
end

"""Recalculate ring index if not provided."""
Expand Down
1 change: 1 addition & 0 deletions src/physics/define_column.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Base.@kwdef mutable struct ColumnVariables{NF<:AbstractFloat} <: AbstractColumnV
surface_wind_speed::NF = 0
skin_temperature_sea::NF = 0
skin_temperature_land::NF = 0
soil_moisture_availability::NF = 0

# THERMODYNAMICS
surface_air_density::NF = 0
Expand Down
Loading

0 comments on commit 0c44b11

Please sign in to comment.