criptic v1
Cosmic Ray Interstellar Propagation Tool using Itô Calculus
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
criptic::CRTree Class Reference

A class to manage CR packets and sources. More...

#include <CRTree.H>

Public Member Functions

 CRTree (const ParmParser &pp, const Geometry &geom_, const gas::Gas &gasBG_, const propagation::Propagation &prop_, const Losses &loss_, RngThread &rng_)
 Construct an empty CRTree.
 
void addPacketsAndSources (const std::vector< RealVec > &x_, const std::vector< CRPacket > &pd_, const std::vector< RealVec > &xSrc_, const std::vector< CRSource > &src_)
 Add CR packets and sources to the tree.
 
void addPackets (const std::vector< RealVec > &x_, const std::vector< CRPacket > &pd_)
 Add CR packets to the tree.
 
void addSources (const std::vector< RealVec > &xSrc_, const std::vector< CRSource > &src_)
 Add CR sources to the tree.
 
void deletePacketsAndSources (std::vector< IdxType > &pIdx, std::vector< IdxType > &sIdx, const Real t)
 Delete CR packets and sources from the tree.
 
void deletePackets (std::vector< IdxType > &pIdx, const Real t)
 Delete CR packets.
 
void deleteSources (std::vector< IdxType > &sIdx)
 Delete CR packets.
 
IdxType nPacket () const
 Number of packets across all MPI ranks.
 
IdxType nPacketLoc () const
 Number of packets on this MPI rank.
 
IdxType nDeletedPacket () const
 Number of deleted packets across all MPI ranks.
 
IdxType nSource () const
 Number of sources across all MPI ranks.
 
IdxType nSourceLoc () const
 Number of sources on this MPI rank.
 
IdxType getUniqueID () const
 Current value of the uniqueID counter.
 
void setUniqueID (const IdxType uniqueID_)
 Set value of the uniqueID counter.
 
std::vector< RealVec > & getPacketPos ()
 Retrieve packet position data.
 
const std::vector< RealVec > & getPacketPos () const
 Retrieve position of a packet.
 
RealVecgetPacketPos (const IdxType i)
 Retrieve position of a packet.
 
const RealVecgetPacketPos (const IdxType i) const
 Retrieve position of a packet as const.
 
std::vector< CRPacket > & getPacketData ()
 Retrieve packet data.
 
const std::vector< CRPacket > & getPacketData () const
 Retrieve packet data as const.
 
CRPacketgetPacketData (const IdxType i)
 Retrieve data on a packet.
 
const CRPacketgetPacketData (const IdxType i) const
 Retrieve data on a packet as const.
 
std::vector< RealVec > & getDeletedPacketPos ()
 Retrieve deleted packet position data.
 
const std::vector< RealVec > & getDeletedPacketPos () const
 Retrieve position of a deleted packet.
 
RealVecgetDeletedPacketPos (const IdxType i)
 Retrieve position of a deleted packet.
 
const RealVecgetDeletedPacketPos (const IdxType i) const
 Retrieve position of a deleted packet as const.
 
std::vector< CRPacket > & getDeletedPacketData ()
 Retrieve deleted packet data.
 
const std::vector< CRPacket > & getDeletedPacketData () const
 Retrieve deleted packet data as const.
 
CRPacketgetDeletedPacketData (const IdxType i)
 Retrieve data on a deleted packet.
 
const CRPacketgetDeletedPacketData (const IdxType i) const
 Retrieve data on a deleted packet as const.
 
std::vector< Real > & getDeletedPacketTime ()
 Retrieve deleted packet deletion times.
 
const std::vector< Real > & getDeletedPacketTime () const
 Retrieve deleted packet deletion times as const.
 
RealgetDeletedPacketTime (const IdxType i)
 Retrieve deletion time of a single deleted packet.
 
const RealgetDeletedPacketTime (const IdxType i) const
 Retrieve deletion time of a single deleted packet as const.
 
std::vector< RealVec > & getSourcePos ()
 Retrieve source position data.
 
const std::vector< RealVec > & getSourcePos () const
 Retrieve source position data as const.
 
RealVecgetSourcePos (const IdxType i)
 Retrieve position of a source.
 
const RealVecgetSourcePos (const IdxType i) const
 Retrieve position of a source as const.
 
std::vector< CRSource > & getSourceData ()
 Retrieve source data.
 
const std::vector< CRSource > & getSourceData () const
 Retrieve source data as const.
 
CRSourcegetSourceData (const IdxType i)
 Retrieve data on a source.
 
const CRSourcegetSourceData (const IdxType i) const
 Retrieve data on a source as const.
 
const std::vector< CRSource > & getSourceBufData () const
 Retrieve source buffer data as const.
 
RealgetPacketScale (const IdxType i)
 Retrieve scale length for specified packet.
 
std::vector< FieldQty > & getPacketQty ()
 Retrieve field quantities for all packets.
 
const std::vector< FieldQty > & getPacketQty () const
 Retrieve field quantities for all packets as const.
 
FieldQtygetPacketQty (const IdxType i)
 Retrieve field quantities for a specific packet.
 
const FieldQtygetPacketQty (const IdxType i) const
 Retrieve field quantities for a specific packet as const.
 
std::vector< FieldQtyGrad > & getPacketQtyGrad ()
 Retrieve field quantity gradients for all packets.
 
const std::vector< FieldQtyGrad > & getPacketQtyGrad () const
 Retrieve field quantity gradients for all packets as const.
 
FieldQtyGradgetPacketQtyGrad (const IdxType i)
 Retrieve field quantity gradients for a specific packet.
 
const FieldQtyGradgetPacketQtyGrad (const IdxType i) const
 Retrieve field quantity gradients for a specific packet as const.
 
const Losses & getLoss () const
 Return reference to the loss calculator.
 
void getLossRates (const Real t, std::vector< Real > &dpdt, std::vector< Real > &lossRate) const
 Total continuous and catastropic loss rates for all packets.
 
void getLossRates (const IdxType i, const Real t, Real &dpdt, Real &lossRate) const
 Total continuous and catastropic loss rates for specified packet.
 
void getLossRatesMech (const Real t, std::vector< Losses::MechArr< Real > > &dpdt, std::vector< Losses::MechArr< Real > > &lossRate) const
 Compute mechanism-by-mechanism loss rates for all packets.
 
void getLossRatesMech (const IdxType i, const Real t, Losses::MechArr< Real > &dpdt, Losses::MechArr< Real > &lossRate) const
 Compute mechanism-by-mechanism loss rates for specified packet.
 
std::vector< RealphotLum (const Real t, const std::vector< Real > &en) const
 Compute photon emission from all packets by all mechanisms.
 
std::vector< RealphotLumSummary (const Real t, const std::vector< Real > &en, const int rank=0) const
 Compute total photon emission, summing by type and mechanism.
 
std::vector< RealionRate (const Real t) const
 Compute ionization rate from all packets.
 
std::vector< RealcomputePdot (const Real t) const
 Compute non-loss dp/dt terms for all packets.
 
std::string getRngState () const
 Get serialized RNG state.
 
void setRngState (std::string &buf) const
 Set RNG state from serialized buffer.
 
void clearDeletedPackets ()
 Remove deleted packets.
 
void rebuild ()
 Rebuild the tree.
 
void fillFieldQty ()
 Compute the field quantities for packets in the tree.
 
void injectPackets (const Real tStart, const Real tStop)
 Inject new CR packets from sources.
 
Real advancePackets (const Real tStart, const Real tStop)
 Advance all packets through one time step.
 

Static Public Attributes

static constexpr int leafSize = TREE_LEAF_SIZE
 
static constexpr int nRigidBin = TREE_RIGIDITY_BINS
 

Private Member Functions

void setupDomain ()
 Find the global bounding box and total number of packets.
 
void buildGlobalTree ()
 Build the global KD tree.
 
void buildLocalTree ()
 Build the local KD tree.
 
void computeSplit (GlobalNode &nd)
 Figure out how to split a global tree node.
 
template<class U >
IdxType partitionGlobalNode (const GlobalNode &nd, const IdxType start, const IdxType count, std::vector< RealVec > &x_, std::vector< U > &dat)
 Partition a node global node using a pre-computed split.
 
void partitionNode (LocalNode &nd)
 Partition a local node at the median point.
 
void sumTree ()
 Sum weights and bounding boxes in local tree.
 
void exchange ()
 Exchange packets and sources across MPI ranks.
 
void fillFieldQty (std::vector< IdxType > &start, std::vector< IdxType > &count, std::vector< IdxType > &leafList_)
 Compute the field quantities for packets in the tree.
 
void fillFieldQtyRange (const IdxType start, const IdxType count, const RealVec x_[], const Real R[], const RealTensor2 &h2Inv, const RealTensor2 &h2InvGrad, const Real &hScale, FieldQty q[], FieldQtyGrad qGrad[], const int nrank=0, const FieldQty *qOwner=nullptr)
 Fill the field quantities for a set of packets.
 
void addNodeToField (const IdxType &nodeIdx, const IdxType &start, const IdxType &count, const RealVec x_[], const Real R[], const RealTensor2 &h2Inv, const RealTensor2 &h2InvGrad, FieldQty q[], FieldQty qErr[], FieldQtyGrad qGrad[], FieldQtyGrad qGradErr[])
 Add contribution of node to field quantities of packets.
 
void nodeWgtLimits (const RealVec &x_, const RealBox &bnd, const RealTensor2 &h2Inv, const RealTensor2 &h2InvGrad, Real &wMin, Real &wMax, RealVec &wGradMin, RealVec &wGradMax) const
 Compute min and max weight functions over a node.
 

Private Attributes

const Geometrygeom
 
const gas::GasgasBG
 
const propagation::Propagationprop
 
const Losses & loss
 
RngThreadrng
 
CRTreeCommunicator comm
 
IdxType uniqueID
 
int verbosity
 
int globTreeExtLev
 
int partitionSamples
 
int nNgbEff
 
int equalSampling
 
Real kdeTol
 
Real hDither
 
Real qSamp
 
Real packetRate
 
Real cMinWgt
 
Real cStep
 
Real errTol
 
Real wFracMin
 
Real pMin
 
Real TMin
 
Real packetDtMin
 
std::vector< RealsamplingRatio
 
bool needFQ
 
bool needFQG
 
IdxType totPacket
 
std::vector< RealVecx
 
std::vector< CRPacketpd
 
std::vector< FieldQtyqty
 
std::vector< Realh
 
std::vector< FieldQtyGradqtyGrad
 
std::vector< RealVecxBuf
 
std::vector< CRPacketpdBuf
 
std::vector< FieldQtyqtyBuf
 
std::vector< FieldQtyGradqtyGradBuf
 
std::vector< RealhBuf
 
IdxType totDeletedPacket
 
std::vector< RealVecxDel
 
std::vector< CRPacketpdDel
 
std::vector< RealtDel
 
IdxType totSrc
 
Real totSrcWgt
 
std::vector< RealtotSrcWgtSpec
 
std::vector< RealVecxSrc
 
std::vector< CRSourcesrc
 
std::vector< RealVecxSrcBuf
 
std::vector< CRSourcesrcBuf
 
std::vector< IdxTypesrcLeaf
 
RealVec domLo
 
RealVec domHi
 
Real logR0
 
Real logR1
 
Real dlogR
 
IdxType globTreeMaxLev
 
IdxType globTreeNLeaf
 
IdxType globTreeLeafPtr
 
IdxType globTreeMyLeafPtr
 
IdxType globTreeNOwned
 
std::vector< IdxTypelocTreeOffsets
 
std::vector< IdxTypelocTreeMaxLev
 
std::vector< IdxTypelocTreeLeafStart
 
std::vector< IdxTypelocTreeNLeaf
 
std::vector< IdxTypeleafList
 
std::vector< GlobalNodeglobNodes
 
std::vector< LocalNodenodes
 
std::vector< RealTensor2h2InvLeaf
 
std::vector< RealTensor2h2InvGradLeaf
 
std::vector< RealhScaleLeaf
 

Friends

class CRTreeCommunicator
 

Detailed Description

A class to manage CR packets and sources.

This is the primary simulation class in criptic. The CRTree stores the packets and sources, and is responsible for distributing them across MPI ranks, building the tree to allow fast kernel density estimation, and farming out the work of updating CR packet positions and properties to the update routines.

Constructor & Destructor Documentation

◆ CRTree()

CRTree::CRTree ( const ParmParser pp,
const Geometry geom_,
const gas::Gas gasBG_,
const propagation::Propagation prop_,
const Losses &  loss_,
RngThread rng_ 
)

Construct an empty CRTree.

Parameters
ppcriptic::ParmParser object containg input deck
geom_criptic::Geometry object containing problem geometry
gasBG_criptic::gas::Gas object describing background gas
prop_criptic::propagation::Propagation object describing CR propagation
loss_criptic::Losses object describing loss mechanisms
rng_criptic::RngThread random number generator object

Member Function Documentation

◆ addNodeToField()

void CRTree::addNodeToField ( const IdxType nodeIdx,
const IdxType start,
const IdxType count,
const RealVec  x_[],
const Real  R[],
const RealTensor2 h2Inv,
const RealTensor2 h2InvGrad,
FieldQty  q[],
FieldQty  qErr[],
FieldQtyGrad  qGrad[],
FieldQtyGrad  qGradErr[] 
)
private

Add contribution of node to field quantities of packets.

Parameters
nodeIdxIndex of node to add
startStarting index of packets to fill, or maxIdx if external
countNumber of packets to fill
x_Positions of packets to fill
RRigidities of packets to fill
h2InvInverse of bandwidth squared matrix
h2InvGradSame as h2Inv, but for computation of gradients
qContributions of nodes to field quantities
qErrUncertainties in contributions of nodes to field quantities
qGradContribution of nodes to field quantity gradients
qGradErrUncertainties in contribution of nodes to gradients

The arguments h2InvGrad, qGrad, and errGrad are used only if the propagation model needs gradients of field quantities; they are ignored otherwise. The action of this function depends on whether the node on which it is called is a leaf or not. If it is a leaf, then the contributions of the packets in that leaf are added to q and qGrad, and qErr and qGradErr are not altered (since contributions from leaves have no errors). If the node is not a leaf, then q, qGrad, qErr, and qGradErr are set equal to estimates of the contribution of the node, and uncertainties on that estimate, resectively.

◆ addPackets()

void CRTree::addPackets ( const std::vector< RealVec > &  x_,
const std::vector< CRPacket > &  pd_ 
)

Add CR packets to the tree.

Parameters
x_Positions of packets to add
pd_Packet data for packets to add

◆ addPacketsAndSources()

void CRTree::addPacketsAndSources ( const std::vector< RealVec > &  x_,
const std::vector< CRPacket > &  pd_,
const std::vector< RealVec > &  xSrc_,
const std::vector< CRSource > &  src_ 
)

Add CR packets and sources to the tree.

Parameters
x_Positions of packets to add
pd_Packet data for packets to add
xSrc_Positions of sources to add
src_Source data to add

◆ addSources()

void CRTree::addSources ( const std::vector< RealVec > &  xSrc_,
const std::vector< CRSource > &  src_ 
)

Add CR sources to the tree.

Parameters
xSrc_Positions of sources to add
src_Source data for sources to add

◆ advancePackets()

Real CRTree::advancePackets ( const Real  tStart,
const Real  tStop 
)

Advance all packets through one time step.

Parameters
tStartStart of time step
tStopEnd of time step
Returns
Size of next time step

◆ buildGlobalTree()

void CRTree::buildGlobalTree ( )
private

Build the global KD tree.

This method builds the global KD tree, which organizes the data across all MPI ranks. Note that, even if MPI is not enabled, we still build a global tree, though it will generally consist of only a single node.

◆ buildLocalTree()

void CRTree::buildLocalTree ( )
private

Build the local KD tree.

This method builds the local KD tree, which organizes the data across on a single MPI rank.

◆ clearDeletedPackets()

void criptic::CRTree::clearDeletedPackets ( )
inline

Remove deleted packets.

Calling this routine flushes the deleted packet buffer. This is intended to be used after writing those data to a checkpoint.

◆ computePdot()

vector< Real > CRTree::computePdot ( const Real  t) const

Compute non-loss dp/dt terms for all packets.

Parameters
tCurrent time
Returns
All non-loss terms contributing to dp/dt

This routine computes all the non-loss terms that contribute to dp/dt for each packet. The three terms included are, in order, dK_pp/dp + 2 K_pp/p, -(p/3) dv_i/dx_i, and -p/3 (dw/dx_i t_i + w dt_i/dx_i), which physically represent changes in momentum due to momentum diffusion (second-order Fermi acceleration), adiabatic expansion or compression, and streaming. Data are packed into a single vector, with all three terms for packet 0 coming first, then all 3 terms for packet 1, and so forth. Loss rates are in code units.

◆ computeSplit()

void CRTree::computeSplit ( GlobalNode nd)
private

Figure out how to split a global tree node.

Parameters
ndThe node whose split is to be computed

This routine computes the split dimension and value for a node in the global tree. It has the effect of setting the splitDim and splitVal fields for the node. It does not partition the packets or initialize the child nodes.

◆ deletePackets()

void criptic::CRTree::deletePackets ( std::vector< IdxType > &  pIdx,
const Real  t 
)
inline

Delete CR packets.

Parameters
pIdxIndices of packets to delete
tCurrent time

This is a thin wrapper around deletePacketsAndSources, with the list of source indices left empty.

◆ deletePacketsAndSources()

void CRTree::deletePacketsAndSources ( std::vector< IdxType > &  pIdx,
std::vector< IdxType > &  sIdx,
const Real  t 
)

Delete CR packets and sources from the tree.

Parameters
pIdxIndices of packets to delete
sIdxIndices of sources to delete
tCurrent time

This function is provided for users to manually add or remove packets and sources as part of userWork or similar functions. pIdx and sIdx give the indices (not IDs) of the packets and sources to be deleted, and must be non-repeating; on return they will be sorted. Packets that are marked for deletion will be moved to the deleted packets list, but sources that are deleted will not be recorded automatically; it is up to users to log these deletions if they wish to do so.

◆ deleteSources()

void criptic::CRTree::deleteSources ( std::vector< IdxType > &  sIdx)
inline

Delete CR packets.

Parameters
sIdxIndices of sources to delete

This is a thin wrapper around deletePacketsAndSources, with the list of packet indices left empty and the time not used.

◆ exchange()

void CRTree::exchange ( )
private

Exchange packets and sources across MPI ranks.

This method is called after buildGlobalTree; its purpose is to exchange packets and sources between ranks, so that each MPI rank owns the packets and sources on its leaves and no others

◆ fillFieldQty() [1/2]

void criptic::CRTree::fillFieldQty ( )
inline

Compute the field quantities for packets in the tree.

This routine does kernel density estimation to compute the field quantities (and gradients if field quantities) for packets in the tree. Only things needed by the propagation model are computed, so if the propagation model does not require field quantities or their gradients, this function has no effect. Note that the public version is a thin wrapper around the private version; the public version defaults to operating on packets in the main tree, while the private version can operate on the main tree or the buffer, depending on the arguments supplied.

◆ fillFieldQty() [2/2]

void CRTree::fillFieldQty ( std::vector< IdxType > &  start,
std::vector< IdxType > &  count,
std::vector< IdxType > &  leafList_ 
)
private

Compute the field quantities for packets in the tree.

Parameters
startStarting indices of packets in each leaf to fill
countNumber of packets in each leaf
leafList_Indices of leaves to which packets belong

This routine does kernel density estimation to compute the field quantities (and gradients if field quantities) for packets in the tree. Only things needed by the propagation model are computed, so if the propagation model does not require field quantities or their gradients, this function has no effect. This differs from the public version in that it accepts explicit arguments to specify packet and leaf indices on which to operate; this capability allows it to be used to fill field quantities in the buffer of packets waiting to be added to the tree as well as in the main tree.

◆ fillFieldQtyRange()

void CRTree::fillFieldQtyRange ( const IdxType  start,
const IdxType  count,
const RealVec  x_[],
const Real  R[],
const RealTensor2 h2Inv,
const RealTensor2 h2InvGrad,
const Real hScale,
FieldQty  q[],
FieldQtyGrad  qGrad[],
const int  nrank = 0,
const FieldQty qOwner = nullptr 
)
private

Fill the field quantities for a set of packets.

Parameters
startStarting index of packets to fill
countNumber of packets to fill
x_Positions of packets to fill
RRigidities of packets to fill
h2InvInverse squared bandwidth matrix
h2InvGradInverse squared bandwidth matrix for gradients
hScaleLength scale for gradient errors
qArray of field quantities to fill
qGradArray of field quantity gradients to fill
nrankNumber of MPI ranks contributing to this packet
qOwnerEstimate q from the rank that owns each packet

If field quantity gradients are not needed, as indicated by needFQG being false, then qGrad, h2InvGrad, and hScale are not used. This method can operate in two modes: if start is equal to nullPacket, the packets passed to it are assumed to reside on another MPI rank, and we only compute the contribution to field quantities from this rank. If start is not equal to nullPacket, the packets passed are assumed to reside on this MPI rank, and the routine attempts to compute the total contribution across all ranks. If this requires data not available because it is held on another rank, the routine launches the required communication requests to gather the data, allowing completion of the estimate later.

◆ getDeletedPacketData() [1/4]

std::vector< CRPacket > & criptic::CRTree::getDeletedPacketData ( )
inline

Retrieve deleted packet data.

Returns
Reference to deleted packet data

◆ getDeletedPacketData() [2/4]

const std::vector< CRPacket > & criptic::CRTree::getDeletedPacketData ( ) const
inline

Retrieve deleted packet data as const.

Returns
Const reference to deleted packet data

◆ getDeletedPacketData() [3/4]

CRPacket & criptic::CRTree::getDeletedPacketData ( const IdxType  i)
inline

Retrieve data on a deleted packet.

Parameters
iIndex of deleted packet to return
Returns
Data for specified deleted packet

◆ getDeletedPacketData() [4/4]

const CRPacket & criptic::CRTree::getDeletedPacketData ( const IdxType  i) const
inline

Retrieve data on a deleted packet as const.

Parameters
iIndex of deleted packet to return
Returns
Const reference to data for specified deleted packet

◆ getDeletedPacketPos() [1/4]

std::vector< RealVec > & criptic::CRTree::getDeletedPacketPos ( )
inline

Retrieve deleted packet position data.

Returns
Reference to deleted packet position data

◆ getDeletedPacketPos() [2/4]

const std::vector< RealVec > & criptic::CRTree::getDeletedPacketPos ( ) const
inline

Retrieve position of a deleted packet.

Returns
Position of specified deleted packet

Retrieve deleted packet position data as const

Returns
Const reference to deleted packet position data

◆ getDeletedPacketPos() [3/4]

RealVec & criptic::CRTree::getDeletedPacketPos ( const IdxType  i)
inline

Retrieve position of a deleted packet.

Returns
Position of specified deleted packet

◆ getDeletedPacketPos() [4/4]

const RealVec & criptic::CRTree::getDeletedPacketPos ( const IdxType  i) const
inline

Retrieve position of a deleted packet as const.

Returns
Const reference to position of specified deleted packet

◆ getDeletedPacketTime() [1/4]

std::vector< Real > & criptic::CRTree::getDeletedPacketTime ( )
inline

Retrieve deleted packet deletion times.

Returns
Array of deleted packet deletion times

◆ getDeletedPacketTime() [2/4]

const std::vector< Real > & criptic::CRTree::getDeletedPacketTime ( ) const
inline

Retrieve deleted packet deletion times as const.

Returns
Const reference to array of deleted packet deletion times

◆ getDeletedPacketTime() [3/4]

Real & criptic::CRTree::getDeletedPacketTime ( const IdxType  i)
inline

Retrieve deletion time of a single deleted packet.

Parameters
iIndex of deleted packet time to return
Returns
Reference to deletion time of a single deleted packet

◆ getDeletedPacketTime() [4/4]

const Real & criptic::CRTree::getDeletedPacketTime ( const IdxType  i) const
inline

Retrieve deletion time of a single deleted packet as const.

Parameters
iIndex of deleted packet time to return
Returns
Const reference to deletion time of a single deleted packet

◆ getLoss()

const Losses & criptic::CRTree::getLoss ( ) const
inline

Return reference to the loss calculator.

Returns
Const reference to the losses object

This exposes a const reference to the losses object. It is provided so user-provided routines can have access to the loss and photon emission calculation machinery.

◆ getLossRates() [1/2]

void criptic::CRTree::getLossRates ( const IdxType  i,
const Real  t,
Real dpdt,
Real lossRate 
) const
inline

Total continuous and catastropic loss rates for specified packet.

Parameters
iPacket index
tCurrent time
dpdtVector of continuous loss rates
lossRateVector of catastrophic loss rates

◆ getLossRates() [2/2]

void criptic::CRTree::getLossRates ( const Real  t,
std::vector< Real > &  dpdt,
std::vector< Real > &  lossRate 
) const
inline

Total continuous and catastropic loss rates for all packets.

Parameters
tCurrent time
dpdtVector of continuous loss rates
lossRateVector of catastrophic loss rates

◆ getLossRatesMech() [1/2]

void criptic::CRTree::getLossRatesMech ( const IdxType  i,
const Real  t,
Losses::MechArr< Real > &  dpdt,
Losses::MechArr< Real > &  lossRate 
) const
inline

Compute mechanism-by-mechanism loss rates for specified packet.

Parameters
iPacket index
tCurrent time
dpdtVector of continuous loss rates
lossRateVector of catastrophic loss rates

dpdt and lossRate follow the same order as returned by getLossMechNames

◆ getLossRatesMech() [2/2]

void criptic::CRTree::getLossRatesMech ( const Real  t,
std::vector< Losses::MechArr< Real > > &  dpdt,
std::vector< Losses::MechArr< Real > > &  lossRate 
) const
inline

Compute mechanism-by-mechanism loss rates for all packets.

Parameters
tCurrent time
dpdtVector of continuous loss rates
lossRateVector of catastrophic loss rates

◆ getPacketData() [1/4]

std::vector< CRPacket > & criptic::CRTree::getPacketData ( )
inline

Retrieve packet data.

Returns
Reference to packet data

◆ getPacketData() [2/4]

const std::vector< CRPacket > & criptic::CRTree::getPacketData ( ) const
inline

Retrieve packet data as const.

Returns
Const eference to packet data

◆ getPacketData() [3/4]

CRPacket & criptic::CRTree::getPacketData ( const IdxType  i)
inline

Retrieve data on a packet.

Parameters
iIndex of packet to return
Returns
Data for specified packet

This method can retrieve the positions of packets in the buffer, as well as those in the main tree. If i >= pd.size(), then the packet returned will be packet i - pd.size() from the buffer.

◆ getPacketData() [4/4]

const CRPacket & criptic::CRTree::getPacketData ( const IdxType  i) const
inline

Retrieve data on a packet as const.

Parameters
iIndex of packet to return
Returns
Const reference to data for specified packet

This method can retrieve the positions of packets in the buffer, as well as those in the main tree. If i >= pd.size(), then the packet returned will be packet i - pd.size() from the buffer.

◆ getPacketPos() [1/4]

std::vector< RealVec > & criptic::CRTree::getPacketPos ( )
inline

Retrieve packet position data.

Returns
Reference to packet position data

◆ getPacketPos() [2/4]

const std::vector< RealVec > & criptic::CRTree::getPacketPos ( ) const
inline

Retrieve position of a packet.

Returns
Position of specified packet

Retrieve packet position data as const

Returns
Const reference to packet position data

◆ getPacketPos() [3/4]

RealVec & criptic::CRTree::getPacketPos ( const IdxType  i)
inline

Retrieve position of a packet.

Returns
Position of specified packet

This method can retrieve the positions of packets in the buffer, as well as those in the main tree. If i >= x.size(), then the packet returned will be packet i - x.size() from the buffer.

◆ getPacketPos() [4/4]

const RealVec & criptic::CRTree::getPacketPos ( const IdxType  i) const
inline

Retrieve position of a packet as const.

Returns
Const reference to position of specified packet

This method can retrieve the positions of packets in the buffer, as well as those in the main tree. If i >= x.size(), then the packet returned will be packet i - x.size() from the buffer.

◆ getPacketQty() [1/4]

std::vector< FieldQty > & criptic::CRTree::getPacketQty ( )
inline

Retrieve field quantities for all packets.

Returns
Vector of field quantities

◆ getPacketQty() [2/4]

const std::vector< FieldQty > & criptic::CRTree::getPacketQty ( ) const
inline

Retrieve field quantities for all packets as const.

Returns
Const reference to vector of field quantities

◆ getPacketQty() [3/4]

FieldQty & criptic::CRTree::getPacketQty ( const IdxType  i)
inline

Retrieve field quantities for a specific packet.

Parameters
iIndex of packet to return
Returns
Field quantities for specified packet

This method can retrieve quantities for packets in the buffer, as well as those in the main tree. If i >= x.size(), then the quantities returned will be those for packet i - x.size() from the buffer.

◆ getPacketQty() [4/4]

const FieldQty & criptic::CRTree::getPacketQty ( const IdxType  i) const
inline

Retrieve field quantities for a specific packet as const.

Parameters
iIndex of source to return
Returns
Const reference to Field quantities for specified packet

This method can retrieve quantities for packets in the buffer, as well as those in the main tree. If i >= x.size(), then the quantities returned will be those for packet i - x.size() from the buffer.

◆ getPacketQtyGrad() [1/4]

std::vector< FieldQtyGrad > & criptic::CRTree::getPacketQtyGrad ( )
inline

Retrieve field quantity gradients for all packets.

Returns
Vector of field quantity gradients

◆ getPacketQtyGrad() [2/4]

const std::vector< FieldQtyGrad > & criptic::CRTree::getPacketQtyGrad ( ) const
inline

Retrieve field quantity gradients for all packets as const.

Returns
Const reference to vector of field quantity gradients

◆ getPacketQtyGrad() [3/4]

FieldQtyGrad & criptic::CRTree::getPacketQtyGrad ( const IdxType  i)
inline

Retrieve field quantity gradients for a specific packet.

Parameters
iIndex of source to return
Returns
Field quantity gradients for specified packet

This method can retrieve quantity gradients for packets in the buffer, as well as those in the main tree. If i >= x.size(), then the quantity gradients returned will be those for packet i - x.size() from the buffer.

◆ getPacketQtyGrad() [4/4]

const FieldQtyGrad & criptic::CRTree::getPacketQtyGrad ( const IdxType  i) const
inline

Retrieve field quantity gradients for a specific packet as const.

Parameters
iIndex of source to return
Returns
Const reference to Field quantity gradients for specified packet

This method can retrieve quantity gradients for packets in the buffer, as well as those in the main tree. If i >= x.size(), then the quantity gradients returned will be those for packet i - x.size() from the buffer.

◆ getPacketScale()

Real & criptic::CRTree::getPacketScale ( const IdxType  i)
inline

Retrieve scale length for specified packet.

Parameters
iIndex of packet to return
Returns
Scale length for specified packet This method can retrieve quantities for packets in the buffer, as well as those in the main tree. If i >= x.size(), then the quantities returned will be those for packet i - x.size() from the buffer.

◆ getRngState()

std::string criptic::CRTree::getRngState ( ) const
inline

Get serialized RNG state.

Returns
A serialized buffer containing the RNG state

This routine is a thin wrapper around RngThread::getState()

◆ getSourceBufData()

const std::vector< CRSource > & criptic::CRTree::getSourceBufData ( ) const
inline

Retrieve source buffer data as const.

Returns
Const reference to source buffer data

◆ getSourceData() [1/4]

std::vector< CRSource > & criptic::CRTree::getSourceData ( )
inline

Retrieve source data.

Returns
Reference to source data

◆ getSourceData() [2/4]

const std::vector< CRSource > & criptic::CRTree::getSourceData ( ) const
inline

Retrieve source data as const.

Returns
Const reference to source data

◆ getSourceData() [3/4]

CRSource & criptic::CRTree::getSourceData ( const IdxType  i)
inline

Retrieve data on a source.

Parameters
iIndex of source to return
Returns
Data for specified source

◆ getSourceData() [4/4]

const CRSource & criptic::CRTree::getSourceData ( const IdxType  i) const
inline

Retrieve data on a source as const.

Parameters
iIndex of source to return
Returns
Const reference to specified source

◆ getSourcePos() [1/4]

std::vector< RealVec > & criptic::CRTree::getSourcePos ( )
inline

Retrieve source position data.

Returns
Reference to source position data

◆ getSourcePos() [2/4]

const std::vector< RealVec > & criptic::CRTree::getSourcePos ( ) const
inline

Retrieve source position data as const.

Returns
Const reference to source position data

◆ getSourcePos() [3/4]

RealVec & criptic::CRTree::getSourcePos ( const IdxType  i)
inline

Retrieve position of a source.

Parameters
iIndex of source to return
Returns
Position of specified source

◆ getSourcePos() [4/4]

const RealVec & criptic::CRTree::getSourcePos ( const IdxType  i) const
inline

Retrieve position of a source as const.

Parameters
iIndex of source to return
Returns
Const reference to position of specified source

◆ getUniqueID()

IdxType criptic::CRTree::getUniqueID ( ) const
inline

Current value of the uniqueID counter.

Returns
Current value of the uniqueID counter

◆ injectPackets()

void CRTree::injectPackets ( const Real  tStart,
const Real  tStop 
)

Inject new CR packets from sources.

Parameters
tStartStart of time interval over which to inject
tStopEnd of time interval over which to inject

◆ ionRate()

std::vector< Real > criptic::CRTree::ionRate ( const Real  t) const
inline

Compute ionization rate from all packets.

Parameters
tCurrent time
Returns
Ionization rates for all packets

This routine computes the ionization rates for H, H2, and He. Data are packed into a single vector with ionization species as the fastest varying dimension, so elements 0 - 2 in the output are the ionization rates of H, H2, and He for the first packet, elements 3 - 5 are the rates for the second packet, and so forth. The quantity returned has units of volume per time.

◆ nDeletedPacket()

IdxType criptic::CRTree::nDeletedPacket ( ) const
inline

Number of deleted packets across all MPI ranks.

Returns
Number of deleted packets across all MPI ranks

◆ nodeWgtLimits()

void CRTree::nodeWgtLimits ( const RealVec x_,
const RealBox bnd,
const RealTensor2 h2Inv,
const RealTensor2 h2InvGrad,
Real wMin,
Real wMax,
RealVec wGradMin,
RealVec wGradMax 
) const
private

Compute min and max weight functions over a node.

Parameters
x_Location of the point
bndTight bounding box for node
h2InvInverse of bandwidth squared matrix
h2InvGradSame as h2Inv, but for computation of gradients
wMinThe minimum of the weight function
wMaxThe maximum of the weight fucntion
wGradMinThe minimum of the gradient weight function
wGradMaxThe maximum of the gradient weight function

This function finds the maximum and minimum values assumed by the weight function w = exp( -r h2Inv r^T / 2) and the gradient weight function grad w = -r h2InvGrad exp( -r h2InvGrad r^T / 2) within the volume covered by the tight bounding box of the specified node, where r is a vector pointing from any point inside the bounding box to x. The minima and maxima for the gradient weight grad w are taken elementwise. The gradient weight is computed, and h2InvGrad, wGradMin, and wGradMax are used, only if the propagation model requires gradients of the field quantities.

◆ nPacket()

IdxType criptic::CRTree::nPacket ( ) const
inline

Number of packets across all MPI ranks.

Returns
Number of packets across all MPI ranks

◆ nPacketLoc()

IdxType criptic::CRTree::nPacketLoc ( ) const
inline

Number of packets on this MPI rank.

Returns
Number of packets on this MPI rank

◆ nSource()

IdxType criptic::CRTree::nSource ( ) const
inline

Number of sources across all MPI ranks.

Returns
Number of sources across all MPI ranks

◆ nSourceLoc()

IdxType criptic::CRTree::nSourceLoc ( ) const
inline

Number of sources on this MPI rank.

Returns
Number of sources on this MPI rank

◆ partitionGlobalNode()

template<class U >
IdxType CRTree::partitionGlobalNode ( const GlobalNode nd,
const IdxType  start,
const IdxType  count,
std::vector< RealVec > &  x_,
std::vector< U > &  dat 
)
private

Partition a node global node using a pre-computed split.

Template Parameters
UThe type of data to be partitioned: CRPacket or CRSource
Parameters
ndThe node to be partitioned
startStarting index of objects to be partitioned
countNumber of objects to be partitioned
x_Vector object positions to be partitioned
datVector of object data to be partitioned
Returns
The starting index of the right child

This routine is called after computeSplit, to partition packets or sources based on the computed split. This is a template function, allowing it to be called on both local and global nodes, and on both packets and sources

◆ partitionNode()

void CRTree::partitionNode ( LocalNode nd)
private

Partition a local node at the median point.

Parameters
ndThe node to partition

This routine partitions a node at the median point, and sets the properties of the partition

◆ photLum()

std::vector< Real > criptic::CRTree::photLum ( const Real  t,
const std::vector< Real > &  en 
) const
inline

Compute photon emission from all packets by all mechanisms.

Parameters
tCurrent time
enPhoton energies at which to compute emission rate
Returns
Specific luminosities at each energy dL/dE

Unlike other functions, this uses physical units. Specifically, en is the photon energy in GeV, and dL/dE is the specific luminosity in erg/s/GeV (if the code was compiled in CGS mode; J/s/GeV is compiled in MKS mode). The data are packed into a single vector, which represents a 3D array of nPacket * nMechanism * nEnergy, with energy as the fastest varying dimension and packet as the slowest varying dimension.

◆ photLumSummary()

vector< Real > CRTree::photLumSummary ( const Real  t,
const std::vector< Real > &  en,
const int  rank = 0 
) const

Compute total photon emission, summing by type and mechanism.

Parameters
tCurrent time
enPhoton energies at which to compute emission rate
rankMPI rank onto which to reduce
Returns
Specific luminosities at each energy dL/dE

Unlike other functions, this uses physical units. Specifically, en is the photon energy in GeV, and dL/dE is the specific luminosity in erg/s/GeV (if the code was compiled in CGS mode; J/s/GeV is compiled in MKS mode). The data are packed into a single vector, which represents a 4D array of nPartType * 2 * nMechanism * nEnergy, with energy as the fastest varying dimension and particle as the slowest varying dimension. The two is for primaries and secondaries, so for example element (i,j,k,l) in the output vector represents emission by the ith type of particle, considering only primaries/secondaries of that particle type for j = 0/1, via the kth emission mechanism, and in the lth energy bin. The variable rank specifies how to reduce across MPI ranks. For a value >= 0, the sum will be reduced onto that rank; a value of -1 leads to an AllReduce (i.e., data are reduced across all ranks), while a value of -2 causes no reduction to be performed (sum is local to the rank invoking the method). For calls where rank has any value other than -2, this method must be invoked collectively across MPI ranks.

◆ rebuild()

void CRTree::rebuild ( )

Rebuild the tree.

Invoking this method rebuilds the tree. It redistributes all packets and sources across MPI ranks, and builds the search tree within each rank.

◆ setRngState()

void criptic::CRTree::setRngState ( std::string &  buf) const
inline

Set RNG state from serialized buffer.

Parameters
bufA string containing the serialized state

This routine is a thin wrapper around RngThread::setState()

◆ setUniqueID()

void criptic::CRTree::setUniqueID ( const IdxType  uniqueID_)
inline

Set value of the uniqueID counter.

◆ setupDomain()

void CRTree::setupDomain ( )
private

Find the global bounding box and total number of packets.

This method finds the global bounding box and total count of packets across all MPI ranks, as a first step to partitioning the domain between ranks.

◆ sumTree()

void CRTree::sumTree ( )
private

Sum weights and bounding boxes in local tree.

This routine is called after buildLocalTree; its purpose is to sum the contributions of each node to the field quantities, and also compute tight bounding boxes on the nodes. The routine starts with the leaves, then propagates that information up to the top of the tree, including doing exchanges between MPI ranks where required.

Friends And Related Symbol Documentation

◆ CRTreeCommunicator

friend class CRTreeCommunicator
friend

Member Data Documentation

◆ cMinWgt

Real criptic::CRTree::cMinWgt
private

Weight between mean and min time steps

◆ comm

CRTreeCommunicator criptic::CRTree::comm
private

Communicator helper class

◆ cStep

Real criptic::CRTree::cStep
private

Step size control parameter

◆ dlogR

Real criptic::CRTree::dlogR
private

Size of rigidity grid spacing

◆ domHi

RealVec criptic::CRTree::domHi
private

High corner of domain bounding box

◆ domLo

RealVec criptic::CRTree::domLo
private

Low corner of domain bounding box

◆ equalSampling

int criptic::CRTree::equalSampling
private

Equal sampling for all injected species?

◆ errTol

Real criptic::CRTree::errTol
private

Field line integrator error tolerance parameter

◆ gasBG

const gas::Gas& criptic::CRTree::gasBG
private

Background gas descriptor

◆ geom

const Geometry& criptic::CRTree::geom
private

Problem geometry

◆ globNodes

std::vector<GlobalNode> criptic::CRTree::globNodes
private

Nodes of global tree

◆ globTreeExtLev

int criptic::CRTree::globTreeExtLev
private

Number of "extra levels" in global tree

◆ globTreeLeafPtr

IdxType criptic::CRTree::globTreeLeafPtr
private

Index of leaves in global tree, regardless of which MPI rank owns them

◆ globTreeMaxLev

IdxType criptic::CRTree::globTreeMaxLev
private

Maximum level in global tree

◆ globTreeMyLeafPtr

IdxType criptic::CRTree::globTreeMyLeafPtr
private

Index of first leaf this MPI rank owns in the global tree

◆ globTreeNLeaf

IdxType criptic::CRTree::globTreeNLeaf
private

Number of leaves in global tree

◆ globTreeNOwned

IdxType criptic::CRTree::globTreeNOwned
private

Number of leaves of the global tree that this rank owns

◆ h

std::vector<Real> criptic::CRTree::h
private

Scale length for packet

◆ h2InvGradLeaf

std::vector<RealTensor2> criptic::CRTree::h2InvGradLeaf
private

Inverse squared bandwidth matrix to be used for gradient estimation in each leaf

◆ h2InvLeaf

std::vector<RealTensor2> criptic::CRTree::h2InvLeaf
private

Inverse squared bandwidth matrix to be used for field quantity estimation in each leaf

◆ hBuf

std::vector<Real> criptic::CRTree::hBuf
private

Scale length for buffer packet

◆ hDither

Real criptic::CRTree::hDither
private

Dither size for sources

◆ hScaleLeaf

std::vector<Real> criptic::CRTree::hScaleLeaf
private

Length scale factor for each leaf

◆ kdeTol

Real criptic::CRTree::kdeTol
private

Kernel density estimation tolerance

◆ leafList

std::vector<IdxType> criptic::CRTree::leafList
private

List of all local tree leaves

◆ leafSize

constexpr int criptic::CRTree::leafSize = TREE_LEAF_SIZE
staticconstexpr

Size of leaf

◆ locTreeLeafStart

std::vector<IdxType> criptic::CRTree::locTreeLeafStart
private

List of nodes in local tree where leaves coming from a global tree leaf begin

◆ locTreeMaxLev

std::vector<IdxType> criptic::CRTree::locTreeMaxLev
private

Maximum level of local trees; one entry per leaf in the global tree owned by this MPI rank

◆ locTreeNLeaf

std::vector<IdxType> criptic::CRTree::locTreeNLeaf
private

Number of leaves in each local tree

◆ locTreeOffsets

std::vector<IdxType> criptic::CRTree::locTreeOffsets
private

Pointers to locations in nodes array where local tree starts; one entry per leaf in global tree owned by this MPI rank

◆ logR0

Real criptic::CRTree::logR0
private

Log of minimum CR rigidity in domain

◆ logR1

Real criptic::CRTree::logR1
private

Log of maximum CR rigidity in domain

◆ loss

const Losses& criptic::CRTree::loss
private

Loss mechanisms

◆ needFQ

bool criptic::CRTree::needFQ
private

Are field quantities needed?

◆ needFQG

bool criptic::CRTree::needFQG
private

Are gradients of field quantities needed?

◆ nNgbEff

int criptic::CRTree::nNgbEff
private

Target effective neighbor number

◆ nodes

std::vector<LocalNode> criptic::CRTree::nodes
private

Nodes of the local tree

◆ nRigidBin

constexpr int criptic::CRTree::nRigidBin = TREE_RIGIDITY_BINS
staticconstexpr

Number of rigidity bins

◆ packetDtMin

Real criptic::CRTree::packetDtMin
private

Minimum individual packet time step

◆ packetRate

Real criptic::CRTree::packetRate
private

Rate per unit time at which sources inject new packets

◆ partitionSamples

int criptic::CRTree::partitionSamples
private

Number of samples per MPI rank used to partition the global tree

◆ pd

std::vector<CRPacket> criptic::CRTree::pd
private

CR packet data

◆ pdBuf

std::vector<CRPacket> criptic::CRTree::pdBuf
private

CR packet data buffer

◆ pdDel

std::vector<CRPacket> criptic::CRTree::pdDel
private

Deleted CR packet data

◆ pMin

Real criptic::CRTree::pMin
private

Minimum packet momentum

◆ prop

const propagation::Propagation& criptic::CRTree::prop
private

CR propagation descriptor

◆ qSamp

Real criptic::CRTree::qSamp
private

Sampling index for CR packets

◆ qty

std::vector<FieldQty> criptic::CRTree::qty
private

CR field quantities

◆ qtyBuf

std::vector<FieldQty> criptic::CRTree::qtyBuf
private

Field quantities for buffer CRs

◆ qtyGrad

std::vector<FieldQtyGrad> criptic::CRTree::qtyGrad
private

CR field quantity gradients

◆ qtyGradBuf

std::vector<FieldQtyGrad> criptic::CRTree::qtyGradBuf
private

Field quantity gradients for buffer CRs

◆ rng

RngThread& criptic::CRTree::rng
private

Random number generator

◆ samplingRatio

std::vector<Real> criptic::CRTree::samplingRatio
private

Sampling ratios of different species

◆ src

std::vector<CRSource> criptic::CRTree::src
private

CR source data

◆ srcBuf

std::vector<CRSource> criptic::CRTree::srcBuf
private

CR source data buffer

◆ srcLeaf

std::vector<IdxType> criptic::CRTree::srcLeaf
private

Index of leaf to which sources belong in the array of local tree nodes

◆ tDel

std::vector<Real> criptic::CRTree::tDel
private

Times at which packets were deleted

◆ TMin

Real criptic::CRTree::TMin
private

Minimum packet kinetic energy

◆ totDeletedPacket

IdxType criptic::CRTree::totDeletedPacket
private

Number of deleted packets

◆ totPacket

IdxType criptic::CRTree::totPacket
private

Packet counter

◆ totSrc

IdxType criptic::CRTree::totSrc
private

Source counter

◆ totSrcWgt

Real criptic::CRTree::totSrcWgt
private

Total weight of all sources

◆ totSrcWgtSpec

std::vector<Real> criptic::CRTree::totSrcWgtSpec
private

Total source weight by species

◆ uniqueID

IdxType criptic::CRTree::uniqueID
private

Unique ID counter

◆ verbosity

int criptic::CRTree::verbosity
private

Level of verbosity

◆ wFracMin

Real criptic::CRTree::wFracMin
private

Minimum statistical weight of packets relative to starting weight

◆ x

std::vector<RealVec> criptic::CRTree::x
private

CR packet positions

◆ xBuf

std::vector<RealVec> criptic::CRTree::xBuf
private

CR packet position buffer

◆ xDel

std::vector<RealVec> criptic::CRTree::xDel
private

Deleted CR packet positions

◆ xSrc

std::vector<RealVec> criptic::CRTree::xSrc
private

CR source positions

◆ xSrcBuf

std::vector<RealVec> criptic::CRTree::xSrcBuf
private

CR source position buffer


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