OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
ParticleContainer.hpp
Go to the documentation of this file.
1
2#ifndef OPAL_PARTICLE_CONTAINER_H
3#define OPAL_PARTICLE_CONTAINER_H
4
5// #include <functional>
6#include <cmath>
7#include <cstddef>
8#include <functional>
9#include <memory>
10#include <string>
11#include <vector>
12
13#include "Manager/BaseManager.h"
14
16
19#include "Algorithms/PartData.h"
22
24#include "Utilities/Options.h"
25
26#include "Physics/Physics.h"
27
28// #include <Kokkos_Core.hpp>
29
30template <typename T>
31using ParticleAttrib = ippl::ParticleAttrib<T>;
32
33using size_type = ippl::detail::size_type;
34
36
61template <typename T, unsigned Dim = 3>
63 : public ippl::ParticleBase<
64 ippl::ParticleSpatialLayout<T, Dim>, Kokkos::DefaultExecutionSpace::memory_space> {
76 using Base = ippl::ParticleBase<
77 ippl::ParticleSpatialLayout<T, Dim>, Kokkos::DefaultExecutionSpace::memory_space>;
78
79private:
85 using Base::alloc;
86 using Base::create;
87 using Base::destroy;
88
89public:
91
93 using bin_index_type = short int; // Needed in AdaptBins class
94
96 using qm_view_type = typename ippl::ParticleAttrib<double>::view_type;
97
102 using spin_vector_type = ippl::Vector<float, 3>;
103
104public:
110 return QAttr.getView();
111 }
112 return QView_m;
113 }
114
120 return MAttr.getView();
121 }
122 return MView_m;
123 }
124
126 ippl::ParticleAttrib<double> dt;
127
129 ippl::ParticleAttrib<double> Phi;
130
132 ippl::ParticleAttrib<bin_index_type> Bin;
133
135 short Sp = 0;
136
138 typename Base::particle_position_type P;
139
141 typename Base::particle_position_type E;
142
144 // typename Base::particle_position_type Etmp; // TODO: might not need this...
145
147 typename Base::particle_position_type B;
148
150 ippl::ParticleAttrib<bool> InvalidMask;
151
155 ippl::ParticleAttrib<spin_vector_type> Pol;
156
159 bool hasSpin() const { return spinEnabled_m; }
160
161 ParticleContainer(Mesh_t<Dim>& mesh, FieldLayout_t<Dim>& FL, bool spinEnabled = false)
162 : pl_m(FL, mesh),
164 Options::useQMAttributes ? QMStorageMode::Attributes
167 QView_m("ParticleContainer::QView_m", 1),
168 MView_m("ParticleContainer::MView_m", 1),
169 spinEnabled_m(spinEnabled) {
170 this->initialize(pl_m);
172 setupBCs();
173 Kokkos::deep_copy(QView_m, 0.0);
174 Kokkos::deep_copy(MView_m, 0.0);
175 }
176
178
180 // register the particle attributes
181 this->addAttribute(dt);
182 this->addAttribute(Phi);
183 this->addAttribute(Bin);
184 this->addAttribute(P);
185 this->addAttribute(E);
186 this->addAttribute(B);
187 this->addAttribute(InvalidMask);
189 this->addAttribute(QAttr);
190 this->addAttribute(MAttr);
191 }
192 if (spinEnabled_m) {
193 this->addAttribute(Pol);
194 }
195 }
196
198
201 const size_t nLoc = this->getLocalNum();
202 trafo.transformBunchTo(this->R.getView(), nLoc);
203 trafo.rotateBunchTo(this->P.getView(), nLoc);
204 trafo.rotateBunchTo(this->E.getView(), nLoc);
205 trafo.rotateBunchTo(this->B.getView(), nLoc);
206 }
208
209 void setBunchStateHandler(std::shared_ptr<BunchStateHandler> handler) {
210 // We only keep the slot: per-container flags own their own sync, so
211 // no back-reference to the handler is needed. The handler itself
212 // manages bunch-wide state, which ParticleContainer never touches.
213 containerState_m = handler->registerContainer();
215 }
216
217 // -- per-container state pass-throughs --------------------------------
218 // Thin wrappers around the slot's own API so callers don't need to reach
219 // into `containerState_m` directly.
220
221 bool isUnitlessPositions() const { return containerState_m->unitlessPositions; }
222
223 bool isMomentsDirty() const { return containerState_m->momentsDirty; }
224 void markMomentsDirty() { containerState_m->markMomentsDirty(); }
225 void markMomentsClean() { containerState_m->markMomentsClean(); }
226
228 /*
229 Quick check that this container was registered with a BunchStateHandler. If not, throw an
230 error. This seems to be an easy to make error when interacting (e.g. through unit tests)
231 with the ParticleContainer.
232 */
233 if (!containerState_m) {
234 throw OpalException(
235 "ParticleContainer::updateMoments",
236 "BunchStateHandler not set in ParticleContainer (containerState is null).");
237 }
238
239 size_t Np = this->getTotalNum();
240 Np = (Np == 0) ? 1 : Np; // only used for normalization in the moments class --> avoid
241 // division by zero
242
243 size_t Nlocal = this->getLocalNum();
244
245 distMoments_m.computeMoments(this->R.getView(), this->P.getView(), getMView(), Np, Nlocal);
246 }
247
248 void setEnergyReferenceMass(double referenceMassGeV, bool rescaleToReference = true) {
249 distMoments_m.setEnergyReferenceMass(referenceMassGeV, rescaleToReference);
250 }
251
253
255
257
259
261
263 size_t Nlocal = this->getLocalNum();
264 distMoments_m.computeMinMaxPosition(this->R.getView(), Nlocal);
265 }
266
268
270
272
274
276
278
280
282
284
285 double getDx() const { return distMoments_m.getDx(); }
286
287 double getDDx() const { return distMoments_m.getDDx(); }
288
289 double getDy() const { return distMoments_m.getDy(); }
290
291 double getDDy() const { return distMoments_m.getDDy(); }
292
293 double getDebyeLength() const { return distMoments_m.getDebyeLength(); }
294
295 double getMeanGammaZ() const { return distMoments_m.getMeanGammaZ(); }
296
297 double getTemperature() const { return distMoments_m.getTemperature(); }
298
300
301 double computeDebyeLength(double density) {
302 size_t Np = this->getTotalNum();
303 Np = (Np == 0) ? 1 : Np; // only used for normalization in the moments class --> avoid
304 // division by zero
305
306 size_t Nlocal = this->getLocalNum();
307 distMoments_m.computeDebyeLength(this->P.getView(), Np, Nlocal, density);
309 }
310
318 void setQ(double q) {
320 auto view = QAttr.getView();
321 const size_type n = this->getLocalNum();
322 if (n == 0) {
323 return;
324 }
325 Kokkos::parallel_for(
326 "ParticleContainer::setQ", n,
327 KOKKOS_LAMBDA(const size_type i) { view(i) = q; });
328 Kokkos::fence();
329 } else {
330 Kokkos::deep_copy(QView_m, q);
331 }
332 }
333
335 double getChargePerParticle() const {
337 auto view = QAttr.getView();
338 if (view.extent(0) == 0) {
339 return 0.0;
340 }
341 double q = 0.0;
342 Kokkos::deep_copy(q, Kokkos::subview(view, 0));
343 return q;
344 }
345 double q = 0.0;
346 Kokkos::deep_copy(q, Kokkos::subview(QView_m, 0));
347 return q;
348 }
349
351 double getTotalCharge() const { return getChargePerParticle() * this->getTotalNum(); }
352
360 void setM(double m) {
362 auto view = MAttr.getView();
363 const size_type n = view.extent(0);
364
365 Kokkos::parallel_for(
366 "ParticleContainer::setM", n,
367 KOKKOS_LAMBDA(const size_type i) { view(i) = m; });
368 Kokkos::fence();
369 } else {
370 Kokkos::deep_copy(MView_m, m);
371 }
372 }
373
375 double getMassPerParticle() const {
377 auto view = MAttr.getView();
378 if (view.extent(0) == 0) {
379 return 0.0;
380 }
381 double m = 0.0;
382 Kokkos::deep_copy(m, Kokkos::subview(view, 0));
383 return m;
384 }
385 double m = 0.0;
386 Kokkos::deep_copy(m, Kokkos::subview(MView_m, 0));
387 return m;
388 }
389
391 double getTotalMass() const { return getMassPerParticle() * this->getTotalNum(); }
392
395
398
400 void setRefPartR(const Vector_t<double, Dim>& refPartR) { refPartR_m = refPartR; }
401
404
407
409 void setRefPartP(const Vector_t<double, Dim>& refPartP) { refPartP_m = refPartP; }
410
412 void setReference(const PartData* ref) {
413 reference_m = ref;
414 if (reference_m) {
415 // PartData mass is stored in eV; DistributionMoments expects GeV.
417 }
418 }
419
421 const PartData* getReference() const { return reference_m; }
422
424 void set_sPos(double sPos) { sPos_m = sPos; }
425
427 double get_sPos() const { return sPos_m; }
428
430 void setGlobalToLocalQuaternion(const Quaternion_t& globalToLocalQuaternion) {
431 globalToLocalQuaternion_m = globalToLocalQuaternion;
432 }
433
436
439
442
444 void setToLabTrafo(const CoordinateSystemTrafo& toLabTrafo) { toLabTrafo_m = toLabTrafo; }
445
447 void updateRefToLabCSTrafo(double bunchDT) {
450
451 const double ds =
452 std::copysign(1.0, bunchDT) * std::sqrt(R[0] * R[0] + R[1] * R[1] + R[2] * R[2]);
453 sPos_m += ds;
454
456 transformBunch(update);
458 }
459
461 template <typename Pusher>
462 void applyFractionalStep(const Pusher& pusher, double tau, double pathLengthTarget) {
463 refPartR_m /= (Physics::c * 2 * tau);
464 pusher.push(refPartR_m, refPartP_m, tau);
465 refPartR_m *= (Physics::c * 2 * tau);
466
467 sPos_m = pathLengthTarget;
474 }
475
485 auto dtView = dt.getView();
486 const size_type n = this->getLocalNum();
487 if (n == 0) {
488 return;
489 }
490
492 auto qView = QAttr.getView();
493 Kokkos::parallel_for(
494 "ParticleContainer::scaleDtByCharge(attrs)", n,
495 KOKKOS_LAMBDA(const size_type i) { dtView(i) *= qView(i); });
496 } else {
497 auto QView = QView_m;
498 Kokkos::parallel_for(
499 "ParticleContainer::scaleDtByCharge(single)", n,
500 KOKKOS_LAMBDA(const size_type i) { dtView(i) *= QView(0); });
501 }
502 Kokkos::fence();
503 }
504
513 auto dtView = dt.getView();
514 const size_type n = this->getLocalNum();
515 if (n == 0) {
516 return;
517 }
518
520 auto qView = QAttr.getView();
521 Kokkos::parallel_for(
522 "ParticleContainer::unscaleDtByCharge(attrs)", n,
523 KOKKOS_LAMBDA(const size_type i) { dtView(i) /= qView(i); });
524 } else {
525 auto QView = QView_m;
526 Kokkos::parallel_for(
527 "ParticleContainer::unscaleDtByCharge(single)", n,
528 KOKKOS_LAMBDA(const size_type i) { dtView(i) /= QView(0); });
529 }
530 Kokkos::fence();
531 }
532
541 if (containerState_m->unitlessPositions) {
542 throw OpalException(
543 "ParticleContainer::switchToUnitlessPositions",
544 "ParticleContainer is already in unitless positions!");
545 }
546 auto Rview = this->R.getView();
547 auto dtview = this->dt.getView();
548 const size_type nLocal = this->getLocalNum();
549 Kokkos::parallel_for(
550 "ParticleContainer::switchToUnitlessPositions", nLocal,
551 KOKKOS_LAMBDA(const size_type i) { Rview(i) *= 1.0 / (Physics::c * dtview(i)); });
552 Kokkos::fence();
553 containerState_m->setUnitlessPositions(true);
554 }
555
564 if (!containerState_m->unitlessPositions) {
565 throw OpalException(
566 "ParticleContainer::switchOffUnitlessPositions",
567 "ParticleContainer is already in physical positions!");
568 }
569 auto Rview = this->R.getView();
570 auto dtview = this->dt.getView();
571 const size_type nLocal = this->getLocalNum();
572 Kokkos::parallel_for(
573 "ParticleContainer::switchOffUnitlessPositions", nLocal,
574 KOKKOS_LAMBDA(const size_type i) { Rview(i) *= Physics::c * dtview(i); });
575 Kokkos::fence();
576 containerState_m->setUnitlessPositions(false);
577 }
579
580 void setGlobalProcesses(std::vector<std::unique_ptr<GlobalProcess>> processes) {
581 globalProcesses_m = std::move(processes);
582 }
583
584 const std::vector<std::unique_ptr<GlobalProcess>>& getGlobalProcesses() const {
585 return globalProcesses_m;
586 }
587
598 size_type markParticlesOutside(double sigmasAway) {
599 size_type nLocal = this->getLocalNum();
600
601 if (nLocal == 0 && this->getTotalNum() == 0) return 0;
602 if (sigmasAway <= 0.0) return 0;
603
604 // Force fresh moments: cached values from bunchUpdate may not reflect the exact
605 // particle state at this point (emission/migration ordering can shift R between
606 // the last bunchUpdate and this call). Safety-critical deletion always recomputes.
609
612
613 double lb0 = meanR[0] - sigmasAway * rmsR[0];
614 double lb1 = meanR[1] - sigmasAway * rmsR[1];
615 double lb2 = meanR[2] - sigmasAway * rmsR[2];
616 double ub0 = meanR[0] + sigmasAway * rmsR[0];
617 double ub1 = meanR[1] + sigmasAway * rmsR[1];
618 double ub2 = meanR[2] + sigmasAway * rmsR[2];
619
620 auto invalid = InvalidMask.getView();
621 auto Rview = this->R.getView();
622
623 size_type localMarkedNum = 0;
624 Kokkos::parallel_reduce(
625 "ParticleContainer::markParticlesOutside", nLocal,
626 KOKKOS_LAMBDA(const size_type i, size_type& count) {
627 bool outside = (Rview(i)[0] < lb0 || Rview(i)[0] > ub0)
628 || (Rview(i)[1] < lb1 || Rview(i)[1] > ub1)
629 || (Rview(i)[2] < lb2 || Rview(i)[2] > ub2);
630 const bool newlyMarked = outside && !invalid(i);
631 invalid(i) = invalid(i) || outside;
632 count += newlyMarked ? 1 : 0;
633 },
634 localMarkedNum);
635 Kokkos::fence(); // not needed, but also doesn't hurt
636
637 size_type globalMarkedNum = 0;
638 ippl::Comm->allreduce(localMarkedNum, globalMarkedNum, 1, std::plus<size_type>());
639 return globalMarkedNum;
640 }
641
655 void createParticles(size_type numParticles) {
656 Inform m("ParticleContainer::createParticles");
657
658 // Total allocated capacity of the underlying view
659 size_type oldCapacity = this->R.size();
660 size_type oldLocalNum = this->getLocalNum();
661 this->create(numParticles, true); // non_destructive = true
662 size_type newCapacity = this->R.size();
663
664 // Initialize newly active slots. Emitted particles are created after
665 // the per-step field reset, so E/B must be explicitly cleared here.
667 auto invalid = InvalidMask.getView();
668 auto dtView = dt.getView();
669 auto phiView = Phi.getView();
670 auto binView = Bin.getView();
671 auto eView = E.getView();
672 auto bView = B.getView();
673 Kokkos::parallel_for(
674 "ParticleContainer::createParticles::initializeNewSlots", numParticles,
675 KOKKOS_LAMBDA(const size_type i) {
676 const size_type idx = oldLocalNum + i;
677 invalid(idx) = false;
678 dtView(idx) = 0.0;
679 phiView(idx) = 0.0;
680 binView(idx) = 0;
681 eView(idx) = Vector_t<double, Dim>(0.0);
682 bView(idx) = Vector_t<double, Dim>(0.0);
683 });
684 Kokkos::fence();
685
686 // Pretty print numParticles, newCapacity and new totalNum + localNum after creation
687 constexpr int labelWidth = 32;
688 m << level4 << std::left << std::setw(labelWidth) << "Requested creation:" << numParticles
689 << " particles" << endl;
690 m << level4 << std::setw(labelWidth) << "New total number:" << this->getTotalNum()
691 << " (local: " << this->getLocalNum() << ")" << endl;
692 m << level4 << std::setw(labelWidth) << "Underlying view capacity:" << newCapacity << endl;
693
694 if (newCapacity != oldCapacity) {
695 m << level1
696 << "WARNING: createParticles triggered a reallocation of the underlying particle "
697 "views! This can be a costly operation. To avoid this, consider increasing "
698 "preallocation (BEAM::NALLOC) or the overallocation factor."
699 << endl;
700 }
701 }
702
703 void allocateParticles(size_type numParticles) {
704 Inform m("ParticleContainer::allocateParticles");
705
706 // Total allocated capacity of the underlying view
707 size_type oldCapacity = this->R.size();
708 if (oldCapacity != 0) {
709 throw OpalException(
710 "ParticleContainer::allocateParticles",
711 "Underlying views already allocated. This function is meant to be called on an "
712 "empty container, since it is destructive on existing particles. If you want "
713 "to create particles without deallocating existing ones, use createParticles() "
714 "instead.");
715 }
716
717 this->alloc(numParticles); // alloc is always destructive
718
719 m << level4 << std::left << std::setw(32) << "Requested allocation:" << numParticles
720 << " particles" << endl;
721 m << level4 << std::setw(32) << "Size of underlying view:" << this->R.size() << endl;
722 }
723
733 Inform m("ParticleContainer::deleteInvalidParticles");
734
735 const size_type nLocal = this->getLocalNum();
736 auto invalid = InvalidMask.getView();
737 if (invalid.extent(0) < nLocal) {
738 throw OpalException(
739 "ParticleContainer::deleteInvalidParticles",
740 "InvalidMask extent (" + std::to_string(invalid.extent(0))
741 + ") is smaller than local particle count (" + std::to_string(nLocal)
742 + ").");
743 }
744
745 size_type localDestroyNum = 0;
746 Kokkos::parallel_reduce(
747 "ParticleContainer::deleteInvalidParticles::count", nLocal,
748 KOKKOS_LAMBDA(const size_type i, size_type& count) { count += invalid(i) ? 1 : 0; },
749 localDestroyNum);
750 Kokkos::fence();
751
752 size_type globalDestroyNum = 0;
753 ippl::Comm->allreduce(localDestroyNum, globalDestroyNum, 1, std::plus<size_type>());
754
755 // This is a collective call! All ranks must execute it. Note that this is safe with the
756 // current IPPL implementation: ParticleBase::internalDestroy() first consumes the invalid
757 // view to build internal deleteIndex_m and keepIndex_m arrays. Meaning, the fact that
758 // destroy edits the InvalidMask while using it is not a problem.
759 Base::destroy(invalid, localDestroyNum);
760
761 // Mark moments dirty only if there were changes globally.
762 if (globalDestroyNum > 0) {
764 }
765
766 // Reset particle mask after deletion.
767 InvalidMask = false;
768 Kokkos::fence();
769
770 constexpr int labelWidth = 32;
771 m << level4 << std::left << std::setw(labelWidth)
772 << "Requested destruction:" << localDestroyNum << " particles" << endl
773 << std::setw(labelWidth) << "New total number:" << this->getTotalNum()
774 << " (local: " << this->getLocalNum() << ")" << endl;
775
776 return globalDestroyNum;
777 }
778
779private:
780 void setBCAllPeriodic() { this->setParticleBC(ippl::BC::PERIODIC); }
781
783
785
787
792 std::shared_ptr<BunchStateHandler::ContainerState> containerState_m;
793
794 // Single shared scalar mode stored as a length-1 Kokkos view.
797
798 // Per-particle attributes mode
799 ippl::ParticleAttrib<double> QAttr;
800 ippl::ParticleAttrib<double> MAttr;
801
802 // Whether the spin attribute is registered on this container.
803 bool spinEnabled_m = false;
804
805 // Reference particle information
808
809 // Global to local quaternion
811
812 // Reference particle to lab transformation
814
815 // Particle reference data (!= reference particle)
816 const PartData* reference_m = nullptr;
817
818 // Distance along the beamline
819 double sPos_m = 0.0;
820
822 std::vector<std::unique_ptr<GlobalProcess>> globalProcesses_m;
823};
824
825#endif
ippl::Vector< T, Dim > Vector_t
typename ippl::ParticleSpatialLayout< T, Dim, Mesh_t< Dim > > PLayout_t
ippl::FieldLayout< Dim > FieldLayout_t
Definition PBunchDefs.h:25
ippl::UniformCartesian< double, 3 > Mesh_t
Definition PBunchDefs.h:18
ippl::detail::size_type size_type
ippl::ParticleAttrib< T > ParticleAttrib
Quaternion getQuaternion(ippl::Vector< double, 3 > u, ippl::Vector< double, 3 > ref)
Return a unit quaternion that rotates vec onto reference.
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.
void rotateBunchTo(ViewType Pview, size_t nLocal) const
Apply rotateTo() to a Kokkos view of vectors such as momenta.
void transformBunchTo(ViewType Rview, size_t nLocal) const
Apply transformTo() to a Kokkos view of particle positions.
CoordinateSystemTrafo inverted() const
Return the inverse transform.
matrix6x6_t getMoments6x6() const
double getMeanKineticEnergy() const
Vector_t< double, 3 > getMinPosition() const
Vector_t< double, 3 > getMeanMomentum() const
void computeDebyeLength(ippl::ParticleAttrib< Vector_t< double, 3 > >::view_type Pview, size_t Np, size_t Nlocal, double density)
Vector_t< double, 3 > getStandardDeviationPosition() const
Vector_t< double, 3 > getNormalizedEmittance() const
double getTemperature() const
void computeMoments(ippl::ParticleAttrib< Vector_t< double, 3 > >::view_type Rview, ippl::ParticleAttrib< Vector_t< double, 3 > >::view_type Pview, ippl::ParticleAttrib< double >::view_type Mview, size_t Np, size_t Nlocal)
double getDebyeLength() const
void computeMinMaxPosition(ippl::ParticleAttrib< Vector_t< double, 3 > >::view_type Rview, size_t Nlcoal)
double getStdKineticEnergy() const
Vector_t< double, 3 > getStandardDeviationMomentum() const
Vector_t< double, 3 > getMeanPosition() const
Vector_t< double, 3 > getStandardDeviationRP() const
double getPlasmaParameter() const
Vector_t< double, 3 > getMaxPosition() const
Vector_t< double, 3 > getGeometricEmittance() const
Vector_t< double, 6 > getCentroid() const
void setContainerState(std::weak_ptr< BunchStateHandler::ContainerState > containerState)
void setEnergyReferenceMass(double referenceMassGeV, bool rescaleToReference=true)
Vector_t< double, 6 > getMeans() const
Particle reference data.
Definition PartData.h:37
KOKKOS_INLINE_FUNCTION double getM() const
The constant mass per particle.
Definition PartData.h:109
Container for all per-particle (and per-simulation) fields tracked during OPALX tracking.
Vector_t< double, 3 > getMeanP() const
Vector_t< double, Dim > refPartP_m
void setGlobalProcesses(std::vector< std::unique_ptr< GlobalProcess > > processes)
void setReference(const PartData *ref)
Set reference particle data.
Vector_t< double, 6 > getMeans() const
void setGlobalToLocalQuaternion(const Quaternion_t &globalToLocalQuaternion)
Set global-to-local rotation quaternion.
CoordinateSystemTrafo & getToLabTrafo()
Get local-to-lab coordinate transformation.
ippl::ParticleAttrib< bool > InvalidMask
particle deletion mask (indicates which particles are deleted every timestep)
void setRefPartR(const Vector_t< double, Dim > &refPartR)
Set the reference particle position.
qm_view_type getQView() const
Vector_t< double, 3 > getMaxR() const
ippl::ParticleAttrib< double > MAttr
Vector_t< double, Dim > & getRefPartP()
Get the reference particle momentum.
double getMeanGammaZ() const
ippl::ParticleAttrib< double > dt
timestep in [s]
const Vector_t< double, Dim > & getRefPartR() const
Get the reference particle position (const).
const CoordinateSystemTrafo & getToLabTrafo() const
Get local-to-lab coordinate transformation (const).
QMStorageMode getQMStorageMode() const
double getTotalMass() const
Get total mass [GeV] in this container.
double getPlasmaParameter() const
ippl::ParticleAttrib< double > Phi
the scalar potential in [Cb/s]
std::vector< std::unique_ptr< GlobalProcess > > globalProcesses_m
Global physics processes attached to this container.
void setRefPartP(const Vector_t< double, Dim > &refPartP)
Set the reference particle momentum.
Vector_t< double, 3 > getRmsP() const
Vector_t< double, 3 > getMinR() const
Vector_t< double, 3 > getRmsRP() const
void scaleDtByCharge()
Scale particle time-step weights by charge before scatter.
Base::particle_position_type B
electric field for gun simulation with bins
ippl::Vector< float, 3 > spin_vector_type
const PartData * reference_m
Vector_t< double, Dim > refPartR_m
Vector_t< double, 3 > getGeometricEmit() const
double computeDebyeLength(double density)
void transformBunch(const CoordinateSystemTrafo &trafo)
Apply coordinate transform to local particles: translate R, rotate P, E, B.
ippl::ParticleAttrib< spin_vector_type > Pol
CoordinateSystemTrafo toLabTrafo_m
size_type markParticlesOutside(double sigmasAway)
Mark particles whose position is more than sigmasAway standard deviations from the bunch mean in any ...
void applyFractionalStep(const Pusher &pusher, double tau, double pathLengthTarget)
Apply a fractional Boris step and update reference/lab transform state.
void switchOffUnitlessPositions()
Restore physical positions from unitless form using each particle's dt[i].
const Vector_t< double, Dim > & getRefPartP() const
Get the reference particle momentum (const).
matrix6x6_t getCovMatrix() const
void setBunchStateHandler(std::shared_ptr< BunchStateHandler > handler)
QMStorageMode qmStorageMode_m
Vector_t< double, Dim > & getRefPartR()
Get the reference particle position.
short Sp
the particle specis
Vector_t< double, 6 > getCentroid() const
Vector_t< double, 3 > getNormEmit() const
void unscaleDtByCharge()
Restore original dt values after scaleDtByCharge().
double getMeanKineticEnergy() const
PLayout_t< T, Dim > pl_m
const std::vector< std::unique_ptr< GlobalProcess > > & getGlobalProcesses() const
void setToLabTrafo(const CoordinateSystemTrafo &toLabTrafo)
Set local-to-lab coordinate transformation.
double getTotalCharge() const
Get total charge [Cb] in this container.
void setEnergyReferenceMass(double referenceMassGeV, bool rescaleToReference=true)
ippl::ParticleAttrib< bin_index_type > Bin
the energy bin the particle is in
void setQ(double q)
Set particle charge for the active Q storage mode.
std::shared_ptr< BunchStateHandler::ContainerState > containerState_m
Vector_t< double, 3 > getMeanR() const
Vector_t< double, 3 > getRmsR() const
double getMassPerParticle() const
Get mass per particle [GeV].
typename ippl::ParticleAttrib< double >::view_type qm_view_type
View types of Q and M values.
short int bin_index_type
Defines which type to use as a particle bin.
void updateRefToLabCSTrafo(double bunchDT)
Advance reference/lab transform state and map bunch accordingly.
const PartData * getReference() const
Get reference particle data.
Base::particle_position_type E
electric field at particle position
Base::particle_position_type P
particle momenta [\beta\gamma]
ParticleContainer(Mesh_t< Dim > &mesh, FieldLayout_t< Dim > &FL, bool spinEnabled=false)
double getChargePerParticle() const
Get charge per particle [Cb].
double getTemperature() const
ippl::ParticleBase< ippl::ParticleSpatialLayout< T, Dim >, Kokkos::DefaultExecutionSpace::memory_space > Base
Alias for the ippl::ParticleBase specialization this container inherits from.
qm_view_type getMView() const
Quaternion_t globalToLocalQuaternion_m
void switchToUnitlessPositions()
Transform positions to unitless coordinates using each particle's dt[i].
double getStdKineticEnergy() const
void createParticles(size_type numParticles)
Create/allocate a specified number of particles.
ippl::ParticleAttrib< double > QAttr
void setM(double m)
Set particle mass for the active M storage mode.
DistributionMoments distMoments_m
double getDebyeLength() const
size_type deleteInvalidParticles()
Delete particles currently marked in InvalidMask.
double get_sPos() const
Get longitudinal position along design trajectory.
void set_sPos(double sPos)
Set longitudinal position along design trajectory.
PLayout_t< T, Dim > & getPL()
bool isUnitlessPositions() const
Quaternion_t getGlobalToLocalQuaternion() const
Get global-to-local rotation quaternion.
void allocateParticles(size_type numParticles)
Quaternion storage and rotation algebra used by OPALX geometry code.
A collection of routines to construct object Attributes and retrieve.
constexpr double c
The velocity of light in m/s.
Definition Physics.h:60
constexpr double eV2GeV
Definition Units.h:71