Skip to content

rvignolo/RayTracing.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RayTracing.jl

Build Status

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.

Pin-cell material geometry Cyclic ray tracing over the pin-cell mesh

Features

  • 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.

Installation

import Pkg
Pkg.add("RayTracing")

For local development:

import Pkg
Pkg.develop(path="/path/to/RayTracing.jl")

Quick Start

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))

Workflow

Mesh and materials Cyclic tracks Cell-local segments

Boundary Conditions

vacuum_boundaries()
reflective_boundaries()
periodic_boundaries()

BoundaryConditions(
    top=Vacuum,
    bottom=Reflective,
    left=Periodic,
    right=Periodic,
)

Plotting

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.jl

The mesh source can also be regenerated from gmsh in an environment that has GridapGmsh:

julia demo/pincell-gmsh.jl -nopopup

Transport Integration

After segmentize!(tg), each Track contains ordered Segments with:

  • segment.p and segment.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.

Documentation

Build local docs with:

julia --project=docs docs/make.jl

Benchmarks

The 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.json

Benchmark definitions are grouped in benchmark/benchmarks.jl so they can also be loaded by PkgBenchmark-style workflows.

License

RayTracing.jl is distributed under the MIT License. See LICENSE.

Citation

@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}
}

About

High performance cyclic ray tracing algorithm for neutron transport in Julia.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages