OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
OpalQuadrupole.cpp
Go to the documentation of this file.
1 //
2 // Class OpalQuadrupole
3 // The QUADRUPOLE element.
4 //
5 // Copyright (c) 200x - 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 //
20 #include "Attributes/Attributes.h"
22 #include "Fields/BMultipoleField.h"
23 #include "Physics/Physics.h"
24 #include "Utilities/Options.h"
26 
27 #include <cmath>
28 #include <iostream>
29 #include <sstream>
30 
31 
33  OpalElement(SIZE, "QUADRUPOLE",
34  "The \"QUADRUPOLE\" element defines a Quadrupole."),
35  parmatint_m(nullptr) {
37  ("K1", "Normalised upright quadrupole coefficient in m^(-2)");
39  ("DK1", "Normalised upright quadrupole coefficient error in m^(-2)");
41  ("K1S", "Normalised skew quadrupole coefficient in m^(-2)");
43  ("DK1S", "Normalised skew quadrupole coefficient error in m^(-2)");
45  ("NSLICES", "The number of slices/ steps for this element in Map Tracking", 1);
46 
48 
49  setElement((new MultipoleRep("QUADRUPOLE")));
50 }
51 
52 
53 OpalQuadrupole::OpalQuadrupole(const std::string& name, OpalQuadrupole* parent):
54  OpalElement(name, parent),
55  parmatint_m(nullptr) {
56  setElement((new MultipoleRep(name)));
57 }
58 
59 
61  delete parmatint_m;
62 }
63 
64 
66  return new OpalQuadrupole(name, this);
67 }
68 
69 
70 void OpalQuadrupole::print(std::ostream& os) const {
72 }
73 
74 
77 
78  MultipoleRep* quad =
79  dynamic_cast<MultipoleRep*>(getElement());
80 
82  double factor = OpalData::getInstance()->getP0() / Physics::c;
83 
84  BMultipoleField field;
85  field.setNormalComponent(2, factor * Attributes::getReal(itsAttr[K1])); // this is for the maps
86  field.setSkewComponent(2, factor * Attributes::getReal(itsAttr[K1S])); // this is for the maps
87  quad->setField(field);
91 
92  if (itsAttr[PARTICLEMATTERINTERACTION] && parmatint_m == nullptr) {
93  const std::string matterDescriptor = Attributes::getString(itsAttr[PARTICLEMATTERINTERACTION]);
95  parmatint_m = orig->clone(matterDescriptor);
98  }
99 
100  // Transmit "unknown" attributes.
102 }
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
static OpalData * getInstance()
Definition: OpalData.cpp:196
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:45
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
virtual void print(std::ostream &) const
Print the quadrupole.
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
void setNormalComponent(int, double)
Set normal component.
Definition: Multipole.h:147
ParticleMatterInteraction * parmatint_m
void setSkewComponent(int n, double Bn)
Set component.
virtual void setField(const BMultipoleField &field)
Set mulitpole field.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
void setNormalComponent(int n, double Bn)
Set component.
virtual void print(std::ostream &) const
Print the object.
void setNSlices(const std::size_t &nSlices)
Definition: Multipole.cpp:142
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
OpalQuadrupole()
Exemplar constructor.
void initParticleMatterInteractionHandler(ElementBase &element)
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:575
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
const std::string name
virtual void update()
Update the embedded CLASSIC multipole.
virtual ~OpalQuadrupole()
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
ParticleMatterInteractionHandler * handler_m
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:419
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
void setSkewComponent(int, double)
Set skew component.
Definition: Multipole.h:152
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
The magnetic field of a multipole.
virtual OpalQuadrupole * clone(const std::string &name)
Make clone.