12 double getRequiredPositiveReal(
13 const std::vector<Attribute>& attrs,
int index,
const std::string& where) {
15 throw OpalException(where,
"\"" + attrs[index].getName() +
"\" must be set.");
21 where,
"\"" + attrs[index].getName() +
"\" must be greater than 0.");
28 const Attribute& attr,
const std::string& where,
const std::string& semanticName) {
34 if (values.size() != 3) {
35 std::ostringstream msg;
36 msg <<
"\"" << attr.
getName() <<
"\" must contain exactly 3 values for " << semanticName
37 <<
"; got " << values.size() <<
".";
48 "The \"LASER\" element defines a passive analytic laser pulse for OPALX.") {
56 "STOKES",
"Normalized Stokes polarization vector {xi1, xi2, xi3}.");
72 constexpr const char* where =
"OpalLaser::update()";
103 if (!anyConfigured) {
111 const double waistX = getRequiredPositiveReal(
itsAttr,
WAISTX, where);
112 const double waistY = getRequiredPositiveReal(
itsAttr,
WAISTY, where);
115 const double directionNorm = std::sqrt(
dot(direction, direction));
116 if (directionNorm <= 0.0) {
117 throw OpalException(where,
"\"DIR\" must be a non-zero vector.");
119 direction /= directionNorm;
123 stokes = getVector3(
itsAttr[
STOKES], where,
"the Stokes vector");
124 const double stokesNorm2 =
dot(stokes, stokes);
125 if (stokesNorm2 > 1.0 + 1.0e-12) {
126 throw OpalException(where,
"\"STOKES\" must satisfy xi1^2 + xi2^2 + xi3^2 <= 1.");
132 throw OpalException(where,
"\"L\" must be greater than or equal to 0.");
135 laser->setElementLength(length);
136 laser->setWavelength(wavelength);
137 laser->setPulseEnergy(pulseEnergy);
138 laser->setPulseLength(pulseLength);
139 laser->setWaistX(waistX);
140 laser->setWaistY(waistY);
141 laser->setDirection(direction);
142 laser->setStokes(stokes);
ippl::Vector< T, Dim > Vector_t
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
A representation of an Object attribute.
const std::string & getName() const
Return the attribute name.
ElementBase * getElement() const
Return the embedded OPALX element.
void setElement(ElementBase *)
Assign new OPALX element.
std::vector< Attribute > itsAttr
The object attributes.
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPALX) attributes to OPALX.
virtual void update()
Update the embedded OPALX element.
void registerOwnership() const
void update() override
Update the embedded OPALX element.
OpalLaser * clone(const std::string &name) override
Return a clone.
double getReal(const Attribute &attr)
Return real value.
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.