RayTracing.jl generates two-dimensional Method of Characteristics tracks over Gridap unstructured meshes. It builds cyclic track graphs, segments tracks by mesh cell, and computes ray-tracing volumes for neutron transport workflows such as NeutronTransport.jl.
- Unstructured 2D Gridap meshes, including triangles and quadrilaterals.
- Vacuum, reflective, and periodic rectangular-domain boundary conditions.
- Cyclic track connectivity for forward and backward transport sweeps.
- Track segmentation by mesh element.
- Thread-aware track segmentation with
segmentize!(tg; parallel=:auto). - Optional exact geometric volume correction.
- Lightweight Plots.jl recipes through RecipesBase.
import Pkg
Pkg.add("RayTracing")For local development:
import Pkg
Pkg.develop(path="/path/to/RayTracing.jl")using Gridap
using RayTracing
model = DiscreteModelFromFile("demo/pincell.json")
n_azim = 8
spacing = 0.08
bcs = reflective_boundaries()
tg = TrackGenerator(model, n_azim, spacing; bcs)
trace!(tg)
segmentize!(tg)
println(tg.n_total_tracks)
println(sum(length(track.segments) for track in tg.tracks_by_uid))![]() |
![]() |
![]() |
|---|---|---|
| Mesh and materials | Cyclic tracks | Cell-local segments |
vacuum_boundaries()
reflective_boundaries()
periodic_boundaries()
BoundaryConditions(
top=Vacuum,
bottom=Reflective,
left=Periodic,
right=Periodic,
)RayTracing does not require Plots.jl for core tracking. Load Plots.jl when you want the recipes:
using Plots
plot(tg.mesh)
plot(tg)
plot(tg.tracks_by_uid)The README assets are reproducible:
julia --project=demo demo/pincell.jlThe mesh source can also be regenerated from gmsh in an environment that has GridapGmsh:
julia demo/pincell-gmsh.jl -nopopupAfter segmentize!(tg), each Track contains ordered Segments with:
segment.pandsegment.q: segment endpoints.segment.ℓ: segment length.segment.element: Gridap cell id.
The full track graph is available through tg.tracks_by_uid, with next_track_fwd and
next_track_bwd links plus direction helpers for cyclic sweeps.
By default, segmentize! uses parallel=:auto, which runs track segmentation across Julia
threads when multiple threads are available:
segmentize!(tg; parallel=:auto)Run Julia with multiple threads, for example julia -t auto, to enable parallel execution.
Use parallel=false to force serial execution or parallel=true to force threaded execution
when threads are available.
Threaded segmentation is intended for one segmentize!(tg) call at a time. It mutates each
track's own segments vector in parallel, then fills tg.volumes serially after all tracks
finish.
Build local docs with:
julia --project=docs docs/make.jlThe benchmark suite uses BenchmarkTools and lives in benchmark/:
julia --project=benchmark benchmark/runbenchmarks.jl --quick
julia --project=benchmark benchmark/runbenchmarks.jl
julia --project=benchmark benchmark/runbenchmarks.jl --output benchmark/results.jsonBenchmark definitions are grouped in benchmark/benchmarks.jl so they can also be loaded by
PkgBenchmark-style workflows.
RayTracing.jl is distributed under the MIT License. See LICENSE.
@software{raytracing_jl,
title = {RayTracing.jl: A Julia package for ray tracing in unstructured meshes},
author = {Vignolo, Ramiro},
year = {2024},
url = {https://github.com/rvignolo/RayTracing.jl}
}



