42 filename_m(right.filename_m),
43 plane_m(right.plane_m),
68 const double sPos = pc->get_sPos();
70 if (globalStep == 0 && std::abs(sPos) < 1.0e-14) {
71 Inform msg(
"Monitor::apply(pc)");
72 msg << level5 <<
"Ignoring pre-tracking spatial particle crossing"
73 <<
" globalStep=" << globalStep <<
" pc_spos=" << sPos << endl;
77 const auto nLoc = pc->getLocalNum();
82 auto Rview = pc->R.getView();
83 auto Pview = pc->P.getView();
84 auto dtview = pc->dt.getView();
85 auto IDview = pc->ID.getView();
86 auto Qview = pc->getQView();
87 auto Mview = pc->getMView();
89 auto hR = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Rview);
90 auto hP = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Pview);
91 auto hdt = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), dtview);
92 auto hID = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), IDview);
93 auto hQ = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Qview);
94 auto hM = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Mview);
96 const bool qmAreAttributes =
101 for (
size_t i = 0; i < nLoc; ++i) {
104 const double dt = hdt(i);
108 if (singleStep(2) == 0.0) {
112 if (dt * R(2) < 0.0 && dt * (R(2) + singleStep(2)) > 0.0) {
113 const double frac = -R(2) / singleStep(2);
118 const std::size_t
id =
static_cast<std::size_t
>(hID(i));
119 const double q = qmAreAttributes ? hQ(i) : hQ(0);
120 const double m = qmAreAttributes ? hM(i) : hM(0);
139 const std::shared_ptr<ParticleContainer_t> pc =
RefPartBunch_m->getParticleContainer();
144 auto Rview = pc->
R.getView();
145 auto Pview = pc->P.getView();
146 auto dtview = pc->dt.getView();
147 auto IDview = pc->ID.getView();
148 auto Qview = pc->getQView();
149 auto Mview = pc->getMView();
153 const double dt = dtview(i);
157 if (singleStep(2) == 0.0) {
161 if (dt * R(2) < 0.0 && dt * (R(2) + singleStep(2)) > 0.0) {
162 const double frac = -R(2) / singleStep(2);
164 const double crossingTime = t + frac * dt;
166 const bool qmAreAttributes =
169 const std::size_t
id =
static_cast<std::size_t
>(IDview(i));
170 const double q = qmAreAttributes ? Qview(i) : Qview(0);
171 const double m = qmAreAttributes ? Mview(i) : Mview(0);
194 const std::shared_ptr<ParticleContainer_t> pc =
RefPartBunch_m->getParticleContainer();
204 if (driftPerTimeStep(2) == 0.0) {
208 const double tau = -refR(2) / driftPerTimeStep(2);
216 auto Rview = pc->R.getView();
217 auto Pview = pc->P.getView();
218 auto IDview = pc->ID.getView();
219 auto Qview = pc->getQView();
220 auto Mview = pc->getMView();
222 auto hR = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Rview);
223 auto hP = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Pview);
224 auto hID = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), IDview);
225 auto hQ = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Qview);
226 auto hM = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Mview);
228 const auto nLoc = pc->getLocalNum();
230 const bool qmAreAttributes =
235 for (
size_t i = 0; i < nLoc; ++i) {
245 const std::size_t
id =
static_cast<std::size_t
>(hID(i));
247 const double q = qmAreAttributes ? hQ(i) : hQ(0);
249 const double macroMassGeV = qmAreAttributes ? hM(i) : hM(0);
250 const double macroWeight = std::abs(q) / std::abs(
Physics::q_e);
252 const double m = macroWeight > 0.0 ? macroMassGeV *
Units::GeV2MeV / macroWeight
267 const std::shared_ptr<ParticleContainer_t> pc =
RefPartBunch_m->getParticleContainer();
276 if (singleStep(2) == 0.0) {
280 if (dt * R(2) < 0.0 && dt * (R(2) + singleStep(2)) > 0.0) {
282 const double sPos = pc->get_sPos();
284 if (globalStep == 0 && std::abs(sPos) < 1.0e-14) {
285 Inform msg(
"Monitor::applyToReferenceParticle");
286 msg << level5 <<
"Ignoring pre-tracking reference crossing"
287 <<
" globalStep=" << globalStep <<
" pc_spos=" << sPos << endl;
291 const double frac = -R(2) / singleStep(2);
292 const double time = t + frac * dt;
305 auto stats =
lossDs_m->computeStatistics(1);
306 if (!stats.empty()) {
329 double currentPosition = endField;
330 if (bunch !=
nullptr) {
331 const std::shared_ptr<ParticleContainer_t> pc = bunch->getParticleContainer();
333 currentPosition = pc->get_sPos();
340 || currentPosition < startField) {
341 namespace fs = std::filesystem;
343 const fs::path lossFileName(
filename_m +
".h5");
344 if (fs::exists(lossFileName)) {
345 ippl::Comm->barrier();
346 if (ippl::Comm->rank() == 0) {
347 fs::remove(lossFileName);
349 ippl::Comm->barrier();
366 for (
auto& stat : stats) {
388 std::string fileName =
391 bool hasPriorTrack = instance->hasPriorTrack();
392 bool inRestartRun = instance->inRestartRun();
395 double spos = it->first;
401 writer.
addRow(entry.second);
ippl::Vector< T, Dim > Vector_t
Template PIC bunch: IPPL PicManager, shared field mesh/solver, and multiple particle containers.
Quaternion getQuaternion(ippl::Vector< double, 3 > u, ippl::Vector< double, 3 > ref)
Return a unit quaternion that rotates vec onto reference.
KOKKOS_INLINE_FUNCTION double euclidean_norm(const Vector_t< T, D > &v)
virtual void visitMonitor(const Monitor &)=0
Apply the algorithm to a beam position monitor.
PartBunch_t * RefPartBunch_m
Rigid spatial transform between a parent frame and a local frame.
ippl::Vector< double, 3 > transformFrom(const ippl::Vector< double, 3 > &r) const
Map a point from the local frame back to the parent frame.
ippl::Vector< double, 3 > rotateFrom(const ippl::Vector< double, 3 > &r) const
Rotate a vector from the local frame back into the parent frame.
ippl::Vector< double, 3 > rotateTo(const ippl::Vector< double, 3 > &r) const
Rotate a vector from the parent frame into the local frame.
ippl::Vector< double, 3 > transformTo(const ippl::Vector< double, 3 > &r) const
Map a point from the parent frame to the local frame.
bool update(const AttributeSet &)
Update element.
CoordinateSystemTrafo getCSTrafoGlobal2Local() const
std::string getOutputFN() const
Get output filename.
CoordinateSystemTrafo csTrafoGlobal2Local_m
void addRow(const SetStatistics &set)
static void writeStatistics()
void accept(BeamlineVisitor &) const override
Apply visitor to Monitor.
virtual void goOnline(const double &kineticEnergy) override
virtual ElementType getType() const override
virtual void goOffline() override
std::unique_ptr< LossDataSink > lossDs_m
static std::map< double, SetStatistics > statFileEntries_sm
virtual void finalise() override
unsigned int numPassages_m
virtual bool applyToReferenceParticle(const Vector_t< double, 3 > &R, const Vector_t< double, 3 > &P, const double &t, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) override
Apply to reference particle with position R and momemtum P.
virtual void initialise(PartBunch_t *bunch, double &startField, double &endField) override
static const double halfLength_s
void driftToCorrectPositionAndSave(const Vector_t< double, 3 > &R, const Vector_t< double, 3 > &P)
virtual bool bends() const override
virtual void getFieldExtend(double &zBegin, double &zEnd) const override
Return the field-support extent of the component.
virtual bool apply(const std::shared_ptr< ParticleContainer_t > &pc) override
Apply to all particles. Kernel launch moved inside the function.
std::string getInputBasename()
get input file name without extension
OpenMode getOpenMode() const
static OpalData * getInstance()
OpenMode
Enum for writing to files.
Vector_t< double, Dim > R(size_t)
Do not use; throws (access positions via ParticleContainer::R).
double getdT() const
Get the global time step.
double getT() const
Get the current simulation time.
long long getGlobalTrackStep() const
Current global tracking step.
constexpr double q_e
The elementary charge in As.
constexpr double c
The velocity of light in m/s.
unsigned int rewindLinesSDDS(const std::string &fileName, double maxSPos, bool checkForTime)
rewind the SDDS file such that the spos of the last step is less or equal to maxSPos
ippl::Vector< double, 3 > getBeta(ippl::Vector< double, 3 > p)