OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
OpalQuadrupole.cpp
Go to the documentation of this file.
1//
2// Class OpalQuadrupole
3// The QUADRUPOLE element.
4//
5// A convenience wrapper around MULTIPOLE that accepts a single
6// quadrupole strength K1 instead of the full KN vector.
7// Internally the element is represented as a MultipoleRep with
8// KN = {0, K1}.
9//
10// Copyright (c) 2024 – 2026, Paul Scherrer Institut, Villigen PSI, Switzerland
11// All rights reserved
12//
13// This file is part of OPAL.
14//
15// OPAL is free software: you can redistribute it and/or modify
16// it under the terms of the GNU General Public License as published by
17// the Free Software Foundation, either version 3 of the License, or
18// (at your option) any later version.
19//
20// You should have received a copy of the GNU General Public License
21// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
22//
28#include "Physics/Physics.h"
29
32 SIZE, "QUADRUPOLE",
33 "The \"QUADRUPOLE\" element defines a thick quadrupole.\n"
34 "It is a convenience wrapper around MULTIPOLE with a single\n"
35 "quadrupole strength K1.\n"
36 "* If the length is non-zero, K1 is per unit length.\n"
37 "* If the length is zero, K1 is the integrated strength.") {
38 itsAttr[K1] = Attributes::makeReal("K1", "Normalised quadrupole strength in m^(-2)", 0.0);
39 itsAttr[DK1] =
40 Attributes::makeReal("DK1", "Normalised quadrupole strength error in m^(-2)", 0.0);
41 itsAttr[K1S] =
42 Attributes::makeReal("K1S", "Normalised skew quadrupole strength in m^(-2)", 0.0);
44 "DK1S", "Normalised skew quadrupole strength error in m^(-2)", 0.0);
45
47
48 setElement(new MultipoleRep("QUADRUPOLE"));
49}
50
51OpalQuadrupole::OpalQuadrupole(const std::string& name, OpalQuadrupole* parent)
52 : OpalElement(name, parent) {
53 setElement(new MultipoleRep(name));
54}
55
57
58OpalQuadrupole* OpalQuadrupole::clone(const std::string& name) {
59 return new OpalQuadrupole(name, this);
60}
61
62void OpalQuadrupole::print(std::ostream& os) const { OpalElement::print(os); }
63
66
67 MultipoleRep* mult = dynamic_cast<MultipoleRep*>(getElement());
68 double length = getLength();
69 mult->setElementLength(length);
70
71 // Build a multipole field from the scalar K1 / K1S values.
72 // The KN vector convention is: index 0 = dipole, index 1 = quadrupole, ...
73 BMultipoleField field;
74
75 double k1 = Attributes::getReal(itsAttr[K1]);
76 double dk1 = Attributes::getReal(itsAttr[DK1]);
77 double k1s = Attributes::getReal(itsAttr[K1S]);
78 double dk1s = Attributes::getReal(itsAttr[DK1S]);
79
80 double factor = OpalData::getInstance()->getP0() / Physics::c;
81
82 // comp 0 (dipole): strength = 0, factor /= 1
83 factor /= 1.0; // comp 0
84 field.setNormalComponent(0, 0.0);
85 mult->setNormalComponent(0, 0.0, 0.0);
86 field.setSkewComponent(0, 0.0);
87 mult->setSkewComponent(0, 0.0, 0.0);
88
89 // comp 1 (quadrupole): factor /= 2
90 factor /= 2.0;
91 field.setNormalComponent(1, k1 * factor);
92 mult->setNormalComponent(1, k1, dk1);
93 field.setSkewComponent(1, k1s * factor);
94 mult->setSkewComponent(1, k1s, dk1s);
95
96 mult->setField(field);
97
98 // Transmit "unknown" attributes.
100}
@ SIZE
Definition IndexMap.cpp:179
The magnetic field of a multipole.
void setNormalComponent(int n, double Bn)
Set component.
void setSkewComponent(int n, double Bn)
Set component.
virtual void setElementLength(double length)
Set design length.
ElementBase * getElement() const
Return the embedded OPALX element.
Definition Element.h:119
void setElement(ElementBase *)
Assign new OPALX element.
Definition Element.h:123
virtual void setField(const BMultipoleField &field)
Set mulitpole field.
void setSkewComponent(int n, double)
Definition Multipole.h:216
void setNormalComponent(int n, double)
Definition Multipole.h:214
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
double getP0() const
Return value of global reference momentum.
Definition OpalData.cpp:479
static OpalData * getInstance()
Definition OpalData.cpp:193
virtual double getLength() const
Return element length.
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPALX) attributes to OPALX.
virtual void print(std::ostream &) const
Print the object.
virtual void update()
Update the embedded OPALX element.
void registerOwnership() const
virtual void print(std::ostream &) const
Print the object.
virtual ~OpalQuadrupole()
virtual OpalQuadrupole * clone(const std::string &name)
Make clone.
OpalQuadrupole()
Exemplar constructor.
virtual void update()
Update the embedded OPALX multipole.
double getReal(const Attribute &attr)
Return real value.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
constexpr double c
The velocity of light in m/s.
Definition Physics.h:60