OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Septum.cpp
Go to the documentation of this file.
1 //
2 // Class Septum
3 // Interface for a septum magnet
4 //
5 // Copyright (c) 2016-2020, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 #include "AbsBeamline/Septum.h"
19 
22 #include "Physics/Physics.h"
23 #include "Structure/LossDataSink.h"
24 
25 extern Inform *gmsg;
26 
28 {}
29 
30 Septum::Septum(const std::string &name):
32  width_m(0.0) {
33 }
34 
35 Septum::Septum(const Septum &right):
36  PluginElement(right),
37  width_m(right.width_m) {
39 }
40 
42 
43 void Septum::accept(BeamlineVisitor &visitor) const {
44  visitor.visitSeptum(*this);
45 }
46 
47 void Septum::initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) {
48  endField = startField + 0.005;
49  startField -= 0.005;
50  initialise(bunch);
51 }
52 
54  *gmsg << "Septum initialise" << endl;
55 }
56 
57 double Septum::getWidth() const {
58  return width_m;
59 }
60 
61 void Septum::setWidth(double width) {
62  width_m = width;
64 }
65 
67  Vector_t rmin;
68  Vector_t rmax;
69  bunch->get_bounds(rmin, rmax);
70  // interested in absolute maximum
71  double xmax = std::max(std::abs(rmin(0)), std::abs(rmax(0)));
72  double ymax = std::max(std::abs(rmin(1)), std::abs(rmax(1)));
73  double rbunch_max = std::hypot(xmax, ymax);
74 
75  if (rbunch_max > rstart_m - 0.1) {
76  return true;
77  }
78  return false;
79 }
80 
81 bool Septum::doCheck(PartBunchBase<double, 3> *bunch, const int turnnumber, const double t, const double /*tstep*/) {
82 
83  bool flag = false;
84  const double slope = (yend_m - ystart_m) / (xend_m - xstart_m);
85  const double halfLength = width_m / 2.0 * std::hypot(slope, 1);
86  const double intcept = ystart_m - slope * xstart_m;
87  const double intcept1 = intcept - halfLength;
88  const double intcept2 = intcept + halfLength;
89 
90  for (unsigned int i = 0; i < bunch->getLocalNum(); ++i) {
91  const Vector_t& R = bunch->R[i];
92 
93  double line1 = std::abs(slope * R(0) + intcept1);
94  double line2 = std::abs(slope * R(0) + intcept2);
95 
96  if (std::abs(R(1)) > line2 &&
97  std::abs(R(1)) < line1 &&
98  R(0) > xstart_m &&
99  R(0) < xend_m &&
100  R(1) > ystart_m &&
101  R(1) < yend_m) {
102 
103  lossDs_m->addParticle(OpalParticle(bunch->ID[i],
104  R, bunch->P[i],
105  t, bunch->Q[i], bunch->M[i]),
106  std::make_pair(turnnumber, bunch->bunchNum[i]));
107  bunch->Bin[i] = -1;
108  flag = true;
109  }
110  }
111  return flag;
112 }
113 
115  return SEPTUM;
116 }
Inform * gmsg
Definition: Main.cpp:62
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
const std::string name
ParticlePos_t & R
ParticleAttrib< int > Bin
size_t getLocalNum() const
ParticleAttrib< double > M
ParticleAttrib< Vector_t > P
ParticleAttrib< double > Q
void get_bounds(Vector_t &rmin, Vector_t &rmax)
ParticleAttrib< short > bunchNum
ParticleIndex_t & ID
virtual void visitSeptum(const Septum &)=0
Apply the algorithm to a septum magnet.
void setGeom(const double dist)
Sets geometry geom_m with element width dist.
double xstart_m
input geometry positions
std::unique_ptr< LossDataSink > lossDs_m
Pointer to Loss instance.
Definition: Septum.h:23
virtual bool doCheck(PartBunchBase< double, 3 > *bunch, const int turnnumber, const double t, const double tstep) override
Record hits when bunch particles pass.
Definition: Septum.cpp:81
virtual ~Septum()
Definition: Septum.cpp:41
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
virtual bool doPreCheck(PartBunchBase< double, 3 > *) override
Virtual hook for preCheck.
Definition: Septum.cpp:66
double width_m
input geometry positions
Definition: Septum.h:57
void setWidth(double width)
Member variable access.
Definition: Septum.cpp:61
virtual ElementBase::ElementType getType() const override
Override implementation of PluginElement.
Definition: Septum.cpp:114
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Septum.
Definition: Septum.cpp:43
Septum()
Definition: Septum.cpp:27
virtual void doInitialise(PartBunchBase< double, 3 > *bunch) override
Hook for initialise.
Definition: Septum.cpp:53
double getWidth() const
Definition: Septum.cpp:57
Definition: Inform.h:42