-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tracer advection #579
base: main
Are you sure you want to change the base?
Add tracer advection #579
Conversation
new syntax is add!(model, Tracer(:ch4)) # before initialize! or
add!(simulation, Tracer(:ch4)) # after tracers are now just identified with their |
Tracers can be added ( julia> simulation.prognostic_variables.tracers
Dict{Symbol, Tuple{LowerTriangularArray{ComplexF32, 2, Matrix{ComplexF32}}, LowerTriangularArray{ComplexF32, 2, Matrix{ComplexF32}}}} with 2 entries:
:ch4 => ([0.0+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;], [0.0+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;])
:co2 => ([0.0+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;], [0.0+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;]) can be julia> set!(simulation, ch4=1)
julia> simulation.prognostic_variables.tracers
Dict{Symbol, Tuple{LowerTriangularArray{ComplexF32, 2, Matrix{ComplexF32}}, LowerTriangularArray{ComplexF32, 2, Matrix{ComplexF32}}}} with 2 entries:
:ch4 => ([3.54491+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;], [0.0+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;])
:co2 => ([0.0+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;], [0.0+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;])
julia> set!(simulation, co2=2)
julia> simulation.prognostic_variables.tracers
Dict{Symbol, Tuple{LowerTriangularArray{ComplexF32, 2, Matrix{ComplexF32}}, LowerTriangularArray{ComplexF32, 2, Matrix{ComplexF32}}}} with 2 entries:
:ch4 => ([3.54491+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;], [0.0+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;])
:co2 => ([7.08982+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;], [0.0+0.0im; 0.0+0.0im; … ; 0.0+0.0im; 0.0+0.0im;;]) @maximilian-gelbrecht which I implemented simply by checking whether additional julia> set!(simulation, co3=2)
ERROR: UndefVarError: `co3` not defined Technically we could do the same to avoid all the predefined |
This seems to work! out.mp4done via spectral_grid = SpectralGrid(trunc=63, nlayers=1)
model = ShallowWaterModel(spectral_grid)
# add tracer
add!(model, Tracer(:co2))
add!(model, SpeedyWeather.TracerOutput())
simulation = initialize!(model)
# set tracer and run a simulation
set!(simulation, co2 = (λ, φ, σ) -> 0 < λ < 10 ? 1 : 0)
run!(simulation, period=Day(10))
# reset tracer but continue simulation
set!(simulation, co2 = (λ, φ, σ) -> exp(-(λ-180)^2/10^2))
run!(simulation, period=Day(10), output=true) |
And T170 resolution and 20days long out.mp4 |
If everything passes this is ready to go. Tracer output needs some overhaul, but I want #633 merged first so will simply do this in another pull request |
Great! I can do a review tomorrow or Friday. |
Okay, docs built, see here https://speedyweather.github.io/SpeedyWeather.jl/previews/PR579/tracers/ hope you like the interface to tracers!! |
I also think this is a good test case for the semi-Lagrangian advection I've been dreaming about! Because that should allow us to get to maybe 3-4k SYPD at T31 by allowing for larger time steps and cutting down on the number of transforms, especially for all the tracers. Every tracer adds 4 transforms (1x spec-> grid, 1x grid tendencies -> spec, 2x grid -> spec for the fluxes with u,v). So we could
The reason I say "dreaming" is that the semi-implicit semi-Lagrangian scheme is at the heart of what makes ECMWF's model so fast, allowing really big time steps and making the model very stable. |
fixes #564 by
Tracer
(name,id, active)model.tracers
for a list of tracerslength(model.tracers)
add additional progn/diagn variablesset!
for tracers