-
Notifications
You must be signed in to change notification settings - Fork 24
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
Vorticity initial conditions #153
Vorticity initial conditions #153
Conversation
There's a Julia subtlety that I don't get, but noticed while doing this PR: (LowerTriangularMatrix{Complex{NF}} <: LowerTriangularMatrix) == true but (Vector{LowerTriangularMatrix{Complex{NF}}} <: Vector{LowerTriangularMatrix}) == false I know that for parametric types the type without the parameter is automatically the supertype (and abstract) to all discrete types, but this doesn't work as I expected for the Vector anymore. One can do (Vector{LowerTriangularMatrix{Complex{NF}}} <: Vector{<:LowerTriangularMatrix}) == false though |
Isn't this precisely the invariance of Julia types discussed here? |
Ah yes, you are right. I also did encounter this before, but somehow wasn't thinking about it in that way. |
I very much like the idea to have the initial conditions easily choosable with arrays that are defined in the REPL before p,d,m = initialize_speedy(kwargs...)
p.layers[1].leapfrog[1].vor .= ... # change vorticity, or any other prognostic variable
time_stepping!(p,d,m) where the second line could also be replaced by something like set_vorticity!(p,some_array...)
set_divergence!(p,some_other_data...)
... which could take |
lmax,mmax = size(vor_new) .- (2,1) | ||
|
||
vor_ic_trunc = spectral_truncation(layer_ic, lmax+1, mmax) | ||
vor_new .= convert(LowerTriangularMatrix{Complex{NF}}, vor_ic_trunc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we still have #135 open, meaning that vor_new .= some_array
may not do what you expect it too. To avoid this broadcasting issue in the first place I've already defined copyto!
for :LowerTriangularMatrix
which can handle the type conversion in convert
implicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just copied from the initialize_from_file!
function. Then that should also be looked at, but we can also replace that function with set_vorticity!
etc as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point!
progn, diagn, model = initialize_speedy(initial_conditions=ic,model=:barotropic) | ||
for layers in progn.layers | ||
for leapfrog in layers.leapfrog | ||
@test all(leapfrog.vor .== 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the open broadcasting issue related to the comment above, note that this is a redundant test: Replacing zeros with zeros would pass even if nothing is actually done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as well, that's essentially the same test as already done for the other initialisations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, boooh past me setting up shitty tests 😆
@test all(leapfrog.vor .== 0) | ||
@test all(leapfrog.div .== 0) | ||
end | ||
end | ||
@test all(progn.pres.leapfrog[1] .== 0) | ||
@test all(progn.pres.leapfrog[2] .== 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
@@ -109,7 +109,8 @@ The default values of the keywords define the default model setup. | |||
|
|||
# INITIAL CONDITIONS | |||
seed::Int = abs(rand(Int)) # a random seed that's used in initialize_speedy for the global RNG | |||
initial_conditions::Symbol=:barotropic_vorticity # :rest, :barotropic_vorticity or :restart | |||
initial_conditions::Union{Symbol, Vector}=:barotropic_vorticity # :rest, :barotropic_vorticity, :restart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another problem I see here is that with output=true
the parameters struct is printed to parameters.txt
such that one can easily trace back what parameters were used in a given simulation. I'm not sure what happens if a big array is part of the parameters struct. This also applies to setting the vertical levels manually, which I haven't checkedn. Those ones, ideally, should be written into that .txt file (as just a vector) but entire vectors or matrices obviously not...
Mh, initial conditions do belong to a well defined differential equation problem, so I am not fundamentally opposed to including them in the Parameters (as this is also currently the only way input arguments are handled). However, I also like your idea of having flexible |
I am working on a new draft for this |
Thanks! I'm busy this week, but happy to review code. I absolutely agree with you that technically the initial conditions should be part of the problem. Having said that, at the moment we do set up a fully defined "speedy problem" with In order to be consistent I'd probably suggest to allow any |
This is closed in favour of #154 |
I first wanted to do it by requiring to hand over an instance of
PrognosticVariables
, but for that you have the problem again thatPrognosticVariables
are not defined at the time the inputs are handles. Changing that would need larger changes, so I am thinking handing over initial conditions asVector{LowerTriangluarMatrix}
is fine