OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
OpalMultipole.cpp
Go to the documentation of this file.
1//
2// Class OpalMultipole
3// The MULTIPOLE 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//
24#include "Expressions/SValue.h"
26#include "Physics/Physics.h"
27#include "Utilities/Options.h"
28#include <iostream>
29#include <sstream>
30#include <vector>
31
33 OpalElement(SIZE, "MULTIPOLE",
34 "The \"MULTIPOLE\" element defines a thick multipole.\n"
35 "* If the length is non-zero, the strengths are per unit "
36 "length.\n* If the length is zero, the strengths are the "
37 "values integrated over the length.\n"
38 "* With zero length no synchrotron radiation can be calculated.") {
40 ("KN", "Normalised multipole strengths (normal) in m^(-k)");
42 ("DKN", "Normalised multipole strengths errors(normal) in m^(-k)");
44 ("KS", "Normalised multipole strengths (skew) in m^(-k)");
46 ("DKS", "Normalised multipole strength errors (skew) in m^(-k)");
47
49
50 setElement(new MultipoleRep("MULTIPOLE"));
51}
52
53
54OpalMultipole::OpalMultipole(const std::string &name, OpalMultipole *parent):
55 OpalElement(name, parent) {
57}
58
59
61{}
62
63
65 return new OpalMultipole(name, this);
66}
67
68
69void OpalMultipole::print(std::ostream &os) const {
71}
72
73
76
77 // Magnet length.
78 MultipoleRep *mult =
79 dynamic_cast<MultipoleRep *>(getElement());
80 double length = getLength();
81 mult->setElementLength(length);
82
83 // Field components.
84 BMultipoleField field;
85
86 const std::vector<double> norm = Attributes::getRealArray(itsAttr[KN]);
87 std::vector<double> normErrors = Attributes::getRealArray(itsAttr[DKN]);
88 const std::vector<double> skew = Attributes::getRealArray(itsAttr[KS]);
89 std::vector<double> skewErrors = Attributes::getRealArray(itsAttr[DKS]);
90 int normSize = norm.size();
91 int skewSize = skew.size();
92 normErrors.resize(normSize, 0.0);
93 skewErrors.resize(skewSize, 0.0);
94 double factor = OpalData::getInstance()->getP0() / Physics::c;
95 int top = (normSize > skewSize) ? normSize : skewSize;
96
97 for(int comp = 1; comp <= top; comp++) {
98 factor /= double(comp);
99 if(comp <= normSize) {
100 field.setNormalComponent(comp, norm[comp-1] * factor);
101 mult->setNormalComponent(comp, norm[comp-1], normErrors[comp-1]);
102 }
103 if(comp <= skewSize) {
104 field.setSkewComponent(comp, skew[comp-1] * factor);
105 mult->setSkewComponent(comp, skew[comp-1], skewErrors[comp-1]);
106 }
107 }
108
109 mult->setField(field);
110
111 // Transmit "unknown" attributes.
113}
@ SIZE
Definition: IndexMap.cpp:174
const std::string name
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:289
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:294
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:45
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:570
static OpalData * getInstance()
Definition: OpalData.cpp:196
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:418
void setNormalComponent(int, double)
Set normal component.
Definition: Multipole.h:147
void setSkewComponent(int, double)
Set skew component.
Definition: Multipole.h:152
virtual void setField(const BMultipoleField &field)
Set mulitpole field.
The magnetic field of a multipole.
void setNormalComponent(int n, double Bn)
Set component.
void setSkewComponent(int n, double Bn)
Set component.
virtual double getLength() const
Return element length.
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
virtual void print(std::ostream &) const
Print the object.
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
virtual ~OpalMultipole()
virtual OpalMultipole * clone(const std::string &name)
Make clone.
virtual void print(std::ostream &) const
Print the object.
virtual void update()
Update the embedded CLASSIC multipole.
OpalMultipole()
Exemplar constructor.