SpeedyWeather / SpeedyWeather.jl

Play atmospheric modelling like it's LEGO.
https://speedyweather.github.io/SpeedyWeather.jl/dev
MIT License
400 stars 24 forks source link

The PrimitiveWetModel example fails #515

Closed markmbaum closed 2 months ago

markmbaum commented 2 months ago

I tried running the example in the readme:

spectral_grid = SpectralGrid(trunc=31, nlev=8)          # define resolution
orography = EarthOrography(spectral_grid)               # create non-default components
model = PrimitiveWetModel(; spectral_grid, orography)   # construct model
simulation = initialize!(model)                         # initialize all model components
run!(simulation, period=Day(10), output=true)           # aaaand action!

and it produces NaNs:

Screenshot 2024-04-05 at 11 16 21β€―AM
milankl commented 2 months ago

Thanks for the interest in this package πŸ‘‹πŸΌ Which version do you use? I cannot reproduce this blowup. In general, if a simulation blows up the most helpful way to report this is

markmbaum commented 2 months ago
milankl commented 2 months ago

On the first time step usually means you already started with NaNs somewhere in the initial conditions. Can you

On the 2nd point maybe this helps https://github.com/SpeedyWeather/SpeedyWeather.jl/issues/350

milankl commented 2 months ago

@markmbaum did this get resolved?

markmbaum commented 2 months ago

It seems to be working now although I really can't explain why. Previously, I just copied that example snippet into a repl and it produced NaNs. Nevermind then!

The docs are generally extremely helpful, but it could be useful to have more indication of which model components are default and/or required. Relatedly, I'm getting an error when trying to use the tree function to look into simulations

julia> using SpeedyWeather

julia> SpeedyWeather.tree
ERROR: UndefVarError: `tree` not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base ./Base.jl:31
 [2] top-level scope
   @ REPL[3]:1

No idea why this is happening, as I can see the export clearly in the source and I'm using the latest version.

milankl commented 2 months ago

tree was only introduced after the latest release, so is only in the main branch not in v0.9 it works there

julia> using SpeedyWeather
julia> spectral_grid = SpectralGrid(trunc=31, nlev=1);
julia> model = ShallowWaterModel(;spectral_grid);
julia> simulation = initialize!(model);
julia> tree(simulation)
Simulation{ShallowWaterModel}
β”œβ”prognostic_variables
β”‚β”œ trunc
β”‚β”œ nlat_half
β”‚β”œ nlev
β”‚β”œ n_steps
β”‚β”œβ”layers
││└┐timesteps
...

The docs are generally extremely helpful, but it could be useful to have more indication of which model components are default and/or required

none are required except for spectral_grid (not even that in v0.9, we made it only mandatory with #519) the defaults are usually best seen in the show of model

julia> model
ShallowWaterModel <: ShallowWater
β”œ spectral_grid: SpectralGrid
β”œ device_setup: SpeedyWeather.DeviceSetup{SpeedyWeather.CPUDevice, DataType}
β”œ geometry: Geometry{Float32}
β”œ planet: Earth{Float32}
β”œ atmosphere: EarthAtmosphere{Float32}
β”œ coriolis: Coriolis{Float32}
β”œ orography: EarthOrography{Float32, OctahedralGaussianGrid{Float32}}
β”œ forcing: NoForcing
β”œ drag: NoDrag
β”œ particle_advection: NoParticleAdvection
β”œ initial_conditions: InitialConditions{ZonalJet, ZeroInitially, ZeroInitially, ZeroInitially}
β”œ time_stepping: Leapfrog{Float32}
β”œ spectral_transform: SpectralTransform{Float32}
β”œ implicit: ImplicitShallowWater{Float32}
β”œ horizontal_diffusion: HyperDiffusion{Float32}
β”œ output: OutputWriter{Float32, ShallowWater}
β”œ callbacks: Dict{Symbol, SpeedyWeather.AbstractCallback}
β”” feedback: Feedback

which shows all fields and their respective types that tell you what defaults are. You can then further inspect each of these, e.g.

julia> model.time_stepping
Leapfrog{Float32} <: SpeedyWeather.AbstractTimeStepper
β”œ trunc::Int64 = 31
β”œ Ξ”t_at_T31::Second = 1800 seconds
β”œ radius::Float32 = 6.371e6
β”œ adjust_with_output::Bool = true
β”œ robert_filter::Float32 = 0.05
β”œ williams_filter::Float32 = 0.53
β”œ Ξ”t_millisec::Dates.Millisecond = 1800000 milliseconds
β”œ Ξ”t_sec::Float32 = 1800.0
β”” Ξ”t::Float32 = 0.0002825302
milankl commented 2 months ago

For more information always check the docstring (with ?) of the respective type (every model component is an instance of its own (struct) type), e.g.

help?> Leapfrog
search: Leapfrog

  Leapfrog time stepping defined by the following fields

    β€’  trunc::Int64: spectral resolution (max degree of spherical harmonics)

    β€’  Ξ”t_at_T31::Second: time step in minutes for T31, scale linearly to trunc

    β€’  radius::AbstractFloat: radius of sphere [m], used for scaling

    β€’  adjust_with_output::Bool: adjust Ξ”tatT31 with the outputdt to reach outputdt exactly
       in integer time steps

    β€’  robert_filter::AbstractFloat: Robert (1966) time filter coefficeint to suppress
       comput. mode

    β€’  williams_filter::AbstractFloat: Williams time filter (Amezcua 2011) coefficient for
       3rd order acc

    β€’  Ξ”t_millisec::Dates.Millisecond: time step Ξ”t [ms] at specified resolution

    β€’  Ξ”t_sec::AbstractFloat: time step Ξ”t [s] at specified resolution

    β€’  Ξ”t::AbstractFloat: time step Ξ”t [s/m] at specified resolution, scaled by 1/radius

  ──────────────────────────────────────────────────────────────────────────────────────────────

  Leapfrog(spectral_grid::SpectralGrid; kwargs...) -> Leapfrog

  Generator function for a Leapfrog struct using spectral_grid for the resolution information.
markmbaum commented 2 months ago

Ok thank you!

tree was only introduced after the latest release, so is only in the main branch not in v0.9 it works there

Have you thought about a patch release when the docs get updated with things that are not yet in the latest version? Meaning 0.9.1. I could submit a PR.

milankl commented 2 months ago

Well that's why there are several version of the docs, /dev for the main branch, and then the various versions. I do agree we are due another release but I want to merge a few pull requests for that first!

markmbaum commented 2 months ago

Ah I see, that was my confusion as well. I thought I was on the stable docs.