32 #include <boost/regex.hpp>
41 Element(size, name, help), itsSize(size) {
43 (
"TYPE",
"The element design type.",
57 (
"L",
"The element length [m]");
60 (
"ELEMEDGE",
"The position of the element in path length [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 (
"DELETEONTRANSVERSEEXIT",
"Flag controlling if particles should be deleted if they exit "
118 "the element transversally. Default=TRUE",
true);
121 for (
unsigned int i = 0; i <
end; ++ i) {
128 Element(name, parent), itsSize(parent->itsSize)
139 std::vector<double>({0.5, 0.5, 1.0}));
144 boost::regex square(
"square *\\((.*)\\)", boost::regex::icase);
145 boost::regex rectangle(
"rectangle *\\((.*)\\)", boost::regex::icase);
146 boost::regex circle(
"circle *\\((.*)\\)", boost::regex::icase);
147 boost::regex ellipse(
"ellipse *\\((.*)\\)", boost::regex::icase);
149 boost::regex twoArguments(
"([^,]*),([^,]*)");
150 boost::regex threeArguments(
"([^,]*),([^,]*),([^,]*)");
154 const double width2HalfWidth = 0.5;
156 if (boost::regex_search(aperture, match, square)) {
157 std::string arguments = match[1];
158 if (!boost::regex_search(arguments, match, twoArguments)) {
162 retvalue.second[0] = width2HalfWidth * std::stod(arguments);
163 retvalue.second[1] = retvalue.second[0];
166 "could not convert '" + arguments +
"' to double");
173 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
174 retvalue.second[1] = retvalue.second[0];
175 retvalue.second[2] = std::stod(match[2]);
178 "could not convert '" + arguments +
"' to doubles");
185 if (boost::regex_search(aperture, match, rectangle)) {
186 std::string arguments = match[1];
188 if (!boost::regex_search(arguments, match, threeArguments)) {
194 retvalue.second[0] = width2HalfWidth * std::stod(arguments, &sz);
195 sz = arguments.find_first_of(
",", sz) + 1;
196 retvalue.second[1] = width2HalfWidth * std::stod(arguments.substr(sz));
200 "could not convert '" + arguments +
"' to doubles");
207 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
208 retvalue.second[1] = width2HalfWidth * std::stod(match[2]);
209 retvalue.second[2] = std::stod(match[3]);
212 "could not convert '" + arguments +
"' to doubles");
219 if (boost::regex_search(aperture, match, circle)) {
220 std::string arguments = match[1];
221 if (!boost::regex_search(arguments, match, twoArguments)) {
225 retvalue.second[0] = width2HalfWidth * std::stod(arguments);
226 retvalue.second[1] = retvalue.second[0];
229 "could not convert '" + arguments +
"' to double");
236 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
237 retvalue.second[1] = retvalue.second[0];
238 retvalue.second[2] = std::stod(match[2]);
241 "could not convert '" + arguments +
"' to doubles");
248 if (boost::regex_search(aperture, match, ellipse)) {
249 std::string arguments = match[1];
251 if (!boost::regex_search(arguments, match, threeArguments)) {
257 retvalue.second[0] = width2HalfWidth * std::stod(arguments, &sz);
258 sz = arguments.find_first_of(
",", sz) + 1;
259 retvalue.second[1] = width2HalfWidth * std::stod(arguments.substr(sz));
263 "could not convert '" + arguments +
"' to doubles");
270 retvalue.second[0] = width2HalfWidth * std::stod(match[1]);
271 retvalue.second[1] = width2HalfWidth * std::stod(match[2]);
272 retvalue.second[2] = std::stod(match[3]);
275 "could not convert '" + arguments +
"' to doubles");
282 if (!aperture.empty()) {
284 "Unknown aperture type '" + aperture +
"'.");
320 "unknown attribute \"" + name +
"\"");
333 "Delimiter \"=\" or \":=\" expected.");
337 attr->
parse(stat,
true);
339 attr->
parse(stat,
false);
352 if (parent != 0 && ! parent->
getOpalName().empty()) {
365 const std::string& sName,
366 const std::string& tName,
389 int div = 2 * (order + 1);
401 std::string normImage = sNorm.
getImage();
403 normImage =
"(" + normImage +
")*(" + length.
getImage() +
")";
413 std::string skewImage = sSkew.
getImage();
415 skewImage =
"(" + skewImage +
")*(" + length.
getImage() +
")";
428 double strength =
std::sqrt(sn * sn + ss * ss);
430 std::ostringstream ts;
432 std::string image = ts.str();
434 image =
"(" + image +
")*(" + length.
getImage() +
")";
437 double tilt = -
std::atan2(ss, sn) / double(div);
448 std::string normImage = sNorm.
getImage();
449 std::string skewImage = sSkew.
getImage();
451 "SQRT((" + normImage +
")^2+(" + skewImage +
")^2)";
454 image =
"(" + image +
")*(" + length.
getImage() +
")";
462 divisor[0] += div / 10;
463 divisor[1] += div % 10;
465 image =
"-ATAN2(" + skewImage +
',' + normImage +
")/" + divisor;
484 if (dir.size() == 3) {
488 rotation = rotTheta * (rotPhi * rotPsi);
492 "Parameter orientation is array of 3 values (theta, phi, psi);\n" +
493 std::to_string(dir.size()) +
" values provided");
497 if (ori.size() == 3) {
498 origin =
Vector_t(ori[0], ori[1], ori[2]);
502 "Parameter origin is array of 3 values (x, y, z);\n" +
503 std::to_string(ori.size()) +
" values provided");
519 }
else if (!
itsAttr[
X].defaultUsed() ||
536 Quaternion rotation = rotTheta * (rotPhi * rotPsi);
554 Quaternion misalignmentRotation = rotationY * rotationX * rotationZ;
567 for (std::vector<Attribute>::size_type i =
itsSize;
576 const std::string& image,
int& len) {
577 len += name.length() + image.length() + 2;
580 len = name.length() + image.length() + 3;
584 os << name <<
'=' << image;
588 (std::ostream &os,
const std::string &
name,
double value,
int &len) {
589 std::ostringstream ss;
590 ss << value << std::ends;
591 printAttribute(os, name, ss.str(), len);
600 for (
unsigned int i =
COMMON; i <
end; ++ i) {
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Tps< T > sqrt(const Tps< T > &x)
Square root.
Quaternion conjugate() const
void parseComponent(Statement &stat, bool eval, int index)
Parse array component.
The base class for all OPAL objects.
std::string getString(const Attribute &attr)
Get string value.
void parseDelimiter(Statement &stat, char delim)
Test for one-character delimiter.
void setCSTrafoGlobal2Local(const CoordinateSystemTrafo &ori)
std::pair< ApertureType, std::vector< double > > getApert() const
Vektor< double, 3 > Vector_t
virtual void print(std::ostream &) const
Print the object.
const std::string & getName() const
Return the attribute name.
std::string getImage() const
Return printable representation.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
constexpr double pi
The value of .
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Inform & endl(Inform &inf)
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
virtual void setAttribute(const std::string &aKey, double val)
Set value of an attribute.
void setFlagDeleteOnTransverseExit(bool=true)
bool getBool(const Attribute &attr)
Return logical value.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
void setRotationAboutZ(double rotation)
Set rotation about z axis in bend frame.
const std::string getTypeName() const
Return the element's type name.
The base class for all OPAL exceptions.
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Object * getParent() const
Return parent pointer.
void setMisalignment(const CoordinateSystemTrafo &cst)
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
const std::string getWakeF() const
Return the element's type name.
Interface for statements.
ElementBase * getElement() const
Return the embedded CLASSIC element.
bool delimiter(char c)
Test for delimiter.
void setElementPosition(double elemedge)
Access to ELEMEDGE attribute.
std::string parseString(Statement &, const char msg[])
Parse string value.
const std::string & getOpalName() const
Return object name.
std::vector< Attribute > itsAttr
The object attributes.
void parse(Statement &stat, bool eval)
Parse attribute.
Tps< T > cos(const Tps< T > &x)
Cosine.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special exception
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.
double parseRealConst(Statement &)
Parse real constant.
double getReal(const Attribute &attr)
Return real value.
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).
virtual void parse(Statement &)
Parse the element.
void setDefault()
Assign default value.
virtual bool isExpression() const
Test for expression.
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown'' (not known to OPAL) attributes to CLASSIC.
AttributeBase & getBase() const
Return reference to polymorphic value.
void setAperture(const ApertureType &type, const std::vector< double > &args)
virtual Attribute * findAttribute(const std::string &name)
Find an attribute by name.
virtual double getLength() const
Return element length.
Tps< T > sin(const Tps< T > &x)
Sine.
const std::string getParticleMatterInteraction() const
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name)
A representation of an Object attribute.