ExternalGeometry

This class encapsulates an external geometry, usually implemented through the C interface. The geometry is represented as a set of sectors with a specific atomic composition, as defined by a MaterialDefinition, and a density model.

Constructor

class ExternalGeometry(path)

Loads a Monte Carlo geometry from a shared library located at the specified path. For example, on a Linux system,

>>> geometry = goupil.ExternalGeometry("/path/to/libgeometry.so")

Warning

One must specify an absolute or explicit relative path to the geometry library, unless it is known system wide (e.g. located under LD_LIBRARY_PATH on a Linux system).

Attributes

Note

ExternalGeometry attributes are read-only. However, physical properties can be edited using the update_material and update_sector methods described below.

ExternalGeometry.lib: CDLL

This attribute provides a ctypes representation of the geometry library.

Tip

The lib attribute grants access to user-defined functions that are embedded in the geometry library. These functions can be used for various purposes, such as initializing Monte Carlo states. This use case is exemplified by examples/geant4/.

ExternalGeometry.materials: tuple[MaterialDefinition]

This attribute lists all geometry materials as a tuple.

ExternalGeometry.path: str

This attribute contains the path to the geometry library.

ExternalGeometry.sectors: tuple[GeometrySector]

This attribute lists all geometry sectors as a tuple.

Methods

ExternalGeometry.locate(states) numpy.ndarray

Locates the specified states within the geometry. The input states must be a structured numpy.ndarray containing the "position" field, e.g. as returned by the states function. Upon completion, the function returns a numpy.ndarray of sector indices.

ExternalGeometry.material_index(name) int

Returns the index of a material in the list of geometry materials based on its name. For instance

>>> geometry.material_index("CaCO3")
1
ExternalGeometry.sector_index(description) int

Returns the index of a sector in the list of geometry sectors based on its description. For instance

>>> geometry.sector_index("Atmosphere")
0
ExternalGeometry.trace(states, lengths=None, density=None) numpy.ndarray

Casts rays through the geometry, starting from the specified states. The states must be a structured numpy.ndarray containing the "position" and "direction" fields, e.g. as returned by the states function. Upon completion, this function returns a numpy.ndarray containing the path length of rays in each geometry sector. Optionally, you can provide a lengths numpy.ndarray of floats, or a single float, indicating the lengths of rays. If no lengths are specified, rays are traced until the geometry outer boundary.

If the density parameter is set to True, this function will return the column depth (grammage) along rays, in each sector, rather than the path length.

ExternalGeometry.update_material(material, definition)

Replaces the material at the specified int index in the list of geometry materials. Alternatively, the material argument could be a str indicating the name of the material to be replaced. The definition argument should be in line with a MaterialDefinition. For instance

>>> geometry.update_material("CaCO3", "SiO2")
ExternalGeometry.update_sector(sector, material=None, density=None)

Alters the material or density model of a sector, identified by its int index in the list of geometry sectors. Alternatively, the sector argument could be a str describing the sector to be altered. For instance

>>> geometry.update_sector("Atmosphere", density=1.205E-03)