Skip to content

Commit

Permalink
Remove unsafe bitsets (#610)
Browse files Browse the repository at this point in the history
* fix

* cleanup

* tighter error bound

* update
  • Loading branch information
svchb authored Sep 26, 2024
1 parent ff9ef7a commit 16b6b5d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/general/buffer.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
struct SystemBuffer{V}
active_particle :: BitVector
active_particle :: Vector{Bool}
eachparticle :: V # Vector{Int}
buffer_size :: Int

function SystemBuffer(active_size, buffer_size::Integer)
active_particle = vcat(trues(active_size), falses(buffer_size))
# We cannot use a `BitVector` here, as writing to a `BitVector` is not thread-safe
active_particle = vcat(fill(true, active_size), fill(false, buffer_size))
eachparticle = collect(1:active_size)

return new{typeof(eachparticle)}(active_particle, eachparticle, buffer_size)
Expand Down
3 changes: 2 additions & 1 deletion src/preprocessing/geometries/triangle_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ function unique_sorted(vertices)
# Sort by the first entry of the vectors
compare_first_element = (x, y) -> x[1] < y[1]
vertices_sorted = sort!(vertices, lt=compare_first_element)
keep = trues(length(vertices_sorted))
# We cannot use a `BitVector` here, as writing to a `BitVector` is not thread-safe
keep = fill(true, length(vertices_sorted))

PointNeighbors.@threaded vertices_sorted for i in eachindex(vertices_sorted)
# We only sorted by the first entry, so we have to check all previous vertices
Expand Down
2 changes: 1 addition & 1 deletion src/schemes/boundary/open_boundary/boundary_zones.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ end
function remove_outside_particles(initial_condition, spanning_set, zone_origin)
(; coordinates, density, particle_spacing) = initial_condition

in_zone = trues(nparticles(initial_condition))
in_zone = fill(true, nparticles(initial_condition))

for particle in eachparticle(initial_condition)
current_position = current_coords(coordinates, initial_condition, particle)
Expand Down

0 comments on commit 16b6b5d

Please sign in to comment.