Skip to content

Source Code

Jon Drobny edited this page Oct 12, 2020 · 10 revisions

Code Structure

RustBCA is structured, wherever possible, to enhance readability, especially compared to legacy codes that precede it. It is broken up into several modules: main.rs, particle.rs, material.rs, mesh.rs, bca.rs, interactions.rs, and tests.rs. Each of these modules is relatively self contained. Functions that can fail use the anyhow crate to return Results, so that error handling is precise and explanatory.

Modules

Main

main.rs includes the core code loop, I/O, error handling on input (e.g., making sure that incompatible interaction potentials and root-finders are not used together), constants and imports, enums for controlling various code options, and the data structures Vector and Vector4.

Particle

particle.rs includes the Particle struct, used for tracking ions and atoms in the code. Functions for rotation, advancement in space, and refraction of particles at material surfaces are also included.

Material

material.rs contains the Material struct and associated functions. Material includes methods for determining the electronic stopping power, pulling information from the mesh, and determining whether points are inside or outside of the material.

Mesh

mesh.rs contains the Mesh2D struct and associated data structures and functions for handling inhomogeneous composition of materials.

BCA

bca.rs contains the main BCA algorithms that involve both particles and materials, including distance of closest approach rootfinding calculation, and scattering angle determination.

Interactions

interactions.rs contains the interatomic potentials used in the code, the distance of closest approach functions, polynomial solver helper functions, scaling functions, and various screening lengths associated with the interatomic potentials in the code.

Tests

tests.rs contains all testing routines, including both unit tests and integration tests. Writing tests for rustbca is a work in progress. Currently, the code checks that momentum is conserved during an entire BCA step, that the numerical quadratures agree with one another, that the distance of closest approach algorithms agree with one another, and that the mesh correctly handles distances and inside/outside checks on the mesh.