Skip to content

Commit

Permalink
Merge pull request #580 from SpeedyWeather/mg/set-docs-kwargs
Browse files Browse the repository at this point in the history
Set! documentation / keywords
  • Loading branch information
maximilian-gelbrecht authored Sep 27, 2024
2 parents aad3f18 + 4f09843 commit a3fc887
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- Extend `set!` with `orography` keyword argument to set the orography with `set!` [#578](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/578)
- Added a new benchmark suite for the dynamics functions [#577](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/577)
- Introduced a new `set!` function that allows to set `PrognosticVariables` to new values with keyword arguments
- Introduced a new `set!` function that allows to set `PrognosticVariables` to new values with keyword arguments [#563](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/563)
- Restructured dynamical core with prognostic/diagnostic variables array-agnostic and 3-dimensional [#525](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/525)
- Modularised NetCDF output [#573](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/573)
- Fixed a bug in RingGrids, now broadcasts are defined even when the dimensions mismatch in some cases [#568](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/568)
Expand Down
6 changes: 6 additions & 0 deletions src/dynamics/orography.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ function set!(
end

# convenient function barrier to use geometry, spectral_transform and gravity from model
"""
$(TYPEDSIGNATURES)
Sets a new `orography` for the `model`. The input can be a function, `RingGrid`, `LowerTriangularMatrix`,
or scalar as for other `set!` functions. If the keyword `add==true` the input is added to the exisiting
orography instead.
"""
function set!(model::AbstractModel; orography, kwargs...)
set!(model.orography, orography, model.geometry, model.spectral_transform;
gravity=model.planet.gravity, kwargs...)
Expand Down
37 changes: 22 additions & 15 deletions src/dynamics/prognostic_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,28 @@ function set!(
soil_moisture_layer2 = nothing,
lf::Integer = 1,
add::Bool = false,
S::Union{Nothing, SpectralTransform} = nothing,
spectral_transform::Union{Nothing, SpectralTransform} = nothing,
coslat_scaling_included::Bool = false,
)
# ATMOSPHERE
isnothing(vor) || set!(progn.vor[lf], vor, geometry, S; add)
isnothing(div) || set!(progn.div[lf], div, geometry, S; add)
isnothing(temp) || set!(progn.temp[lf], temp, geometry, S; add)
isnothing(humid) || set!(progn.humid[lf], humid, geometry, S; add)
isnothing(pres) || set!(progn.pres[lf], pres, geometry, S; add)
isnothing(vor) || set!(progn.vor[lf], vor, geometry, spectral_transform; add)
isnothing(div) || set!(progn.div[lf], div, geometry, spectral_transform; add)
isnothing(temp) || set!(progn.temp[lf], temp, geometry, spectral_transform; add)
isnothing(humid) || set!(progn.humid[lf], humid, geometry, spectral_transform; add)
isnothing(pres) || set!(progn.pres[lf], pres, geometry, spectral_transform; add)

# or provide u, v instead of vor, div
isnothing(u) | isnothing(v) || set_vordiv!(progn.vor[lf], progn.div[lf], u, v, geometry, S; add, coslat_scaling_included)
isnothing(u) | isnothing(v) || set_vordiv!(progn.vor[lf], progn.div[lf], u, v, geometry, spectral_transform; add, coslat_scaling_included)

# OCEAN
isnothing(sea_surface_temperature) || set!(progn.ocean.sea_surface_temperature, sea_surface_temperature, geometry, S; add)
isnothing(sea_ice_concentration) || set!(progn.ocean.sea_ice_concentration, sea_ice_concentration, geometry, S; add)
isnothing(sea_surface_temperature) || set!(progn.ocean.sea_surface_temperature, sea_surface_temperature, geometry, spectral_transform; add)
isnothing(sea_ice_concentration) || set!(progn.ocean.sea_ice_concentration, sea_ice_concentration, geometry, spectral_transform; add)

# LAND
isnothing(land_surface_temperature) || set!(progn.land.land_surface_temperature, land_surface_temperature, geometry, S; add)
isnothing(snow_depth) || set!(progn.land.snow_depth, snow_depth, geometry, S; add)
isnothing(soil_moisture_layer1) || set!(progn.land.soil_moisture_layer1, soil_moisture_layer1, geometry, S; add)
isnothing(soil_moisture_layer2) || set!(progn.land.soil_moisture_layer2, soil_moisture_layer2, geometry, S; add)
isnothing(land_surface_temperature) || set!(progn.land.land_surface_temperature, land_surface_temperature, geometry, spectral_transform; add)
isnothing(snow_depth) || set!(progn.land.snow_depth, snow_depth, geometry, spectral_transform; add)
isnothing(soil_moisture_layer1) || set!(progn.land.soil_moisture_layer1, soil_moisture_layer1, geometry, spectral_transform; add)
isnothing(soil_moisture_layer2) || set!(progn.land.soil_moisture_layer2, soil_moisture_layer2, geometry, spectral_transform; add)
return nothing
end

Expand Down Expand Up @@ -439,11 +439,18 @@ function set_vordiv!(
end
end

"""
$(TYPEDSIGNATURES)
Sets properties of the simuluation `S`. Convenience wrapper to call the other concrete
`set!` methods. All `kwargs` are forwarded to these methods, which are documented
seperately. See their documentation for possible `kwargs`.
"""
function set!(S::AbstractSimulation; kwargs...)
set!(S.prognostic_variables, S.model.geometry; S=S.model.spectral_transform, kwargs...)
set!(S.prognostic_variables, S.model.geometry; spectral_transform=S.model.spectral_transform, kwargs...)
end

function set!(progn::PrognosticVariables, model::AbstractModel; kwargs...)
progn.scale[] != 1 && @warn "Prognostic variables are scaled with $(progn.scale[]), but `set!` assumes unscaled variables."
set!(progn, model.geometry; S=model.spectral_transform, kwargs...)
set!(progn, model.geometry; spectral_transform=model.spectral_transform, kwargs...)
end

4 comments on commit a3fc887

@milankl
Copy link
Member

@milankl milankl commented on a3fc887 Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Action not recognized: regster

@milankl
Copy link
Member

@milankl milankl commented on a3fc887 Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/116780

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.0 -m "<description of version>" a3fc8878f210116efae9a844ed160caea4a0cde6
git push origin v0.11.0

Please sign in to comment.