-
Notifications
You must be signed in to change notification settings - Fork 186
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
Passing parameters for nested boundary functions (nested task error: UndefKeywordError: keyword argument <name> not assigned) #2336
Comments
The boundary condition functions should have the arguments Qᵘ(x, y, t, p) = radius(x, y) < p.L ? imag(p.ρₐ / p.ρₒ * p.cᴰ * U(x, y, p.L) * abs(U(x, y, p.L))) : 0 # m² s⁻²
Qᵛ(x, y, t, p) = radius(x, y) < p.L ? - real(p.ρₐ / p.ρₒ * p.cᴰ * U(x, y, p.L) * abs(U(x, y, p.L))) : 0 # m² s⁻² You may also want to tag functions with @inline d(x, y) = sqrt(x^2 + y^2)
@inline U(x, y, L) = sin(π * d(x, y) / L) * exp(1im * angle(x + y*im))
@inline Qᵘ(x, y, t, p) = ifelse(d(x, y) < p.L, +imag(p.ρₐ / p.ρₒ * p.cᴰ * U(x, y, p.L) * abs(U(x, y, p.L))), 0.0) # m² s⁻²
@inline Qᵛ(x, y, t, p) = ifelse(d(x, y) < p.L, -real(p.ρₐ / p.ρₒ * p.cᴰ * U(x, y, p.L) * abs(U(x, y, p.L))), 0.0) # m² s⁻² Is @inline d(x, y) = sqrt(x^2 + y^2)
@inline s(x, y, L) = sin(π * d(x, y) / L) * exp(1im * angle(x + y*im))
@inline Qᵘ(x, y, t, p) = p.τ₀ * ifelse(d(x, y) < p.L, +imag(s(x, y, p.L) * abs(s(x, y, p.L))), 0.0) # m² s⁻²
@inline Qᵛ(x, y, t, p) = p.τ₀ * ifelse(d(x, y) < p.L, -real(s(x, y, p.L) * abs(s(x, y, p.L))), 0.0) # m² s⁻² or something like that! |
Could you explain why using In this case, we only had the wind velocity from the specifications of the computer fans we used for the rotating tank experiment, but I understand that even in this case, I could calculate For the boundary conditions. I was my bad. You specify on the Documentation that
I am just repeating here in case someone falls in the same problem and comes to this issue. |
No, the ternary operator if a
b
else
c
end This
The first call to On the other hand julia> g(a, first) = ifelse(first, a[1], a[2])
g (generic function with 1 method)
julia> g(a, true)
ERROR: BoundsError: attempt to access 1-element Vector{Float64} at index [2]
Stacktrace:
[1] getindex
@ ./array.jl:805 [inlined]
[2] g(a::Vector{Float64}, first::Bool)
@ Main ./REPL[11]:1
[3] top-level scope
@ REPL[12]:1
julia> g(a, false)
ERROR: BoundsError: attempt to access 1-element Vector{Float64} at index [2]
Stacktrace:
[1] getindex
@ ./array.jl:805 [inlined]
[2] g(a::Vector{Float64}, first::Bool)
@ Main ./REPL[11]:1
[3] top-level scope
@ REPL[13]:1
julia> b = rand(2)
2-element Vector{Float64}:
0.5340042876487958
0.7031634999748222
julia> g(b, true)
0.5340042876487958
julia> g(b, false)
0.7031634999748222 It's easier for the compiler to optimize code that involves Some of this is discussed here: https://discourse.julialang.org/t/multiplying-by-booleans-faster-than-if-else/64117
This a little hazier. The compiler decides based on a heuristic whether or not to "inline" a function (meaning, rather than compiling code for a function independently and jumping to that code at the right moment, it combines the function code with the code that calls the function). We want to inline everything basically, so that every tendency evaluation involves evaluating one giant function. Inlining lets LLVM magic optimize our code to the highest degree (at least that's my impression). For whatever reason the compiler often decides not to inline our functions unless we specifically annotate them. So it seems we probably need to add But I suggest you benchmark yourself and see! |
I'm closing this but re-open if there's still work to be done! |
Can someone help me to figure out what I am doing wrong?
I understand that nested functions were not described on the documentation, but it should work right?
I am trying to create an Oceananigans version for iuryt/ocean_gyre_tank.
For the surface momentum flux I am using
Which returns the error below when I try to run the simulation:
Click to expand!
Full code available at OceanGyreTank.jl
The text was updated successfully, but these errors were encountered: