The SKIRT project
advanced radiative transfer for astrophysics
Public Types | Public Member Functions | Private Attributes | List of all members
EntityCollection Class Reference

#include <EntityCollection.hpp>

Public Types

using Map = std::unordered_map< int, double >
 

Public Member Functions

 EntityCollection ()
 
double accumulate (std::function< double(int m)> value)
 
void add (int m, double w)
 
void addSingle (int m)
 
std::pair< double, double > average (std::function< double(int m)> value, std::function< double(int m)> weight)
 
std::pair< Vec, double > average (std::function< Vec(int m)> value, std::function< double(int m)> weight)
 
Map::const_iterator begin () const
 
void clear ()
 
Map::const_iterator end () const
 

Private Attributes

Map _entities
 

Detailed Description

EntityCollection is a helper class used with the Snapshot class and its subclasses. As indicated there, some snapshot types use smoothed particles and some use spatial cells as their basic constituents. The generic term entity refers to either particles or cells. Assuming a snapshot with \(N_\mathrm{ent}\) entities, any given entity is identfied by its zero-based index \(0\le m \le N_\mathrm{ent}-1\).

An EntityCollection object contains an unordered collection of unique entity indices with corresponding weights. This can be used to represent the set of entities that overlap a given position or path in space with their corresponding relative weights. The relative weights would, depending on the circumstances, take into account the smoothing kernel of an imported particle and/or the length of the path segment overlapping the particle or cell.

An EntityCollection instance can be reused for storing a new collection without forcing memory reallocations.

Member Typedef Documentation

◆ Map

using EntityCollection::Map = std::unordered_map<int, double>

Type declaration for the unordered map underlying the entity collection.

Constructor & Destructor Documentation

◆ EntityCollection()

EntityCollection::EntityCollection ( )

The constructor creates an empty collection.

Member Function Documentation

◆ accumulate()

double EntityCollection::accumulate ( std::function< double(int m)>  value)

This function returns the accumulated weighted value of a given scalar field \(f(m)\) over all entities in the collection,

\[\sum_m f(m)\,w_m.\]

The argument specifies the scalar field \(f(m)\); the call-back function should return the field value corresponding to a given entity index.

◆ add()

void EntityCollection::add ( int  m,
double  w 
)

This function adds an entity with index \(m\) and weight \(w\) to the collection. If \(m<0\), \(w\le 0\), \(w\) is NaN or infinity, or an entity with the same index is already in the collection, the function does nothing.

◆ addSingle()

void EntityCollection::addSingle ( int  m)

This function removes any pre-existing entities from the collection and then adds a single entity with index \(m\) and weight 1 to the collection. If \(m<0\), the function clears the collection but does not add an entity.

◆ average() [1/2]

std::pair< double, double > EntityCollection::average ( std::function< double(int m)>  value,
std::function< double(int m)>  weight 
)

This function returns the nominator and denominator for the weighted average of a given scalar field \(f(m)\) with given external weight \(\omega(m)\) over all entities in the collection. The arguments respectively specify the scalar field \(f(m)\) and the corresponding external weight \(\omega(m)\). These functions should return the field value respectively the external weight corresponding to a given entity index.

The function combines the external weights with the weights stored internally for each entity in the collection. Specifically, it calculates \(\sum_m f(m)\,\omega(m)\,w_m\) and \(\sum_m \omega(m)\,w_m\).

◆ average() [2/2]

std::pair< Vec, double > EntityCollection::average ( std::function< Vec(int m)>  value,
std::function< double(int m)>  weight 
)

This function returns the nominator and denominator for the weighted average of a given vector field \({\bf{f}}(m)\) with given external weight \(\omega(m)\) over all entities in the collection. The arguments respectively specify the vector field \({\bf{f}}(m)\) and the corresponding external weight \(\omega(m)\). These functions should return the field value respectively the external weight corresponding to a given entity index.

The function combines the external weights with the weights stored internally for each entity in the collection. Specifically, it calculates \(\sum_m {\bf{f}}(m)\,\omega(m)\,w_m\) and \(\sum_m \omega(m)\,w_m\).

◆ begin()

Map::const_iterator EntityCollection::begin ( ) const
inline

This function returns read-only iterator to the first entity in the collection. Each entity consists of a key/value pair, where the key is the index \(m\) of the entity being represented and the value is the corresponding weight \(w\). The entity index is guaranteed to be nonnegative.

◆ clear()

void EntityCollection::clear ( )

This function removes any entities from the collection, resulting in an empty collection.

◆ end()

Map::const_iterator EntityCollection::end ( ) const
inline

This function returns read-only iterator just beyond the last entity in the collection.


The documentation for this class was generated from the following file: