20#include "../Gas/Gas.H"
21#include "../Losses/Ionization.H"
22#include "../Losses/Losses.H"
23#include "../MPI/CRTreeCommunicator.H"
24#include "../MPI/MPIUtil.H"
25#include "../Propagation/Propagation.H"
26#include "../Utils/RealBox.H"
27#include "../Utils/RealTensor2.H"
28#include "../Utils/RngThread.H"
29#include "../Utils/Types.H"
30#include "../Utils/Vec3.H"
80 const std::vector<CRPacket>& pd_,
81 const std::vector<RealVec>& xSrc_,
82 const std::vector<CRSource>& src_);
90 void addPackets(
const std::vector<RealVec>& x_,
91 const std::vector<CRPacket>& pd_);
98 void addSources(
const std::vector<RealVec>& xSrc_,
99 const std::vector<CRSource>& src_);
117 std::vector<IdxType>& sIdx,
129 std::vector<IdxType> sIdx;
141 std::vector<IdxType> pIdx;
212 if (i <
x.size())
return x[i];
213 else return xBuf[i-
x.size()];
226 if (i <
x.size())
return x[i];
227 else return xBuf[i-
x.size()];
250 assert(i <
pd.size() +
pdBuf.size());
251 if (i <
pd.size())
return pd[i];
252 else return pdBuf[i -
pd.size()];
265 assert(i <
pd.size() +
pdBuf.size());
266 if (i <
pd.size())
return pd[i];
267 else return pdBuf[i -
pd.size()];
290 assert(i <
xDel.size());
298 assert(i <
xDel.size());
317 assert(i <
pdDel.size());
326 assert(i <
pdDel.size());
373 assert(i <
xSrc.size());
382 assert(i <
xSrc.size());
401 assert(i <
src.size());
410 assert(i <
src.size());
434 else if (i <
h.size())
return h[i];
435 else return hBuf[i-
h.size()];
462 else if (i <
qty.size())
return qty[i];
478 else if (i <
qty.size())
return qty[i];
547 std::vector<Real>& dpdt,
548 std::vector<Real>& lossRate)
const {
549 dpdt.resize(
pd.size());
550 lossRate.resize(
pd.size());
552#pragma omp parallel for
554 for (
IdxType i = 0; i <
pd.size(); i++) {
556 Losses::MechMatrix<Real> pSec;
558 loss.computeLoss(gd,
pd[i], dpdt[i], lossRate[i], wSec, pSec);
572 Real& lossRate)
const {
576 Losses::MechMatrix<Real> pSec;
578 loss.computeLoss(gd, pd_, dpdt, lossRate, wSec, pSec);
588 std::vector<Losses::MechArr<Real> >& dpdt,
589 std::vector<Losses::MechArr<Real> >& lossRate)
591 dpdt.resize(
pd.size());
592 lossRate.resize(
pd.size());
594#pragma omp parallel for
596 for (
IdxType i = 0; i <
pd.size(); i++) {
598 dpdt[i] =
loss.dpdtMech(gd,
pd[i]);
599 lossRate[i] =
loss.lossRateMech(gd,
pd[i]);
615 Losses::MechArr<Real>& dpdt,
616 Losses::MechArr<Real>& lossRate)
const {
620 dpdt =
loss.dpdtMech(gd, pd_);
621 lossRate =
loss.lossRateMech(gd, pd_);
641 const std::vector<Real>& en)
const {
642 IdxType packetSize = lossMech::nMech * en.size();
643 std::vector<Real> out(
pd.size() * packetSize);
645#pragma omp parallel for
647 for (
IdxType i = 0; i <
pd.size(); i++) {
649 std::vector<Real> dLdE =
loss.photLum(gd,
pd[i], en);
650 memcpy(out.data() + i*packetSize,
652 packetSize *
sizeof(
Real));
685 const std::vector<Real>& en,
686 const int rank = 0)
const;
704 std::vector<Real> out(
pd.size() * ionData::nTarget);
706#pragma omp parallel for
708 for (
IdxType i = 0; i <
pd.size(); i++) {
710 out[i * ionData::nTarget] =
711 gd.
xH0 * gd.
nH() *
loss.ionRate(
pd[i], ionData::targetH);
712 out[i * ionData::nTarget + 1] =
713 gd.
xH2() * gd.
nH() *
loss.ionRate(
pd[i], ionData::targetH2);
714 out[i * ionData::nTarget + 2] =
715 gd.
xHe0 * gd.
nH() *
loss.ionRate(
pd[i], ionData::targetHe);
720#ifndef TRACK_PITCH_ANGLE
814 if (
x.size() == 0)
return;
815 std::vector<IdxType> start(
leafList.size());
816 std::vector<IdxType> count(
leafList.size());
904 std::vector<RealVec>& x_,
905 std::vector<U>& dat);
961 std::vector<IdxType>& count,
962 std::vector<IdxType>& leafList_);
1001 ,
const int nrank = 0,
1125 std::vector<RealVec>
x;
1126 std::vector<CRPacket>
pd;
1128 std::vector<Real>
h;
Class to hold data on a CR packet.
Class to define a source of CRs.
Data structures to describe nodes in the CR tree.
#define TREE_LEAF_SIZE
Maximum number of packets per leaf in the CR tree.
Definition Definitions.H:76
#define TREE_RIGIDITY_BINS
Number of rigidity bins to use in the CR tree.
Definition Definitions.H:85
Define classes for field quantities and their gradients.
A class to describe the geometry of a calculation.
A class that holds data to describe a CR packet.
Definition CRPacket.H:28
A class to describe a source of CR packets.
Definition CRSource.H:33
Class to manage communications during tree walks.
Definition CRTreeCommunicator.H:48
A class to manage CR packets and sources.
Definition CRTree.H:44
bool needFQ
Definition CRTree.H:1119
static constexpr int nRigidBin
Definition CRTree.H:784
std::vector< RealVec > & getDeletedPacketPos()
Retrieve deleted packet position data.
Definition CRTree.H:275
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.
Definition CRTree.cpp:2661
std::vector< IdxType > srcLeaf
Definition CRTree.H:1153
Real kdeTol
Definition CRTree.H:1103
const Real & getDeletedPacketTime(const IdxType i) const
Retrieve deletion time of a single deleted packet as const.
Definition CRTree.H:352
const std::vector< Real > & getDeletedPacketTime() const
Retrieve deleted packet deletion times as const.
Definition CRTree.H:338
RealVec domLo
Definition CRTree.H:1158
std::vector< IdxType > leafList
Definition CRTree.H:1194
std::vector< CRPacket > & getDeletedPacketData()
Retrieve deleted packet data.
Definition CRTree.H:305
const Geometry & geom
Definition CRTree.H:1079
std::vector< RealTensor2 > h2InvLeaf
Definition CRTree.H:1198
Real advancePackets(const Real tStart, const Real tStop)
Advance all packets through one time step.
Definition CRTree.cpp:2929
IdxType globTreeLeafPtr
Definition CRTree.H:1172
void buildLocalTree()
Build the local KD tree.
Definition CRTree.cpp:1331
std::vector< CRSource > srcBuf
Definition CRTree.H:1152
std::vector< FieldQtyGrad > qtyGradBuf
Definition CRTree.H:1134
std::vector< RealVec > xSrc
Definition CRTree.H:1149
std::vector< RealVec > x
Definition CRTree.H:1125
const CRPacket & getPacketData(const IdxType i) const
Retrieve data on a packet as const.
Definition CRTree.H:264
Real packetDtMin
Definition CRTree.H:1117
std::vector< RealTensor2 > h2InvGradLeaf
Definition CRTree.H:1202
const CRSource & getSourceData(const IdxType i) const
Retrieve data on a source as const.
Definition CRTree.H:409
Real TMin
Definition CRTree.H:1116
int globTreeExtLev
Definition CRTree.H:1097
void buildGlobalTree()
Build the global KD tree.
Definition CRTree.cpp:458
IdxType uniqueID
Definition CRTree.H:1093
std::vector< FieldQtyGrad > qtyGrad
Definition CRTree.H:1129
std::vector< RealVec > xDel
Definition CRTree.H:1140
std::vector< CRSource > src
Definition CRTree.H:1150
std::vector< Real > ionRate(const Real t) const
Compute ionization rate from all packets.
Definition CRTree.H:703
Real qSamp
Definition CRTree.H:1105
IdxType nSourceLoc() const
Number of sources on this MPI rank.
Definition CRTree.H:175
void fillFieldQty()
Compute the field quantities for packets in the tree.
Definition CRTree.H:813
const std::vector< CRPacket > & getDeletedPacketData() const
Retrieve deleted packet data as const.
Definition CRTree.H:310
void setupDomain()
Find the global bounding box and total number of packets.
Definition CRTree.cpp:360
IdxType getUniqueID() const
Current value of the uniqueID counter.
Definition CRTree.H:180
Real cMinWgt
Definition CRTree.H:1108
RngThread & rng
Definition CRTree.H:1084
IdxType globTreeMaxLev
Definition CRTree.H:1169
std::vector< CRPacket > pdBuf
Definition CRTree.H:1131
IdxType nDeletedPacket() const
Number of deleted packets across all MPI ranks.
Definition CRTree.H:165
IdxType totSrc
Definition CRTree.H:1146
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.
Definition CRTree.H:613
std::vector< IdxType > locTreeNLeaf
Definition CRTree.H:1192
bool needFQG
Definition CRTree.H:1120
std::vector< CRPacket > pd
Definition CRTree.H:1126
std::vector< Real > hBuf
Definition CRTree.H:1136
std::vector< Real > & getDeletedPacketTime()
Retrieve deleted packet deletion times.
Definition CRTree.H:333
std::vector< FieldQty > qtyBuf
Definition CRTree.H:1132
IdxType globTreeMyLeafPtr
Definition CRTree.H:1175
const RealVec & getSourcePos(const IdxType i) const
Retrieve position of a source as const.
Definition CRTree.H:381
const std::vector< FieldQtyGrad > & getPacketQtyGrad() const
Retrieve field quantity gradients for all packets as const.
Definition CRTree.H:492
std::vector< Real > hScaleLeaf
Definition CRTree.H:1206
Real wFracMin
Definition CRTree.H:1113
std::vector< FieldQtyGrad > & getPacketQtyGrad()
Retrieve field quantity gradients for all packets.
Definition CRTree.H:487
int equalSampling
Definition CRTree.H:1102
std::vector< Real > photLum(const Real t, const std::vector< Real > &en) const
Compute photon emission from all packets by all mechanisms.
Definition CRTree.H:640
void addPackets(const std::vector< RealVec > &x_, const std::vector< CRPacket > &pd_)
Add CR packets to the tree.
Definition CRTree.cpp:211
IdxType nPacket() const
Number of packets across all MPI ranks.
Definition CRTree.H:155
const std::vector< FieldQty > & getPacketQty() const
Retrieve field quantities for all packets as const.
Definition CRTree.H:448
void deleteSources(std::vector< IdxType > &sIdx)
Delete CR packets.
Definition CRTree.H:140
std::vector< CRSource > & getSourceData()
Retrieve source data.
Definition CRTree.H:389
int partitionSamples
Definition CRTree.H:1099
IdxType nSource() const
Number of sources across all MPI ranks.
Definition CRTree.H:170
const std::vector< CRSource > & getSourceBufData() const
Retrieve source buffer data as const.
Definition CRTree.H:418
CRPacket & getDeletedPacketData(const IdxType i)
Retrieve data on a deleted packet.
Definition CRTree.H:316
int verbosity
Definition CRTree.H:1096
Real totSrcWgt
Definition CRTree.H:1147
IdxType globTreeNLeaf
Definition CRTree.H:1170
RealVec & getSourcePos(const IdxType i)
Retrieve position of a source.
Definition CRTree.H:372
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.
Definition CRTree.H:587
std::vector< Real > totSrcWgtSpec
Definition CRTree.H:1148
std::vector< RealVec > xSrcBuf
Definition CRTree.H:1151
Real hDither
Definition CRTree.H:1104
std::vector< Real > h
Definition CRTree.H:1128
Real cStep
Definition CRTree.H:1110
FieldQty & getPacketQty(const IdxType i)
Retrieve field quantities for a specific packet.
Definition CRTree.H:459
std::vector< RealVec > xBuf
Definition CRTree.H:1130
CRSource & getSourceData(const IdxType i)
Retrieve data on a source.
Definition CRTree.H:400
std::vector< GlobalNode > globNodes
Definition CRTree.H:1196
const FieldQty & getPacketQty(const IdxType i) const
Retrieve field quantities for a specific packet as const.
Definition CRTree.H:475
const propagation::Propagation & prop
Definition CRTree.H:1081
FieldQtyGrad & getPacketQtyGrad(const IdxType i)
Retrieve field quantity gradients for a specific packet.
Definition CRTree.H:505
const FieldQtyGrad & getPacketQtyGrad(const IdxType i) const
Retrieve field quantity gradients for a specific packet as const.
Definition CRTree.H:521
std::vector< Real > computePdot(const Real t) const
Compute non-loss dp/dt terms for all packets.
Definition CRTree.cpp:3283
const std::vector< CRSource > & getSourceData() const
Retrieve source data as const.
Definition CRTree.H:394
void partitionNode(LocalNode &nd)
Partition a local node at the median point.
Definition CRTree.cpp:1509
const CRPacket & getDeletedPacketData(const IdxType i) const
Retrieve data on a deleted packet as const.
Definition CRTree.H:325
std::vector< Real > tDel
Definition CRTree.H:1142
Real errTol
Definition CRTree.H:1111
const RealVec & getDeletedPacketPos(const IdxType i) const
Retrieve position of a deleted packet as const.
Definition CRTree.H:297
void computeSplit(GlobalNode &nd)
Figure out how to split a global tree node.
Definition CRTree.cpp:572
void clearDeletedPackets()
Remove deleted packets.
Definition CRTree.H:772
RealVec & getDeletedPacketPos(const IdxType i)
Retrieve position of a deleted packet.
Definition CRTree.H:289
Real dlogR
Definition CRTree.H:1166
IdxType nPacketLoc() const
Number of packets on this MPI rank.
Definition CRTree.H:160
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.
Definition CRTree.cpp:740
const std::vector< CRPacket > & getPacketData() const
Retrieve packet data as const.
Definition CRTree.H:238
const Losses & loss
Definition CRTree.H:1083
void rebuild()
Rebuild the tree.
Definition CRTree.cpp:301
void injectPackets(const Real tStart, const Real tStop)
Inject new CR packets from sources.
Definition CRTree.cpp:2761
const std::vector< RealVec > & getPacketPos() const
Retrieve position of a packet.
Definition CRTree.H:200
std::vector< RealVec > & getSourcePos()
Retrieve source position data.
Definition CRTree.H:361
std::vector< Real > photLumSummary(const Real t, const std::vector< Real > &en, const int rank=0) const
Compute total photon emission, summing by type and mechanism.
Definition CRTree.cpp:3212
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.
Definition CRTree.cpp:2535
std::vector< LocalNode > nodes
Definition CRTree.H:1197
int nNgbEff
Definition CRTree.H:1101
std::vector< IdxType > locTreeLeafStart
Definition CRTree.H:1188
Real pMin
Definition CRTree.H:1115
std::vector< IdxType > locTreeMaxLev
Definition CRTree.H:1184
std::vector< RealVec > & getPacketPos()
Retrieve packet position data.
Definition CRTree.H:191
Real & getPacketScale(const IdxType i)
Retrieve scale length for specified packet.
Definition CRTree.H:431
CRTreeCommunicator comm
Definition CRTree.H:1088
const std::vector< RealVec > & getSourcePos() const
Retrieve source position data as const.
Definition CRTree.H:366
const gas::Gas & gasBG
Definition CRTree.H:1080
Real logR0
Definition CRTree.H:1162
void exchange()
Exchange packets and sources across MPI ranks.
Definition CRTree.cpp:785
Real logR1
Definition CRTree.H:1164
void setUniqueID(const IdxType uniqueID_)
Set value of the uniqueID counter.
Definition CRTree.H:184
void setRngState(std::string &buf) const
Set RNG state from serialized buffer.
Definition CRTree.H:758
std::string getRngState() const
Get serialized RNG state.
Definition CRTree.H:748
void addSources(const std::vector< RealVec > &xSrc_, const std::vector< CRSource > &src_)
Add CR sources to the tree.
Definition CRTree.cpp:219
const Losses & getLoss() const
Return reference to the loss calculator.
Definition CRTree.H:538
IdxType totDeletedPacket
Definition CRTree.H:1139
Real & getDeletedPacketTime(const IdxType i)
Retrieve deletion time of a single deleted packet.
Definition CRTree.H:344
void deletePacketsAndSources(std::vector< IdxType > &pIdx, std::vector< IdxType > &sIdx, const Real t)
Delete CR packets and sources from the tree.
Definition CRTree.cpp:230
RealVec domHi
Definition CRTree.H:1160
void sumTree()
Sum weights and bounding boxes in local tree.
Definition CRTree.cpp:1559
std::vector< FieldQty > & getPacketQty()
Retrieve field quantities for all packets.
Definition CRTree.H:443
IdxType globTreeNOwned
Definition CRTree.H:1177
std::vector< CRPacket > & getPacketData()
Retrieve packet data.
Definition CRTree.H:233
std::vector< IdxType > locTreeOffsets
Definition CRTree.H:1179
void getLossRates(const Real t, std::vector< Real > &dpdt, std::vector< Real > &lossRate) const
Total continuous and catastropic loss rates for all packets.
Definition CRTree.H:546
void getLossRates(const IdxType i, const Real t, Real &dpdt, Real &lossRate) const
Total continuous and catastropic loss rates for specified packet.
Definition CRTree.H:569
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.
Definition CRTree.cpp:2076
IdxType totPacket
Definition CRTree.H:1124
Real packetRate
Definition CRTree.H:1106
std::vector< FieldQty > qty
Definition CRTree.H:1127
RealVec & getPacketPos(const IdxType i)
Retrieve position of a packet.
Definition CRTree.H:210
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.
Definition CRTree.cpp:157
const RealVec & getPacketPos(const IdxType i) const
Retrieve position of a packet as const.
Definition CRTree.H:224
const std::vector< RealVec > & getDeletedPacketPos() const
Retrieve position of a deleted packet.
Definition CRTree.H:284
void deletePackets(std::vector< IdxType > &pIdx, const Real t)
Delete CR packets.
Definition CRTree.H:128
std::vector< Real > samplingRatio
Definition CRTree.H:1118
CRPacket & getPacketData(const IdxType i)
Retrieve data on a packet.
Definition CRTree.H:249
static constexpr int leafSize
Definition CRTree.H:782
std::vector< CRPacket > pdDel
Definition CRTree.H:1141
Class to hold and compute gradients of field quantities.
Definition FieldQty.H:293
Class to hold and compute field quantities.
Definition FieldQty.H:53
A class that describes the geometry of a calculation.
Definition Geometry.H:32
Class to parse the criptic input deck.
Definition ParmParser.H:37
Class that represents a 3D rectangular prism.
Definition RealBox.H:30
Class that represents a rank 2 tensor.
Definition RealTensor2.H:34
Thread-safe random number generator.
Definition RngThread.H:39
const std::string getState() const
Get a serialized buffer holding the RNG state.
Definition RngThread.cpp:53
void setState(const std::string &buf)
Restore the RNG state from a buffer.
Definition RngThread.cpp:71
Trivial class to hold gas data.
Definition GasData.H:29
constexpr Real nH() const
Compute number density of H nuclei.
Definition GasData.H:148
constexpr Real xH2() const
Compute H2 abundance.
Definition GasData.H:84
Real xHe0
Definition GasData.H:50
Real xH0
Definition GasData.H:48
Interface class to describe background gas.
Definition Gas.H:44
virtual GasData gasData(const RealVec &x, const Real t) const =0
Return background gas state.
Interface to describe the CR propagation model.
Definition Propagation.H:79
The primary namespace for criptic objects.
Definition AdvancePacket.H:25
std::vector< Real >::size_type IdxType
Definition Types.H:45
double Real
Definition Types.H:38
Struct representing a node of the global KD tree.
Definition CRTreeNode.H:40
Struct representing a node of the local KD tree.
Definition CRTreeNode.H:58