Celeritas 0.7.0-dev.79+develop.b3dc2e108
Loading...
Searching...
No Matches
Public Member Functions | List of all members
celeritas::ItemMap< T1, T2 > Class Template Reference

Access data in a Range<T2> with an index of type T1. More...

#include <Collection.hh>

Public Types

Type aliases
using key_type = T1
 
using mapped_type = T2
 

Public Member Functions

CELER_FUNCTION ItemMap (Range< T2 > range)
 Construct implicitly from an existing Range<T2>
 
CELER_FUNCTION ItemMap (T2 start, T2 stop)
 Construct like a range.
 
CELER_FORCEINLINE_FUNCTION T2 operator[] (T1 id) const
 Access Range via OpaqueId of type T1.
 
CELER_FORCEINLINE_FUNCTION bool empty () const
 Whether the underlying Range<T2> is empty.
 
CELER_FORCEINLINE_FUNCTION size_type size () const
 Size of the underlying Range<T2>
 

Detailed Description

template<class T1, class T2>
class celeritas::ItemMap< T1, T2 >

Access data in a Range<T2> with an index of type T1.

Here, T1 and T2 are expected to be OpaqueId types. This is simply a type-safe "offset" with range checking.

Example:

using ElComponentId = OpaqueId<struct ElComp_>;
// POD struct (record) describing a material
{
using DoubleId = ItemId<double>; // same as OpaqueId
};
template<Ownership W, MemSpace M>
struct MatParamsData
{
Collection<double, W, M> doubles; // Backend storage
// ...
};
Manage generic array-like data ownership and transfer from host to device.
Definition Collection.hh:288
Access data in a Range<T2> with an index of type T1.
Definition Collection.hh:182
Type-safe index for accessing an array or collection of data.
Definition OpaqueId.hh:87
Fundamental (static) properties of a material.
Definition mat/MaterialData.hh:104

Here, components semantically refers to a contiguous range of real values in the doubles collection, where ElComponentId{0} is the first value in that range. Dereferencing the value requires using the map alongside the backend storage:

double get_value(MatParamsData const& params, MatId m, ElComponentId ec)
{
MaterialRecord const& mat = params.materials[m];
ItemId<double> dbl_id = mat.components[ec];
return params.doubles[dbl_id];
}

Note that this access requires only two indirections, as ItemMap is merely performing integer arithmetic.


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