Skip to content

Code Structure

Chris White edited this page Mar 30, 2022 · 10 revisions

For anyone seeking to modify Blacklight, or to fully understand what it is doing, here is an overview of the structure of the code.

There are 5 primary classes (actually structs) that do all the work: InputReader, SimulationReader, GeodesicIntegrator, RadiationIntegrator, and OutputWriter. Each class will only have one instantiation in a given execution of the code, and each has only one or two functions intended to be called externally. The constructors and top-level functions are called in sequence by main:

main(...)
├→InputReader::InputReader(...)
├→InputReader::Read()
├→GeodesicIntegrator::GeodesicIntegrator(...)
├→GeodesicIntegrator::Integrate()
├→SimulationReader::SimulationReader(...)
├→RadiationIntegrator::RadiationIntegrator(...)
├→OutputWriter::OutputWriter(...)
│   // Go through runs
├──→SimulationReader::Read(...)
│     // Iterate with adaptive refinement
├────→RadiationIntegrator::Integrate(...)
├────→GeodesicIntegrator::AddGeodesics(...)
└──→OutputWriter::Write(...)

InputReader processes the input file given as the only argument to the executable.

SimulationReader, only really used when dealing with simulation data (model_type = simulation in the input file), reads the necessary Athena++ or iharm3D data from an HDF5 file.

GeodesicIntegrator defines the camera and calculates the paths rays will take to the camera.

RadiationIntegrator does the bulk of the computation, including populating sample points along the rays with simulation or formula values, calculating the coefficients of the radiative transfer equation, integrating the radiative transfer equation, calculating other images for output, and evaluating adaptive mesh refinement.

OutputWriter simply writes the results of the computation to a file, whether as a NumPy .npz or .npy file, or as a raw binary dump.

Each of the above classes is almost entirely self-contained. One class might read a large array belonging to another, in order to prevent unnecessary copying. The only other classes in the code are the simple exception and warning classes BlacklightException and BlacklightWarning, as well as a multidimensional Array class similar to but simpler than Athena++'s AthenaArray. These, together with some miscellaneous utility functions, are located in src/utils/.

Clone this wiki locally