32 #include <boost/regex.hpp>
43 (
"TYPE",
"The element design type.",
57 (
"L",
"The element length in m");
60 (
"ELEMEDGE",
"The position of the element in path length (in m)");
63 (
"APERTURE",
"The element aperture");
66 (
"WAKEF",
"Defines the wake function");
69 (
"PARTICLEMATTERINTERACTION",
"Defines the particle mater interaction handler");
72 (
"ORIGIN",
"The location of the element");
75 (
"ORIENTATION",
"The Tait-Bryan angles for the orientation of the element");
78 (
"X",
"The x-coordinate of the location of the element", 0);
81 (
"Y",
"The y-coordinate of the location of the element", 0);
84 (
"Z",
"The z-coordinate of the location of the element", 0);
87 (
"THETA",
"The rotation about the y-axis of the element", 0);
90 (
"PHI",
"The rotation about the x-axis of the element", 0);
93 (
"PSI",
"The rotation about the z-axis of the element", 0);
96 (
"DX",
"Misalignment in x direction",0.0);
99 (
"DY",
"Misalignment in y direction",0.0);
102 (
"DZ",
"Misalignment in z direction",0.0);
105 (
"DTHETA",
"Misalignment in theta (Tait-Bryan angles)",0.0);
108 (
"DPHI",
"Misalignment in theta (Tait-Bryan angles)",0.0);
111 (
"DPSI",
"Misalignment in theta (Tait-Bryan angles)",0.0);
114 (
"OUTFN",
"Output filename");
117 for (
unsigned int i = 0; i <
end; ++ i) {
135 std::vector<double>({0.5, 0.5, 1.0}));
140 boost::regex square(
"square *\\((.*)\\)", boost::regex::icase);
141 boost::regex rectangle(
"rectangle *\\((.*)\\)", boost::regex::icase);
142 boost::regex circle(
"circle *\\((.*)\\)", boost::regex::icase);
143 boost::regex ellipse(
"ellipse *\\((.*)\\)", boost::regex::icase);
145 boost::regex twoArguments(
"([^,]*),([^,]*)");
146 boost::regex threeArguments(
"([^,]*),([^,]*),([^,]*)");
150 const double width2HalfWidth = 0.5;
152 if (boost::regex_search(aperture, match, square)) {
153 std::string arguments = match[1];
154 if (!boost::regex_search(arguments, match, twoArguments)) {
158 retvalue.second[0] = width2HalfWidth * std::stod(arguments);
159 retvalue.second[1] = retvalue.second[0];
160 }
catch (
const std::exception &ex) {
162 "could not convert '" + arguments +
"' to double");
169 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
170 retvalue.second[1] = retvalue.second[0];
171 retvalue.second[2] = std::stod(match[2]);
172 }
catch (
const std::exception &ex) {
174 "could not convert '" + arguments +
"' to doubles");
181 if (boost::regex_search(aperture, match, rectangle)) {
182 std::string arguments = match[1];
184 if (!boost::regex_search(arguments, match, threeArguments)) {
190 retvalue.second[0] = width2HalfWidth * std::stod(arguments, &sz);
191 sz = arguments.find_first_of(
",", sz) + 1;
192 retvalue.second[1] = width2HalfWidth * std::stod(arguments.substr(sz));
194 }
catch (
const std::exception &ex) {
196 "could not convert '" + arguments +
"' to doubles");
203 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
204 retvalue.second[1] = width2HalfWidth * std::stod(match[2]);
205 retvalue.second[2] = std::stod(match[3]);
206 }
catch (
const std::exception &ex) {
208 "could not convert '" + arguments +
"' to doubles");
215 if (boost::regex_search(aperture, match, circle)) {
216 std::string arguments = match[1];
217 if (!boost::regex_search(arguments, match, twoArguments)) {
221 retvalue.second[0] = width2HalfWidth * std::stod(arguments);
222 retvalue.second[1] = retvalue.second[0];
223 }
catch (
const std::exception &ex) {
225 "could not convert '" + arguments +
"' to double");
232 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
233 retvalue.second[1] = retvalue.second[0];
234 retvalue.second[2] = std::stod(match[2]);
235 }
catch (
const std::exception &ex) {
237 "could not convert '" + arguments +
"' to doubles");
244 if (boost::regex_search(aperture, match, ellipse)) {
245 std::string arguments = match[1];
247 if (!boost::regex_search(arguments, match, threeArguments)) {
253 retvalue.second[0] = width2HalfWidth * std::stod(arguments, &sz);
254 sz = arguments.find_first_of(
",", sz) + 1;
255 retvalue.second[1] = width2HalfWidth * std::stod(arguments.substr(sz));
257 }
catch (
const std::exception &ex) {
259 "could not convert '" + arguments +
"' to doubles");
266 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
267 retvalue.second[1] = width2HalfWidth * std::stod(match[2]);
268 retvalue.second[2] = std::stod(match[3]);
269 }
catch (
const std::exception &ex) {
271 "could not convert '" + arguments +
"' to doubles");
280 "Unknown aperture type '" + aperture +
"'.");
315 "unknown attribute \"" +
name +
"\"");
328 "Delimiter \"=\" or \":=\" expected.");
332 attr->
parse(stat,
true);
334 attr->
parse(stat,
false);
347 if (parent != 0 && ! parent->
getOpalName().empty()) {
360 const std::string& sName,
361 const std::string& tName,
384 int div = 2 * (order + 1);
396 std::string normImage = sNorm.
getImage();
398 normImage =
"(" + normImage +
")*(" + length.
getImage() +
")";
408 std::string skewImage = sSkew.
getImage();
410 skewImage =
"(" + skewImage +
")*(" + length.
getImage() +
")";
423 double strength =
std::sqrt(sn * sn + ss * ss);
425 std::ostringstream ts;
427 std::string image = ts.str();
429 image =
"(" + image +
")*(" + length.
getImage() +
")";
432 double tilt = -
std::atan2(ss, sn) / double(div);
443 std::string normImage = sNorm.
getImage();
444 std::string skewImage = sSkew.
getImage();
446 "SQRT((" + normImage +
")^2+(" + skewImage +
")^2)";
449 image =
"(" + image +
")*(" + length.
getImage() +
")";
457 divisor[0] += div / 10;
458 divisor[1] += div % 10;
460 image =
"-ATAN2(" + skewImage +
',' + normImage +
")/" + divisor;
479 if (dir.size() == 3) {
483 rotation = rotTheta * (rotPhi * rotPsi);
487 "Parameter orientation is array of 3 values (theta, phi, psi);\n" +
488 std::to_string(dir.size()) +
" values provided");
492 if (ori.size() == 3) {
493 origin =
Vector_t(ori[0], ori[1], ori[2]);
497 "Parameter origin is array of 3 values (x, y, z);\n" +
498 std::to_string(ori.size()) +
" values provided");
514 }
else if (!
itsAttr[
X].defaultUsed() ||
531 Quaternion rotation = rotTheta * (rotPhi * rotPsi);
549 Quaternion misalignmentRotation = rotationY * rotationX * rotationZ;
560 for (std::vector<Attribute>::size_type i =
itsSize;
569 const std::string& image,
int& len) {
570 len +=
name.length() + image.length() + 2;
573 len =
name.length() + image.length() + 3;
577 os <<
name <<
'=' << image;
581 (std::ostream &os,
const std::string &
name,
double value,
int &len) {
582 std::ostringstream ss;
583 ss << value << std::ends;
593 for (
unsigned int i =
COMMON; i <
end; ++ i) {
Tps< T > cos(const Tps< T > &x)
Cosine.
Tps< T > sin(const Tps< T > &x)
Sine.
Tps< T > sqrt(const Tps< T > &x)
Square root.
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
Inform & endl(Inform &inf)
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.
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.
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 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.
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.
std::pair< ElementBase::ApertureType, std::vector< double > > getApert() const
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