-
Notifications
You must be signed in to change notification settings - Fork 78
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
3D simulations for several shape: flow u is NaN or 0 #70
Comments
Can you put up a complete minimal example reproducing the problem? |
# disk_and_box_2D.jl
using WaterLily
using StaticArrays
using GLMakie
import CUDA
@assert CUDA.functional()
include("plot.jl")
function disk(p=6; Re=2e2, mem=Array, U=1)
n = 2^p
center = SA[n/2, n/2]
R = n / 4
ν = U * R / Re
norm2(x) = √sum(abs2, x)
body = AutoBody() do xyz, t
norm2(xyz - center) - R
end
Simulation((2n, n), (U, 0), R; ν, body, mem), center
end
sim, center = disk(mem=CUDA.CuArray);
dat = sim.flow.σ[inside(sim.flow.σ)] |> Array;
makie_video!(sim, dat, ω_θ!, name="disk.mp4", duration=10, step=0.25) do obs, ext
f = Figure()
x, y, m = size(sim.flow.V)
ax = Axis(f[1, 1], limits=(0, x - m, 0, y - m), aspect=DataAspect())
contourf!(ax, obs, levels=ext)
body_plot!(ax, sim)
tightlimits!(ax)
f
end
function box(p=6; Re=2e2, mem=Array, U=1)
n = 2^p
center = SA[n/2, n/2]
R = n / 4
r = n / 16
ν = U * R / Re
norm2(x) = √sum(abs2, x)
body = AutoBody() do xyz, t
d = abs.(xyz - center) - SA[R, r]
norm2(max.(d, 0.0)) + min(maximum(d), 0.0)
end
Simulation((2n, n), (U, 0), R; ν, body, mem), center
end
sim, center = box(mem=CUDA.CuArray);
dat = sim.flow.σ[inside(sim.flow.σ)] |> Array;
makie_video!(sim, dat, ω_θ!, name="box.mp4", duration=10, step=0.25) do obs, ext
f = Figure()
x, y, m = size(sim.flow.V)
ax = Axis(f[1, 1], limits=(0, x - m, 0, y - m), aspect=DataAspect())
contourf!(ax, obs, levels=ext)
body_plot!(ax, sim)
tightlimits!(ax)
f
end # plot.jl
function ω_θ!(dat, sim, center=center)
dt, a = sim.L / sim.U, sim.flow.σ
@inside a[I] = WaterLily.curl(3, I, sim.flow.u) * dt
copyto!(dat, a[inside(a)])
end
function makie_video!(makie_plot, sim, dat, obs_update!; remeasure=false, name="file.mp4", duration=1, step=0.1, framerate=30, compression=20)
t₀ = round(sim_time(sim))
t = range(t₀, t₀ + step; step)
X = obs_update!(dat, sim)
for tᵢ in t
sim_step!(sim, tᵢ; remeasure)
X = obs_update!(dat, sim)
end
obs = X |> Observable
ext = lift(obs) do x
i, a = extrema(x)
LinRange(i, a, 20)
end
f = makie_plot(obs, ext)
t = range(t₀, t₀ + duration; step)
record(f, name, t; framerate, compression) do tᵢ
sim_step!(sim, tᵢ; remeasure)
X = obs_update!(dat, sim)
obs[] = X
println("simulation ", round(Int, (tᵢ - t₀) / duration * 100), "% complete")
println("length: ", length(sim.flow.u), ", nan: ", count(isnan, sim.flow.u), ", zero: ", count(iszero, sim.flow.u))
end
return f
end
function body_plot!(ax, sim; levels=[0], R=inside(sim.flow.p))
WaterLily.measure_sdf!(sim.flow.σ, sim.body, WaterLily.time(sim))
contour!(ax, (sim.flow.σ[R] |> Array)'; levels)
end |
In the previous comment, I included two files. The latter is a modified version of the one for plotting in 3D with makie, but for 2D. The former contains two example. One is a 2D disk which behaves correctly, the other one is a rectangular box. As I said before, and also in the case of some 3D body, the flow u is either NaN or 0. |
A good minimum reproducible example should be as short as possible, while still reproducing the error. You should try to get rid of all the packages and functions which aren't related to the issue you're seeing. Can you try to make an example like that? |
# box
using WaterLily
using StaticArrays
function ω_θ!(dat, sim)
dt, a = sim.L / sim.U, sim.flow.σ
@inside a[I] = WaterLily.curl(3, I, sim.flow.u) * dt
copyto!(dat, a[inside(a)])
end
U = 1
n = 2^6
Re = 2e2
center = SA[n/2, n/2]
R = n / 4
r = n / 16
ν = U * R / Re
norm2(x) = √sum(abs2, x)
body = AutoBody() do xyz, t
d = abs.(xyz - center) - SA[R, r]
norm2(max.(d, 0.0)) + min(maximum(d), 0.0)
end
sim = Simulation((2n, n), (U, 0), R; ν, body, mem=Array)
dat = sim.flow.σ[inside(sim.flow.σ)] |> Array;
step = 0.1
duration = 2
t₀ = round(sim_time(sim))
for tᵢ in range(t₀, t₀ + duration; step)
sim_step!(sim, tᵢ)
ω_θ!(dat, sim)
println("length: ", length(sim.flow.u), ", nan: ", count(isnan, sim.flow.u), ", zero: ", count(iszero, sim.flow.u))
end |
Sorry to be so Socratic, but is the problem really with I suggest creating the |
The
Some using WaterLily
using StaticArrays
U = 1
n = 2^6
Re = 2e2
center = SA[n/2, n/2]
R = n / 4
r = n / 16
ν = U * R / Re
norm2(x) = √sum(abs2, x)
body = AutoBody() do xyz, t
d = abs.(xyz - center) - SA[R, r]
norm2(max.(d, 0.0)) + min(maximum(d), 0.0)
end
sim = Simulation((2n, n), (U, 0), R; ν, body, mem=Array)
for f in fieldnames(typeof(sim.flow))
println(f, ":", getfield(sim.flow, f) .|> isnan |> any)
end
#=
sim.flow
u:false
u⁰:false
f:false
p:false
σ:false
V:false
σᵥ:false
μ₀:true
μ₁:true
U:false
Δt:false
ν:false
=# |
Note that #77 has also "fixed" this issue. I use scare-quotes because it hasn't fixed the underlying problem with the function definition and so there are a LOT of undefined normals. |
I discovered this simulator and I am really appreciating it.
I have been playing with it and I found out that in several case, when dealing with 3D shape, like a cylinder, the
sim.flow.u
array is composed by only 0 and NaN.Test it trying the donut example changing its sdf.
Now, maybe I misunderstood something or it is just an unlucky choice of parameters, or it is a problem.
Edit:
The same problem arises with a 2D box.
The text was updated successfully, but these errors were encountered: