Skip to content

Commit

Permalink
Refactor getvcellcoordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Aug 6, 2023
1 parent 88560b0 commit 75925b9
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/vlsv/vlsvutility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,9 @@ function getvcellcoordinates(meta::MetaVLSV, vcellids::Vector{Int32};
for cid in vcellblockids]

# Get cell coordinates
cellCoords = [SVector(0.0f0, 0.0f0, 0.0f0) for _ in vcellblockids]
@inbounds @simd for i in eachindex(vcellblockids)
cellCoords[i] = [blockCoord[i][j] + (cellidxyz[i][j] + 0.5) * dv[j] for j in 1:3]
end
cellCoords = [
@SVector [Float32(blockCoord[i][j] + (cellidxyz[i][j] + 0.5) * dv[j]) for j in 1:3]
for i in eachindex(vcellblockids)]

cellCoords
end
Expand Down Expand Up @@ -1007,10 +1006,7 @@ function getnearestcellwithvdf(meta::MetaVLSV, id::Int, species::String="proton"
cells = meta.meshes[species].cellwithVDF
isempty(cells) && throw(ArgumentError("No distribution saved in $(meta.name)"))
coords_orig = getcellcoordinates(meta, id)
coords = [zeros(SVector{3}) for _ in cells]
@inbounds for i in eachindex(cells)
coords[i] = getcellcoordinates(meta, cells[i])
end
coords = [getcellcoordinates(meta, cid) for cid in cells]
min_ = findmin(c -> sum(abs2, c .- coords_orig), coords)[2]

cells[min_]
Expand Down

0 comments on commit 75925b9

Please sign in to comment.