44 (
"TYPE",
"The element design type.",
58 (
"L",
"The element length [m]");
61 (
"ELEMEDGE",
"The position of the element in path length [m]");
64 (
"APERTURE",
"The element aperture");
67 (
"WAKEF",
"Defines the wake function");
70 (
"PARTICLEMATTERINTERACTION",
"Defines the particle mater interaction handler");
73 (
"ORIGIN",
"The location of the element");
76 (
"ORIENTATION",
"The Tait-Bryan angles for the orientation of the element");
79 (
"X",
"The x-coordinate of the location of the element", 0);
82 (
"Y",
"The y-coordinate of the location of the element", 0);
85 (
"Z",
"The z-coordinate of the location of the element", 0);
88 (
"THETA",
"The rotation about the y-axis of the element", 0);
91 (
"PHI",
"The rotation about the x-axis of the element", 0);
94 (
"PSI",
"The rotation about the z-axis of the element", 0);
97 (
"DX",
"Misalignment in x direction", 0.0);
100 (
"DY",
"Misalignment in y direction", 0.0);
103 (
"DZ",
"Misalignment in z direction", 0.0);
106 (
"DTHETA",
"Misalignment in theta (Tait-Bryan angles)", 0.0);
109 (
"DPHI",
"Misalignment in theta (Tait-Bryan angles)", 0.0);
112 (
"DPSI",
"Misalignment in theta (Tait-Bryan angles)", 0.0);
115 (
"OUTFN",
"Output filename");
118 (
"DELETEONTRANSVERSEEXIT",
"Flag controlling if particles should be deleted if they exit "
119 "the element transversally. Default=TRUE",
true);
122 for (
unsigned int i = 0; i <
end; ++ i) {
140 std::vector<double>({0.5, 0.5, 1.0}));
145 std::regex square(
"square *\\((.*)\\)", std::regex::icase);
146 std::regex rectangle(
"rectangle *\\((.*)\\)", std::regex::icase);
147 std::regex circle(
"circle *\\((.*)\\)", std::regex::icase);
148 std::regex ellipse(
"ellipse *\\((.*)\\)", std::regex::icase);
150 std::regex twoArguments(
"([^,]*),([^,]*)");
151 std::regex threeArguments(
"([^,]*),([^,]*),([^,]*)");
155 const double width2HalfWidth = 0.5;
157 if (std::regex_search(aperture, match, square)) {
158 std::string arguments = match[1];
159 if (!std::regex_search(arguments, match, twoArguments)) {
163 retvalue.second[0] = width2HalfWidth * std::stod(arguments);
164 retvalue.second[1] = retvalue.second[0];
165 }
catch (
const std::exception &ex) {
167 "could not convert '" + arguments +
"' to double");
174 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
175 retvalue.second[1] = retvalue.second[0];
176 retvalue.second[2] = std::stod(match[2]);
177 }
catch (
const std::exception &ex) {
179 "could not convert '" + arguments +
"' to doubles");
186 if (std::regex_search(aperture, match, rectangle)) {
187 std::string arguments = match[1];
189 if (!std::regex_search(arguments, match, threeArguments)) {
195 retvalue.second[0] = width2HalfWidth * std::stod(arguments, &sz);
196 sz = arguments.find_first_of(
",", sz) + 1;
197 retvalue.second[1] = width2HalfWidth * std::stod(arguments.substr(sz));
199 }
catch (
const std::exception &ex) {
201 "could not convert '" + arguments +
"' to doubles");
208 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
209 retvalue.second[1] = width2HalfWidth * std::stod(match[2]);
210 retvalue.second[2] = std::stod(match[3]);
211 }
catch (
const std::exception &ex) {
213 "could not convert '" + arguments +
"' to doubles");
220 if (std::regex_search(aperture, match, circle)) {
221 std::string arguments = match[1];
222 if (!std::regex_search(arguments, match, twoArguments)) {
226 retvalue.second[0] = width2HalfWidth * std::stod(arguments);
227 retvalue.second[1] = retvalue.second[0];
228 }
catch (
const std::exception &ex) {
230 "could not convert '" + arguments +
"' to double");
237 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
238 retvalue.second[1] = retvalue.second[0];
239 retvalue.second[2] = std::stod(match[2]);
240 }
catch (
const std::exception &ex) {
242 "could not convert '" + arguments +
"' to doubles");
249 if (std::regex_search(aperture, match, ellipse)) {
250 std::string arguments = match[1];
252 if (!std::regex_search(arguments, match, threeArguments)) {
258 retvalue.second[0] = width2HalfWidth * std::stod(arguments, &sz);
259 sz = arguments.find_first_of(
",", sz) + 1;
260 retvalue.second[1] = width2HalfWidth * std::stod(arguments.substr(sz));
262 }
catch (
const std::exception &ex) {
264 "could not convert '" + arguments +
"' to doubles");
271 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
272 retvalue.second[1] = width2HalfWidth * std::stod(match[2]);
273 retvalue.second[2] = std::stod(match[3]);
274 }
catch (
const std::exception &ex) {
276 "could not convert '" + arguments +
"' to doubles");
283 if (!aperture.empty()) {
285 "Unknown aperture type '" + aperture +
"'.");
321 "unknown attribute \"" +
name +
"\"");
334 "Delimiter \"=\" or \":=\" expected.");
338 attr->
parse(stat,
true);
340 attr->
parse(stat,
false);
353 if (parent != 0 && ! parent->
getOpalName().empty()) {
366 const std::string& sName,
367 const std::string& tName,
390 int div = 2 * (order + 1);
402 std::string normImage = sNorm.
getImage();
404 normImage =
"(" + normImage +
")*(" + length.
getImage() +
")";
414 std::string skewImage = sSkew.
getImage();
416 skewImage =
"(" + skewImage +
")*(" + length.
getImage() +
")";
429 double strength = std::sqrt(sn * sn + ss * ss);
431 std::ostringstream ts;
433 std::string image = ts.str();
435 image =
"(" + image +
")*(" + length.
getImage() +
")";
438 double tilt = - std::atan2(ss, sn) / double(div);
449 std::string normImage = sNorm.
getImage();
450 std::string skewImage = sSkew.
getImage();
452 "SQRT((" + normImage +
")^2+(" + skewImage +
")^2)";
455 image =
"(" + image +
")*(" + length.
getImage() +
")";
463 divisor[0] += div / 10;
464 divisor[1] += div % 10;
466 image =
"-ATAN2(" + skewImage +
',' + normImage +
")/" + divisor;
485 if (dir.size() == 3) {
486 Quaternion rotTheta(std::cos(0.5 * dir[0]), 0, std::sin(0.5 * dir[0]), 0);
487 Quaternion rotPhi(std::cos(0.5 * dir[1]), std::sin(0.5 * dir[1]), 0, 0);
488 Quaternion rotPsi(std::cos(0.5 * dir[2]), 0, 0, std::sin(0.5 * dir[2]));
489 rotation = rotTheta * (rotPhi * rotPsi);
493 "Parameter orientation is array of 3 values (theta, phi, psi);\n" +
494 std::to_string(dir.size()) +
" values provided");
498 if (ori.size() == 3) {
499 origin =
Vector_t({ori[0], ori[1], ori[2]});
503 "Parameter origin is array of 3 values (x, y, z);\n" +
504 std::to_string(ori.size()) +
" values provided");
520 }
else if (!
itsAttr[
X].defaultUsed() ||
534 Quaternion rotTheta(std::cos(0.5 * theta), 0, std::sin(0.5 * theta), 0);
535 Quaternion rotPhi(std::cos(0.5 * phi), std::sin(0.5 * phi), 0, 0);
536 Quaternion rotPsi(std::cos(0.5 * psi), 0, 0, std::sin(0.5 * psi));
537 Quaternion rotation = rotTheta * (rotPhi * rotPsi);
552 Quaternion rotationY(std::cos(0.5 * dtheta), 0, std::sin(0.5 * dtheta), 0);
553 Quaternion rotationX(std::cos(0.5 * dphi), std::sin(0.5 * dphi), 0, 0);
554 Quaternion rotationZ(std::cos(0.5 * dpsi), 0, 0, std::sin(0.5 * dpsi));
555 Quaternion misalignmentRotation = rotationY * rotationX * rotationZ;
568 for (std::vector<Attribute>::size_type i =
itsSize;
577 const std::string& image,
int& len) {
578 len +=
name.length() + image.length() + 2;
581 len =
name.length() + image.length() + 3;
585 os <<
name <<
'=' << image;
589(std::ostream &os,
const std::string &
name,
double value,
int &len) {
590 std::ostringstream ss;
591 ss << value << std::ends;
601 for (
unsigned int i =
COMMON; i <
end; ++ i) {
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
std::string parseString(Statement &, const char msg[])
Parse string value.
void parseDelimiter(Statement &stat, char delim)
Test for one-character delimiter.
double parseRealConst(Statement &)
Parse real constant.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
double getReal(const Attribute &attr)
Return real value.
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
bool getBool(const Attribute &attr)
Return logical value.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
constexpr double pi
The value of.
A representation of an Object attribute.
AttributeBase & getBase() const
Return reference to polymorphic value.
const std::string & getName() const
Return the attribute name.
void setDefault()
Assign default value.
void parse(Statement &stat, bool eval)
Parse attribute.
void parseComponent(Statement &stat, bool eval, int index)
Parse array component.
std::string getImage() const
Return printable representation.
virtual bool isExpression() const
Test for expression.
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name)
ElementBase * getElement() const
Return the embedded CLASSIC element.
The base class for all OPAL objects.
Object * getParent() const
Return parent pointer.
const std::string & getOpalName() const
Return object name.
virtual Attribute * findAttribute(const std::string &name)
Find an attribute by name.
std::vector< Attribute > itsAttr
The object attributes.
void setElementPosition(double elemedge)
Access to ELEMEDGE attribute.
void setAperture(const ApertureType &type, const std::vector< double > &args)
void setMisalignment(const CoordinateSystemTrafo &cst)
virtual void setAttribute(const std::string &aKey, double val)
Set value of an attribute.
void setFlagDeleteOnTransverseExit(bool=true)
void setRotationAboutZ(double rotation)
Set rotation about z axis in bend frame.
void setCSTrafoGlobal2Local(const CoordinateSystemTrafo &ori)
Quaternion conjugate() const
Interface for statements.
bool delimiter(char c)
Test for delimiter.
std::pair< ApertureType, std::vector< double > > getApert() const
static void printMultipoleStrength(std::ostream &os, int order, int &len, const std::string &sName, const std::string &tName, const Attribute &length, const Attribute &vNorm, const Attribute &vSkew)
Print multipole components in OPAL-8 format.
virtual double getLength() const
Return element length.
static void printAttribute(std::ostream &os, const std::string &name, const std::string &image, int &len)
Print an attribute with a OPAL-8 name (as an expression).
@ PARTICLEMATTERINTERACTION
virtual void parse(Statement &)
Parse the element.
const std::string getParticleMatterInteraction() const
const std::string getWakeF() const
Return the element's type name.
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
const std::string getTypeName() const
Return the element's type name.
virtual void print(std::ostream &) const
Print the object.
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
The base class for all OPAL exceptions.
Vektor< double, 3 > Vector_t