OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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//
19#include <iostream>
20#include <sstream>
21#include <vector>
28#include "Expressions/SValue.h"
29#include "Physics/Physics.h"
30#include "Utilities/Options.h"
31
34 SIZE, "MULTIPOLE",
35 "The \"MULTIPOLE\" element defines a thick multipole.\n"
36 "* If the length is non-zero, the strengths are per unit "
37 "length.\n* If the length is zero, the strengths are the "
38 "values integrated over the length.\n"
39 "* With zero length no synchrotron radiation can be calculated.") {
40 itsAttr[KN] =
41 Attributes::makeRealArray("KN", "Normalised multipole strengths (normal) in m^(-k)");
43 "DKN", "Normalised multipole strengths errors(normal) in m^(-k)");
44 itsAttr[KS] =
45 Attributes::makeRealArray("KS", "Normalised multipole strengths (skew) in m^(-k)");
47 "DKS", "Normalised multipole strength errors (skew) in m^(-k)");
48
50
51 setElement(new MultipoleRep("MULTIPOLE"));
52}
53
54OpalMultipole::OpalMultipole(const std::string& name, OpalMultipole* parent)
55 : OpalElement(name, parent) {
56 setElement(new MultipoleRep(name));
57}
58
60
61OpalMultipole* OpalMultipole::clone(const std::string& name) {
62 return new OpalMultipole(name, this);
63}
64
65void OpalMultipole::print(std::ostream& os) const { OpalElement::print(os); }
66
69
70 // Get pointer to MultipoleRep object to set length
71 MultipoleRep* mult = dynamic_cast<MultipoleRep*>(getElement());
72 double length = getLength();
73 mult->setElementLength(length);
74
75 // Multipole field for MultipoleRep
76 BMultipoleField field;
77
78 // Get the vector with the multipole expansion components
79 const std::vector<double> norm = Attributes::getRealArray(itsAttr[KN]);
80 std::vector<double> normErrors = Attributes::getRealArray(itsAttr[DKN]);
81 const std::vector<double> skew = Attributes::getRealArray(itsAttr[KS]);
82 std::vector<double> skewErrors = Attributes::getRealArray(itsAttr[DKS]);
83
84 // Resize error arrays
85 unsigned int normSize = norm.size();
86 unsigned int skewSize = skew.size();
87 normErrors.resize(normSize, 0.0);
88 skewErrors.resize(skewSize, 0.0);
89
90 double factor = OpalData::getInstance()->getP0() / Physics::c;
91 unsigned int top = (normSize > skewSize) ? normSize : skewSize;
92
93 // Loop over components (0=Dipole, 1=Quadrupole, ...)
94 for (unsigned int comp = 0; comp < top; ++comp) {
95 factor /= double(comp + 1);
96 if (comp < normSize) {
97 field.setNormalComponent(comp, norm[comp] * factor);
98 mult->setNormalComponent(comp, norm[comp], normErrors[comp]);
99 }
100 if (comp < skewSize) {
101 field.setSkewComponent(comp, skew[comp] * factor);
102 mult->setSkewComponent(comp, skew[comp], skewErrors[comp]);
103 }
104 }
105
106 mult->setField(field);
107
108 // Transmit "unknown" attributes.
110}
@ 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 ~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 OPALX multipole.
OpalMultipole()
Exemplar constructor.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
constexpr double c
The velocity of light in m/s.
Definition Physics.h:60