#include <Snapshot.hpp>
Public Types | |
enum class | CoordinateSystem { CARTESIAN , CYLINDRICAL , SPHERICAL } |
Public Member Functions | |
Snapshot () | |
virtual | ~Snapshot () |
double | age (int m) const |
double | bias (int m) const |
void | close () |
double | currentMass (int m) const |
virtual double | density (int m) const =0 |
virtual double | density (Position bfr) const =0 |
virtual Box | extent () const =0 |
virtual Position | generatePosition () const =0 |
virtual Position | generatePosition (int m) const =0 |
virtual void | getEntities (EntityCollection &entities, Position bfr) const =0 |
virtual void | getEntities (EntityCollection &entities, Position bfr, Direction bfk) const =0 |
bool | hasAge () const |
bool | hasBias () const |
bool | hasCurrentMass () const |
bool | hasInitialMass () const |
bool | hasMagneticField () const |
bool | hasMetallicity () const |
bool | hasParameters () const |
bool | hasTemperature () const |
bool | hasVelocity () const |
bool | hasVelocityDispersion () const |
bool | holdsNumber () const |
void | importBias () |
void | importBox () |
void | importCurrentMass () |
void | importMagneticField () |
void | importMass () |
void | importMassDensity () |
void | importMetallicity () |
void | importNumber () |
void | importNumberDensity () |
void | importParameters (const vector< SnapshotParameter > ¶meters) |
void | importPosition () |
void | importSize () |
void | importTemperature () |
void | importVelocity () |
void | importVelocityDispersion () |
double | initialMass (int m) const |
Vec | magneticField (int m) const |
Vec | magneticField (Position bfr) const |
virtual double | mass () const =0 |
double | metallicity (int m) const |
double | metallicity (Position bfr) const |
virtual int | numEntities () const =0 |
void | open (const SimulationItem *item, string filename, string description) |
void | parameters (int m, Array ¶ms) const |
void | parameters (Position bfr, Array ¶ms) const |
virtual Position | position (int m) const =0 |
virtual void | readAndClose () |
void | setCoordinateSystem (CoordinateSystem coordinateSystem) |
void | setMassDensityPolicy (double multiplier, double maxTemperature, bool useMetallicity) |
void | setNeedGetEntities () |
double | SigmaX () const |
double | SigmaY () const |
double | SigmaZ () const |
double | temperature (int m) const |
double | temperature (Position bfr) const |
void | useColumns (string columns) |
Vec | velocity (int m) const |
Vec | velocity (Position bfr) const |
double | velocityDispersion (int m) const |
double | volume () const |
virtual double | volume (int m) const =0 |
Protected Member Functions | |
int | ageIndex () const |
int | biasIndex () const |
int | boxIndex () const |
void | calculateDensityAndMass (Array &rhov, Array &cumrhov, double &mass) |
int | currentMassIndex () const |
int | densityIndex () const |
bool | hasMassDensityPolicy () const |
TextInFile * | infile () |
int | initialMassIndex () const |
Log * | log () const |
void | logMassStatistics (int numIgnored, double totalOriginalMass, double totalMetallicMass, double totalEffectiveMass) |
int | magneticFieldIndex () const |
int | massIndex () const |
double | maxTemperature () const |
int | metallicityIndex () const |
double | multiplier () const |
bool | needGetEntities () const |
int | numParameters () const |
int | parametersIndex () const |
int | positionIndex () const |
virtual const Array & | properties (int m) const =0 |
Random * | random () const |
void | setContext (const SimulationItem *item) |
int | sizeIndex () const |
int | temperatureIndex () const |
Units * | units () const |
bool | useMetallicity () const |
bool | useTemperatureCutoff () const |
int | velocityDispersionIndex () const |
int | velocityIndex () const |
Private Attributes | |
int | _ageIndex |
int | _biasIndex |
int | _boxIndex |
CoordinateSystem | _coordinateSystem |
int | _currentMassIndex |
int | _densityIndex |
bool | _hasDensityPolicy |
bool | _holdsNumber |
TextInFile * | _infile |
int | _initialMassIndex |
Log * | _log |
int | _magneticFieldIndex |
int | _massIndex |
double | _maxTemperature |
int | _metallicityIndex |
double | _multiplier |
bool | _needGetEntities |
int | _nextIndex |
int | _numParameters |
int | _parametersIndex |
int | _positionIndex |
Random * | _random |
int | _sizeIndex |
int | _temperatureIndex |
Units * | _units |
bool | _useMetallicity |
int | _velocityDispersionIndex |
int | _velocityIndex |
Snapshot is an abstract base class for representing snapshot data that is imported from a column text file and is used to define the properties of primary sources or transfer media. This base class offers facilities to handle the input options, such as determining which columns are to be imported from the text file, and defines a common interface for all snapshot types, for example to obtain the density at a given position. The actual implementation must be provided in a derived class for each snapshot type.
Some snapshot types use smoothed particles and some use spatial cells as their basic constituents. To avoid mentioning both, we use the generic term entity for referring to either particles or cells.
A Snapshot instance must be initialized using the following strict calling sequence; calling any of the getters before the initialization sequence has completed results in undefined behavior:
The functions for extracting information from a snapshot once it is loaded are thread-safe. However, the functions for configuring options and reading the snapshot file are not thread-safe; they must be called from a single thread (for each snapshot object).
|
strong |
This enum has a constant for each of the supported coordinate systems.
Snapshot::Snapshot | ( | ) |
The default constructor initializes the snapshot in an invalid state; see the description of the required calling sequence in the class header.
|
virtual |
The destructor deletes the input file object, if it would still be present. The fact that the destructor is virtual ensures that derived classes can be propertly destructed through a pointer to this base class.
double Snapshot::age | ( | int | m | ) | const |
This function returns the age of the entity with index
|
inlineprotected |
This function returns the column index of the age field, or -1 if this is not being imported, for use by subclasses.
double Snapshot::bias | ( | int | m | ) | const |
This function returns the bias of the entity with index
|
inlineprotected |
This function returns the column index of the bias field, or -1 if this is not being imported, for use by subclasses.
|
inlineprotected |
This function returns the column index of the first box field, or -1 if this is not being imported, for use by subclasses.
This function is provided here for use by subclasses that describe the snapshot through cells (as opposed to particles). It determines the densities and the cumulative mass distribution for all cells and stores the result in the provided array arguments, resizing them and replacing any previous contents. The function also accumulates and stores the total mass, and logs mass statistics by calling logMassStatistics().
The function assumes that the snapshot is fully configured, all properties have been read, and the following functions implemented in the subclass return the proper values: numEntities(), properties(m), volume(m).
void Snapshot::close | ( | ) |
This function closes the file and deletes the corresponding file object.
double Snapshot::currentMass | ( | int | m | ) | const |
This function returns the current mass of the entity with index
|
inlineprotected |
This function returns the column index of the current mass field, or -1 if this is not being imported, for use by subclasses.
|
pure virtual |
This function returns the mass or number density for the entity with index
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
pure virtual |
This function returns the mass or number density represented by the snapshot at a given point
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
inlineprotected |
This function returns the column index of the density field, or -1 if this is not being imported, for use by subclasses.
|
pure virtual |
This function returns the extent of the complete spatial domain of the snapshot as a box lined up with the coordinate axes.
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
pure virtual |
This function returns a random position within the spatial domain of the snapshot, drawn from the mass density distribution represented by the snapshot. If no density policy has been set or no mass/density information is being imported, the behavior is undefined.
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
pure virtual |
This function returns a random position within the entity with index
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
pure virtual |
This function replaces the contents of the specified entity collection by the set of entities that overlap the specified point
For a cell-based snapshot, the function returns the cell containing the given point, if any. The weight is set to 1. For a particle-based snapshot, the function returns all particles with a smoothing kernel that overlaps the given point. The weight of a particle is given by the particle's smoothing kernel value at the given point.
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
pure virtual |
This function replaces the contents of the specified entity collection by the set of entities that overlap the specified path with starting point
For a cell-based snapshot, the weight of a cell is given by the length of the path segment inside the cell. For a particle-based snapshot, the weight of a particle is given by the effective length seen by the path as it crosses the particle's smoothing kernel.
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
inline |
This function returns true if the age is being imported, and false otherwise.
|
inline |
This function returns true if the bias is being imported, and false otherwise.
|
inline |
This function returns true if the current mass is being imported, and false otherwise.
|
inline |
This function returns true if the initial mass is being imported, and false otherwise.
|
inline |
This function returns true if the magnetic field is being imported, and false otherwise.
|
inlineprotected |
This function returns true if the user configured the mass or mass density policy and false otherwise, for use by subclasses.
|
inline |
This function returns true if the metallicity is being imported, and false otherwise.
|
inline |
This function returns true if parameters are being imported (i.e. if the number of imported parameters is nonzero), and false otherwise.
|
inline |
This function returns true if the temperature is being imported, and false otherwise.
|
inline |
This function returns true if the velocity is being imported, and false otherwise.
|
inline |
This function returns true if the velocity dispersion is being imported, and false otherwise.
|
inline |
This function returns true if the snapshot holds number (density) values, and false if it holds mass (density) values (or if no mass or density column is being imported).
void Snapshot::importBias | ( | ) |
This function configures the snapshot to import a bias for each entity in the snapshot.
void Snapshot::importBox | ( | ) |
This function configures the snapshot to import a cuboid lined up with the coordinate axes, defined by six components
void Snapshot::importCurrentMass | ( | ) |
This function configures the snapshot to import the current mass (for use by sources). Not to be confused with the initial mass, which is often requested by single stellar population SED families. The default unit is Msun.
void Snapshot::importMagneticField | ( | ) |
This function configures the snapshot to import a magnetic field vector with three components
void Snapshot::importMass | ( | ) |
This function configures the snapshot to import a mass, i.e. mass density integrated over volume (for use by media). The default unit is Msun. It is allowed to combine the importMassDensity() and importMass() options, supporting special use cases where the volume of the entity cannot be derived otherwise. However, combining the "mass" family functions with the "number" family functions is prohibited and leads to undefined behavior.
void Snapshot::importMassDensity | ( | ) |
This function configures the snapshot to import a mass density per unit of volume (for use by media). The default unit is Msun/pc3. It is allowed to combine the importMassDensity() and importMass() options, supporting special use cases where the volume of the entity cannot be derived otherwise. However, combining the "mass" family functions with the "number" family functions is prohibited and leads to undefined behavior.
void Snapshot::importMetallicity | ( | ) |
This function configures the snapshot to import a (dimensionless) metallicity fraction.
void Snapshot::importNumber | ( | ) |
This function configures the snapshot to import a number, i.e. number density integrated over volume (for use by media). The default unit is 1. It is allowed to combine the importNumberDensity() and importNumber() options, supporting special use cases where the volume of the entity cannot be derived otherwise. However, combining the "mass" family functions with the "number" family functions is prohibited and leads to undefined behavior.
void Snapshot::importNumberDensity | ( | ) |
This function configures the snapshot to import a number density per unit of volume (for use by media). The default unit is 1/cm3. It is allowed to combine the importNumberDensity() and importNumber() options, supporting special use cases where the volume of the entity cannot be derived otherwise. However, combining the "mass" family functions with the "number" family functions is prohibited and leads to undefined behavior.
void Snapshot::importParameters | ( | const vector< SnapshotParameter > & | parameters | ) |
This function configures the snapshot to import a sequence of parameters as described by the specified list of SnapshotParameter metadata objects.
void Snapshot::importPosition | ( | ) |
This function configures the snapshot to import a spatial position with three components
void Snapshot::importSize | ( | ) |
This function configures the snapshot to import a spatial radial size. The default unit is pc.
void Snapshot::importTemperature | ( | ) |
This function configures the snapshot to import a temperature. The default unit is K.
void Snapshot::importVelocity | ( | ) |
This function configures the snapshot to import a velocity with three components
void Snapshot::importVelocityDispersion | ( | ) |
This function configures the snapshot to import a single velocity dispersion value, specifying a random offset to the bulk velocity with a spherically symmetric Gaussian distribution. The default unit is km/s.
|
inlineprotected |
This function returns a pointer to the input file object. It is intended for use in subclasses.
double Snapshot::initialMass | ( | int | m | ) | const |
This function returns the initial mass of the entity with index
|
inlineprotected |
This function returns the column index of the initial mass field, or -1 if this is not being imported, for use by subclasses.
|
inlineprotected |
This function returns a pointer to an appropriate log object. It is intended for use in subclasses.
|
protected |
This function issues log messages with statistics on the imported masses. It is provided here for use by subclasses.
Vec Snapshot::magneticField | ( | int | m | ) | const |
This function returns the magnetic field vector of the entity with index
This function returns the magnetic field vector at the specified point
|
inlineprotected |
This function returns the column index of the first magnetic field field, or -1 if this is not being imported, for use by subclasses.
|
pure virtual |
This function returns the total mass or number represented by the snapshot, which is equivalent to the mass or number density integrated over the complete spatial domain. If no density policy has been set or no mass/density information is being imported, the behavior is undefined.
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
inlineprotected |
This function returns the column index of the mass field, or -1 if this is not being imported, for use by subclasses.
|
inlineprotected |
This function returns the maximum temperature configured by the user for an entity to have mass, or zero if the user did not configure the mass or mass density policy, for use by subclasses.
double Snapshot::metallicity | ( | int | m | ) | const |
This function returns the metallicity of the entity with index
double Snapshot::metallicity | ( | Position | bfr | ) | const |
This function returns the metallicity at the specified point
|
inlineprotected |
This function returns the column index of the metallicity field, or -1 if this is not being imported, for use by subclasses.
|
inlineprotected |
This function returns the mass or mass density multiplier configured by the user, or zero if the user did not configure the mass or mass density policy, for use by subclasses.
|
inlineprotected |
This function returns true if one of the getEntities() functions may be called during the simulation, implying that the snapshot must prebuild the required search data structures. Returns false otherwise. For use by subclasses.
|
pure virtual |
This function returns the number of entities
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
inlineprotected |
This function returns the number of parameters being imported (which may be zero).
void Snapshot::open | ( | const SimulationItem * | item, |
string | filename, | ||
string | description | ||
) |
This function creates an input file object corresponding to the specified file and opens it for reading; if the file can't be opened, a FatalError is thrown. It must be called before invoking any of the configuration functions(). This function takes several arguments: (1) item specifies a simulation item in the hierarchy of the caller (usually the caller itself) used to retrieve context such as an appropriate logger; (2) filename specifies the name of the file, including filename extension but excluding path and simulation prefix; (3) description describes the contents of the file for use in the log message issued after the file is successfully opened.
void Snapshot::parameters | ( | int | m, |
Array & | params | ||
) | const |
This function stores the parameters of the entity with index
This function stores the parameters at the specified point
|
inlineprotected |
This function returns the column index of the first field in the parameter list, or -1 if this is not being imported, for use by subclasses.
|
pure virtual |
This function returns a characteristic position for the entity with index
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
inlineprotected |
This function returns the column index of the first position field, or -1 if this is not being imported, for use by subclasses.
|
protectedpure virtual |
This function returns a reference to an array containing the imported properties (in column order) for the entity with index
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
inlineprotected |
This function returns a pointer to an appropriate random generator. It is intended for use in subclasses.
|
virtual |
This function reads the snapshot data from the input file, honoring the options set through the configuration functions, stores the data for later use, and closes the file.
The implementation in this base class simply calls close(). Subclasses must override the function to actually read the data and then call close().
Reimplemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.
|
protected |
This function retrieves the relevant simulation hierarchy context (such as an appropriate logger) from the specified simulation item (usually the caller itself). It is intended for use in subclasses that support use cases where the open() function is never invoked.
void Snapshot::setCoordinateSystem | ( | CoordinateSystem | coordinateSystem | ) |
This function configures the snapshot to use the specified coordinate system when importing Position, Box, Velocity, and MagneticField. The default coordinate system is Cartesian.
After the input file has been read, the contents of the Position and Box properties are fully under control of the subclass. On the other hand, the Velocity and MagneticField properties are handled by query functions in this base class. Therefore, if a coordinate system other than Cartesian has been configured, the subclass must convert these vector components from the input coordinate system to the Cartesian coordinate system.
void Snapshot::setMassDensityPolicy | ( | double | multiplier, |
double | maxTemperature, | ||
bool | useMetallicity | ||
) |
This function sets the policy for calculating the mass or mass density at a given spatial position in the snapshot. If the policy is not set during configuration, or if neither of the importMass() and importDensity() functions was invoked, attempting to obtain mass or mass density values results in undefined behavior.
If the policy is set during configuration, the argument values determine the heuristic for calculating the mass or density for each entity:
void Snapshot::setNeedGetEntities | ( | ) |
This function notifies the snapshot that one of the getEntities() functions may be called during the simulation, implying that the snapshot must prebuild the required search data structures.
double Snapshot::SigmaX | ( | ) | const |
This function returns the X-axis surface density of the density distribution represented by the snapshot, defined as the integration of the density along the entire X-axis,
This integral is calculated numerically using 10000 samples along the X-axis. If no density policy has been set or no mass/density information is being imported, the behavior is undefined.
double Snapshot::SigmaY | ( | ) | const |
This function returns the Y-axis surface density of the density distribution represented by the snapshot, defined as the integration of the density along the entire Y-axis,
This integral is calculated numerically using 10000 samples along the Y-axis. If no density policy has been set or no mass/density information is being imported, the behavior is undefined.
double Snapshot::SigmaZ | ( | ) | const |
This function returns the Z-axis surface density of the density distribution represented by the snapshot, defined as the integration of the density along the entire Z-axis,
This integral is calculated numerically using 10000 samples along the Z-axis. If no density policy has been set or no mass/density information is being imported, the behavior is undefined.
|
inlineprotected |
This function returns the column index of the size field, or -1 if this is not being imported, for use by subclasses.
double Snapshot::temperature | ( | int | m | ) | const |
This function returns the temperature of the entity with index
double Snapshot::temperature | ( | Position | bfr | ) | const |
This function returns the temperature at the specified point
|
inlineprotected |
This function returns the column index of the temperature field, or -1 if this is not being imported, for use by subclasses.
|
inlineprotected |
This function returns a pointer to an appropriate units object. It is intended for use in subclasses.
void Snapshot::useColumns | ( | string | columns | ) |
This function specifies a mapping (defined by the columns argument) between the "physical" columns in the file being imported (defined by the column information in the file header) and the required "logical" columns (defined by calling the other configuration functions). For information on the syntax and semantics of the columns string contents, refer to the description of the TextInFile::useColumns() function.
This function can be called with a non-empty columns string at most once for each snapshot, and such invocation should occur before the first invocation of any other configuration function. Calling this function with an empty columns string is equivalent to not calling it at all.
|
inlineprotected |
This function returns true if the user configured the mass or mass density policy with a request to use the metallicity, and the metallicity field is being imported. Returns false otherwise. For use by subclasses.
|
inlineprotected |
This function returns true if the user configured the mass or mass density policy with a nonzero maximum temperature and the temperature field is being imported. Returns false otherwise. For use by subclasses.
Vec Snapshot::velocity | ( | int | m | ) | const |
This function returns the velocity of the entity with index
This function returns the velocity at the specified point
double Snapshot::velocityDispersion | ( | int | m | ) | const |
This function returns the velocity dispersion of the entity with index
|
inlineprotected |
This function returns the column index of the velocity dispersion field, or -1 if this is not being imported, for use by subclasses.
|
inlineprotected |
This function returns the column index of the first velocity field, or -1 if this is not being imported, for use by subclasses.
double Snapshot::volume | ( | ) | const |
This function returns the volume of the complete domain of the snapshot, taken to be a box lined up with the coordinate axes.
|
pure virtual |
This function returns the volume of the entity with index
Implemented in AdaptiveMeshSnapshot, CellSnapshot, CylindricalCellSnapshot, ParticleSnapshot, SphericalCellSnapshot, and VoronoiMeshSnapshot.