Add/remove Lagrangian particles #3884
-
Hello, I am trying to model methane bubbles using Lagrangian particles and need to remove particles when they reach the surface. When I remove a particle using bubble = LazyRow(particles.properties, n)
bubble.z += wₚ * Δt
if bubble.z > -0.01
StructArrays.foreachfield(v -> deleteat!(v, n), particles.properties)
end I got and DivideError (see below) Is there a proper way to delete particles on the surface and release new ones on the bottom during simulation? Thank you.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 21 replies
-
Hi @alesok! Lagrangian particle advection should work even as you add and remove particles by modifying the I suspect you're seeing this error because there are zero particles left, and KernelAbstractions.jl is trying to partition the amount of work to be done but ends up dividing by zero somewhere using the
I'm not sure whether to classify this as a bug. Oceananigans could do nothing if there are zero particles. If this is something you're interested in working on, pull requests are very welcome! The quick and easy solution might be to ensure that there's always at least one particle around to be advected. PS: Hope it's okay that I modified your post to format your code and stack trace using triple backticks ( |
Beta Was this translation helpful? Give feedback.
-
On 31 Oct 2024, at 19:43, Gregory L. Wagner ***@***.***> wrote:
So I can run a model with 0 particles for a while and then can start releasing particles every say 60 seconds from the bottom and need to take care not to remove the very last particle. Good for me.
Thank you
For sure @alesok <https://github.com/alesok> there is no question in my mind that this feature is important, and that not supporting is legitimately a bug. Users should not have to stress about how many particles they have. 0 is a number.
For some reason
particles = LagrangianParticles(StructArray{Bubble}(undef,0), restitution=1.0, dynamics=bubble_dynamics!,
tracked_fields=(T=tracers.T, S=tracers.S)
)
Gives ERROR: DivideError: integer division error (see below)
But
particles = LagrangianParticles(StructArray{Bubble}(undef,1), restitution=1.0, dynamics=bubble_dynamics!,
tracked_fields=(T=tracers.T, S=tracers.S)
)
Works as expected (despite undef)
It is OK with me, seems to be something
Thank you
```
[ Info: Initializing simulation...
Iteration: 0000, time: 0 seconds, Δt: 11 seconds, max(|u|, |v|, |w|) = (1.5e-05, 1.6e-05, 1.2e-05) ms⁻¹, wall time: 0 seconds
[ Info: ... simulation initialization complete (6.467 seconds)
[ Info: Executing initial time step...
ERROR: DivideError: integer division error
Stacktrace:
[1] div
@ ./int.jl:295 [inlined]
[2] div
@ ./div.jl:310 [inlined]
[3] div
@ ./div.jl:355 [inlined]
[4] fld
@ ./div.jl:321 [inlined]
[5] mod
@ ./int.jl:287 [inlined]
[6] #4
@ ~/.julia/packages/KernelAbstractions/491pi/src/nditeration.jl:121 [inlined]
[7] ntuple
@ ./ntuple.jl:48 [inlined]
[8] partition(ndrange::Tuple{Int64}, __workgroupsize::Tuple{Int64})
@ KernelAbstractions.NDIteration ~/.julia/packages/KernelAbstractions/491pi/src/nditeration.jl:119
[9] partition
@ ~/.julia/packages/KernelAbstractions/491pi/src/KernelAbstractions.jl:640 [inlined]
[10] launch_config
@ ~/.julia/packages/KernelAbstractions/491pi/src/cpu.jl:87 [inlined]
[11] (::KernelAbstractions.Kernel{…})(::Vector{…}, ::Vararg{…}; ndrange::Nothing, workgroupsize::Nothing)
@ KernelAbstractions ~/.julia/packages/KernelAbstractions/491pi/src/cpu.jl:40
[12] (::KernelAbstractions.Kernel{…})(::Vector{…}, ::Vararg{…})
@ KernelAbstractions ~/.julia/packages/KernelAbstractions/491pi/src/cpu.jl:39
[13] update_lagrangian_particle_properties!(particles::LagrangianParticles{…}, model::NonhydrostaticModel{…}, Δt::Float64)
@ Oceananigans.Models.LagrangianParticleTracking ~/.julia/packages/Oceananigans/BJj1C/src/Models/LagrangianParticleTracking/update_lagrangian_particle_properties.jl:31
[14] step_lagrangian_particles!(particles::LagrangianParticles{…}, model::NonhydrostaticModel{…}, Δt::Float64)
@ Oceananigans.Models.LagrangianParticleTracking ~/.julia/packages/Oceananigans/BJj1C/src/Models/LagrangianParticleTracking/LagrangianParticleTracking.jl:137
[15] step_lagrangian_particles!
@ ~/.julia/packages/Oceananigans/BJj1C/src/Models/NonhydrostaticModels/NonhydrostaticModels.jl:112 [inlined]
[16] time_step!(model::NonhydrostaticModel{…}, Δt::Float64; callbacks::Tuple{})
@ Oceananigans.TimeSteppers ~/.julia/packages/Oceananigans/BJj1C/src/TimeSteppers/runge_kutta_3.jl:115
[17] time_step!(sim::Simulation{…})
@ Oceananigans.Simulations ~/.julia/packages/Oceananigans/BJj1C/src/Simulations/run.jl:122
[18] run!(sim::Simulation{…}; pickup::Bool)
@ Oceananigans.Simulations ~/.julia/packages/Oceananigans/BJj1C/src/Simulations/run.jl:97
[19] run!(sim::Simulation{…})
@ Oceananigans.Simulations ~/.julia/packages/Oceananigans/BJj1C/src/Simulations/run.jl:85
[20] top-level scope
@ ~/MyFiles/Oceananigans_Himmerfjärden/src/cube.jl:114
Some type information was truncated. Use `show(err)` to see complete types.
```
… —
Reply to this email directly, view it on GitHub <#3884 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AH5SLJ5CEWQ7HNI4HTZ5QZ3Z6J25DAVCNFSM6AAAAABQ3QFXU2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMJRGUZDKOI>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
On 31 Oct 2024, at 23:17, Gregory L. Wagner ***@***.***> wrote:
what is length(StructArray{Bubble}(undef,0))?
```
julia> length(StructArray{Bubble}(undef,0))
0
```
|
Beta Was this translation helpful? Give feedback.
Hi @alesok! Lagrangian particle advection should work even as you add and remove particles by modifying the
particle.properties
struct array as you seem to be doing.I suspect you're seeing this error because there are zero particles left, and KernelAbstractions.jl is trying to partition the amount of work to be done but ends up dividing by zero somewhere using the
div
function. You can reproduce the same error easily:I'm not sure whether to classify this as a bug. Oceananigans could do nothing if there are zero particles. If thi…