From 6655c45ee3443be8c3a65b0473b3a8dc50a8a9b6 Mon Sep 17 00:00:00 2001 From: Christof Kraus <christof.kraus@psi.ch> Date: Thu, 23 Jul 2020 20:54:10 +0200 Subject: [PATCH] Resolve 'Add option to source element to make it transparent to backtracking particles' --- src/Classic/AbsBeamline/Source.cpp | 14 ++++++++++++-- src/Classic/AbsBeamline/Source.h | 3 +++ src/Elements/OpalSource.cpp | 8 +++++++- src/Elements/OpalSource.h | 3 ++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Classic/AbsBeamline/Source.cpp b/src/Classic/AbsBeamline/Source.cpp index c270506e5..6a7a8a5b1 100644 --- a/src/Classic/AbsBeamline/Source.cpp +++ b/src/Classic/AbsBeamline/Source.cpp @@ -22,14 +22,16 @@ Source::Source(): Source::Source(const Source &right): Component(right), startField_m(right.startField_m), - endField_m(right.endField_m) + endField_m(right.endField_m), + isTransparent_m(right.isTransparent_m) {} Source::Source(const std::string &name): Component(name), startField_m(0.0), - endField_m(0.0) + endField_m(0.0), + isTransparent_m(false) {} Source::~Source() { @@ -41,6 +43,10 @@ void Source::accept(BeamlineVisitor &visitor) const { } bool Source::apply(const size_t &i, const double &t, Vector_t &/*E*/, Vector_t &/*B*/) { + if (isTransparent_m) { + return false; + } + const Vector_t &R = RefPartBunch_m->R[i]; const Vector_t &P = RefPartBunch_m->P[i]; const double &dt = RefPartBunch_m->dt[i]; @@ -94,4 +100,8 @@ void Source::getDimensions(double &zBegin, double &zEnd) const { ElementBase::ElementType Source::getType() const { return SOURCE; +} + +void Source::setTransparent() { + isTransparent_m = true; } \ No newline at end of file diff --git a/src/Classic/AbsBeamline/Source.h b/src/Classic/AbsBeamline/Source.h index 2783702d0..1e4fa1f30 100644 --- a/src/Classic/AbsBeamline/Source.h +++ b/src/Classic/AbsBeamline/Source.h @@ -39,11 +39,14 @@ public: virtual void getDimensions(double &zBegin, double &zEnd) const override; + void setTransparent(); private: double startField_m; /**< startingpoint of field, m*/ double endField_m; + bool isTransparent_m; + std::unique_ptr<LossDataSink> lossDs_m; // Not implemented. diff --git a/src/Elements/OpalSource.cpp b/src/Elements/OpalSource.cpp index e21a75f6c..e56b11580 100644 --- a/src/Elements/OpalSource.cpp +++ b/src/Elements/OpalSource.cpp @@ -26,8 +26,10 @@ OpalSource::OpalSource(): OpalElement(SIZE, "SOURCE", "The \"SOURCE\" element defines a Source.") { itsAttr[DISTRIBUTION] = Attributes::makeStringArray - ("DISTRIBUTION", "List of particle distributions to be used "); + ("DISTRIBUTION", "List of particle distributions to be used "); + itsAttr[TRANSPARENT] = Attributes::makeBool + ("TRANSPARENT", "Make the source element transparent to impacting elements; Default value is FALSE", false); registerOwnership(); setElement(new SourceRep("SOURCE")); @@ -58,6 +60,10 @@ void OpalSource::update() { sol->setElementLength(length); + if (Attributes::getBool(itsAttr[TRANSPARENT])) { + sol->setTransparent(); + } + // Transmit "unknown" attributes. OpalElement::updateUnknown(sol); } \ No newline at end of file diff --git a/src/Elements/OpalSource.h b/src/Elements/OpalSource.h index 7addfd83e..236ef3d63 100644 --- a/src/Elements/OpalSource.h +++ b/src/Elements/OpalSource.h @@ -28,6 +28,7 @@ public: /// The attributes of class OpalSource. enum { DISTRIBUTION = COMMON, // The longitudinal magnetic field. + TRANSPARENT, SIZE }; @@ -52,4 +53,4 @@ private: OpalSource(const std::string &name, OpalSource *parent); }; -#endif // OPAL_OPALSOURCE_HH +#endif // OPAL_OPALSOURCE_HH \ No newline at end of file -- GitLab