|
HighLevelCodeOverview
High-level overview of the structure of the Sunrise code
Code descriptionHere, I'll try to provide some high-level guidance when reading the Sunrise source code. As always, the ultimate documentation is the code itself, so for this to make sense, you should probably open up the Doxygen class hierarchy in another window and keep them side by side. This description will mostly pertain to the mcrx code. The code in sfrhist is neither that interesting nor as complicated as the radiation transfer code. Basic code structureThe basic idea behind the Sunrise code was to subdivide the functionality needed for the radiation transfer calculation into distinct parts that are as independent as possible and that can be substituted if different behavior is needed. Many of these classes are templated on any of three template parameters, the "chromatic policy" which determines whether it should have mono- or polychromatic functionality, the "rng_policy" which determines how the random numbers are drawn (whether there is a global or thread-local RNG), and the "sampling policy" which determines how sampling of a distribution of discrete items should take place (using either rejection sampling or the cumulative distribution). In practice, it's the polychromatic policy, the thread-local RNGs, and sampling from the cumulative distribution that's used. The fundamental components are:
The grid supplies a few crucial methods used in the ray tracing, so should (in principle) be easy to substitute with a different class, for example for spherical coordinates or unstructured meshes, though this has so far never been done. The operations the grid/cell classes need to provide are essentially finding intersections between rays and cell boundaries and calculating the column density along a given ray. Behind the scenes, the grid is implemented with the classes grid_base which provides the basic functionality of a Cartesian grid, dynamic_grid which is a dynamically allocated Cartesian grid of arbitrary dimensions, and octogrid which is a 2 cubed grid. The class grid_cell represents a cell in a grid, and this cell can contain either data (an arbitrary class) or a subgrid. The way the grid is set up, the base grid is a dynamic_grid, and all subgrids are cells that contain an octogrid.
|