VelocityFields.jl is a Julia package for generating and analysing averaged velocity fields from particle datasets. It provides high-level routines to transform raw 3D point and velocity data into either projected planar or cylindrical coordinates, bin the data points and generate a 2D field. The resulting Field object can be exported to and reconstructed from CSV, and its vorticity automatically calculated. For visualisation, it offers a custom built-in quiver-overlaid heatmap generator with fine control over arrowheads and colorbar ticks. Packing3D.jl is used throughout for mesh bounds, data splitting and I/O.
Above image: Time- and azimuthally averaged velocity field for the net motion of 50000 bidisperse particles throughout 1000 horizontal taps. The process shown exhibits strong segregating densification. Fields for the small (a) and large (b) particles are shown separately. Velocity was computed from the net displacement of each particle. Field is mirrored about 𝑟 = 0 to better visually represent the vessel, as the field is azimuthally averaged about 𝜃 ∈ [0,2𝜋].
Public API Overview:
The package exposes a clean, high-level interface designed for users (e.g., Master’s students) who may not be familiar with the lower-level Julia intricacies. All functions automatically dispatch to the appropriate routines based on the provided geometry type.
The key public functions and types are:
-
Field Generation & Analysis:
generate_fieldcompute_vorticity
-
I/O:
field_to_csvcsv_to_field
-
Visualisation:
plot_field
-
Geometry Types:
PlaneCylinder
-
Core Type:
Field
Note: Some internal docstrings may be outdated. The documentation below reflects the current intended usage.
- Public API Overview
- Key Functions
- Data Structures
- How It Works
- Requirements
- Installation
- Examples
- Limitations
- Planned Features
- License
- Contact
VelocityFields.jl is built around a handful of high-level routines that abstract away the details of file I/O, coordinate transformations, parallel processing, and plotting. Whether you need a planar projection or a cylindrical average, a single dispatch call is all that’s required.
Description:
Processes all VTK files in a directory to produce a 2D averaged velocity field. Supports planar or cylindrical geometries, optional data splitting, long-average (displacement-based) mode, and automatic bin-size estimation.
Signature:
generate_field(
dataset_dir::String,
geom;
bin_size::Union{Float64,Nothing}=nothing,
start_idx::Union{Nothing,Int}=nothing,
end_idx::Union{Nothing,Int}=nothing,
split_by::Union{Symbol,Nothing}=nothing,
threshold::Union{<:Real,Nothing}=nothing,
split::Union{Int,Nothing}=nothing,
long_average::Union{Bool,Nothing}=nothing,
timestep::Union{<:Real,Nothing}=nothing,
vector_type::Union{Symbol,Nothing}=nothing
) -> FieldArguments:
dataset_dir(positional): Path to folder withparticles_*.vtkfiles.geom(positional): EitherPlane(...)orCylinder(...).bin_size(kw): Size of each bin; ifnothing, determined from data span.start_idx,end_idx(kw): Slice indices for file selection.split_by,threshold,split(kw): Criteria for partitioning points.long_average,timestep(kw): Enable displacement-based averaging.vector_type(kw): Symbol for velocity field (default:v).
Returns:
A Field instance containing the averaged field, origin, bin size, and geometry type.
Description:
Generates a heatmap of speed with a quiver overlay. Supports fine control of arrow length, colorbar ticks, and output filename.
Signature:
plot_field(
field::Field;
arrow_length::Union{Float64,Nothing}=nothing,
figure_name::Union{String,Nothing}=nothing,
cbar_max::Union{<:Real,Nothing}=nothing
) -> nothingArguments:
field(positional): AFieldinstance.arrow_length(kw): Fixed arrow length (default 0.7×bin_size).figure_name(kw): Output PNG filename (default"velocity_field.png").cbar_max(kw): Max colorbar value (default = data max).
Description:
Computes the mean absolute 2D vorticity of a Field using central differences on the interior grid.
Signature:
compute_vorticity(field::Field) -> Float64Arguments:
field(positional): AFieldinstance fromgenerate_fieldorcsv_to_field.
Returns:
Mean absolute vorticity (units
Description:
Exports a Field to CSV with metadata headers. The CSV includes columns x,y,u,v.
Signature:
field_to_csv(field::Field, filepath::String) -> nothingArguments:
field(positional): AFieldinstance.filepath(positional): Path to write CSV.
Description:
Reconstructs a Field from a CSV produced by field_to_csv, reading metadata and rebuilding the grid.
Signature:
csv_to_field(filepath::String) -> FieldArguments:
filepath(positional): Path to a CSV with metadata andx,y,u,v.
A struct holding
avg_field::Array{Float64,3}— Averaged velocity array[nₓ, nᵧ, 2].origin::Tuple{Float64,Float64}— Lower-left(x_min,y_min).bin_size::Float64— Grid spacing.geometry_type::Symbol—:planeor:cylindrical.
Construct coordinate transforms:
Plane(point::Vector{3}, normal::Vector{3}): defines a local 2D basis.Cylinder(base::Vector{3}, axis::Vector{3}): defines radial/axial coordinates.
- File Discovery: Scan for
particles_*.vtkviaDataSetModule. - Transformation: Use
Geometry.transform_file_datato rotate & project points and velocities. - Binning: Compute provisional bins via
process_file_helperin parallel, then merge. - Post-Processing: Build dense
avg_field, compute origin & dimensions. - Analysis & I/O: Compute vorticity or export/reimport via CSV.
- Visualisation: Heatmap + custom quiver with
plot_field.
- Julia 1.6 or later
- Packing3D.jl for mesh bounds & I/O
- CSV, DataFrames, Distributed
Not yet registered. Install via:
using Pkg
Pkg.develop(url="https://github.com/fjbarter/VelocityFields.jl")See the examples/ directory for:
- Planar velocity field generation & plotting
- Cylindrical field generation with mirrored r
- CSV export/import and vorticity calculation
- Data Format: Only legacy ASCII VTK via Packing3D.
- Geometry: Only planar & cylindrical supported.
- Performance: Depends on
pmapscalability and file I/O.
- Support for divergence computation.
- Extended geometries (spherical, arbitrary surfaces).
- Interactive plotting backend integration.
MIT License. See LICENSE.
Your Name
Email: fjbarter@outlook.com
GitHub: fjbarter/VelocityFields.jl