59 int printWidth, printPrecision;
67 const ColDesc allColumns[] = {
251 const ColDesc defaultColumns[] = {
271 const ColDesc *findCol(
const Twiss &table,
const std::string &colName) {
272 for(
const ColDesc *col = allColumns; col->colName; ++col) {
273 if(colName == col->colName) {
280 "\" has no column named \"" + colName +
"\".");
295 Column(
const Twiss &tab,
const std::string &colName,
const ColDesc &desc);
297 Column(
const Column &);
307 virtual void print(std::ostream &os,
int precedence = 99)
const;
316 const Twiss &itsTable;
332 Column::Column(
const Twiss &tab,
const std::string &colName,
const ColDesc &desc):
333 itsTable(tab), colName(colName),
334 get(desc.get), ind_1(desc.ind_1), ind_2(desc.ind_2)
338 Column::Column(
const Column &rhs):
340 itsTable(rhs.itsTable), colName(rhs.colName),
341 get(rhs.get), ind_1(rhs.ind_1), ind_2(rhs.ind_2)
350 return new Column(*
this);
354 double Column::evaluate()
const {
355 return (itsTable.*
get)(itsTable.getCurrent(), ind_1, ind_2);
359 void Column::print(std::ostream &os,
int)
const {
410 (
"LINE",
"The beam line use for filling");
412 (
"BEAM",
"The beam to be used",
"UNNAMED_BEAM");
414 (
"RANGE",
"The range in the lattice");
416 (
"STATIC",
"If true, the table is not recalculated at each iteration");
418 (
"ORDER",
"The order of the calculation", 2);
420 (
"METHOD",
"the algorithm used for filling:\n"
421 "\t\t\t\"LINEAR\", \"THIN\", \"THICK\", or \"TRANSPORT\"\n"
422 "\t\t\tDefault value is \"LINEAR\"",
"LINEAR");
424 (
"REVBEAM",
"Set true to run beam backwards through lattice");
426 (
"REVTRACK",
"Set true to track against the beam");
430 (
"BETXMAX",
"Maximum horizontal beta in m");
434 (
"BETYMAX",
"Maximum vertical beta in m");
438 (
"XCMAX",
"Maximum horizontal closed orbit in m");
442 (
"YCMAX",
"Maximum vertical closed orbit in m");
446 (
"XCRMS",
"R.m.s. horizontal closed orbit in m");
450 (
"YCRMS",
"R.m.s. vertical closed orbit in m");
454 (
"DXMAX",
"Maximum horizontal dispersion in m");
458 (
"DYMAX",
"Maximum vertical dispersion in m");
462 (
"DXRMS",
"R.m.s. horizontal dispersion in m");
466 (
"DYRMS",
"R.m.s. vertical dispersion in m");
472 Table(name, parent), itsTable(new
TLine(name)), itsMapper(0)
589 std::cerr <<
"\n### Warning ### Lattice function table \""
592 itsTable->front().setSelectionFlag(
true);
593 itsTable->back().setSelectionFlag(
true);
602 if(method ==
"THICK") {
605 }
else if(method ==
"THIN") {
608 }
else if(method ==
"LINEAR") {
613 "Method name \"" + method +
"\" is unknown.");
628 const ColDesc *col = findCol(*
this, colName);
629 return (this->*(col->get))(row, col->ind_1, col->ind_2);
635 for(
const ColDesc *col = defaultColumns; col->colName; ++col) {
637 new Column(*
this, col->colName, *col);
638 columns.push_back(
Cell(expr, col->printWidth, col->printPrecision));
647 const ColDesc *col = findCol(*
this, colName);
650 std::vector<double> column;
652 for(TLine::const_iterator row =
begin(); row !=
end(); ++row) {
655 column.push_back((this->*(col->get))(*row, col->ind_1, col->ind_2));
725 for(
int i = 0; i < 6; ++i) {
726 for(
int j = 0; j <= i; ++j) {
727 sigma[i][j] = sigma[j][i] =
728 E1 * (eigen[i][0] * eigen[j][0] + eigen[i][1] * eigen[j][1]) +
729 E2 * (eigen[i][2] * eigen[j][2] + eigen[i][3] * eigen[j][3]) +
730 E3 * (eigen[i][4] * eigen[j][4] + eigen[i][5] * eigen[j][5]);
740 std::vector<double> result;
744 for(
const ColDesc *col = defaultColumns; col->colName != 0; ++col) {
745 result.push_back((this->*col->get)(row, col->ind_1, col->ind_2));
749 for(std::vector<std::string>::const_iterator iter = cols.begin();
750 iter != cols.end(); ++iter) {
751 const ColDesc *col = findCol(*
this, *iter);
752 result.push_back((this->*(col->get))(row, col->ind_1, col->ind_2));
762 if(
itsLine == name)
return true;
765 for(TLine::const_iterator row =
begin(); row !=
end(); ++row) {
766 if(row->getElement()->getName() ==
name)
return true;
776 const ColDesc *col = findCol(*
this, colName);
777 return new Column(*
this, colName, *col);
782 return dynamic_cast<Twiss *
>(rhs) != 0;
789 for(CellArray::const_iterator cell = cells.begin();
790 cell < cells.end(); ++cell) {
791 lineLength += cell->printWidth;
795 os << std::string(lineLength,
'-') <<
'\n';
797 for(CellArray::const_iterator cell = cells.begin();
798 cell < cells.end(); ++cell) {
799 std::ostringstream ss;
800 cell->itsExpr->print(ss, 0);
802 std::string image = ss.str();
804 if(
int(image.length()) < cell->printWidth) {
806 os << std::string(cell->printWidth - image.length(),
' ') << image;
809 os <<
' ' << std::string(image, 0, cell->printWidth - 3) <<
"..";
813 os << std::string(lineLength,
'-') <<
'\n';
817 if(
current->getSelectionFlag()) {
818 std::string
name =
current->getElement()->getName();
819 if(
int occur =
current->getCounter()) {
820 std::ostringstream tos;
821 tos << name <<
'[' << occur <<
']' << std::ends;
825 if(name.length() > 16) {
827 os << std::string(name, 0, 13) <<
".. ";
830 os << name << std::string(16 - name.length(),
' ');
833 for(CellArray::const_iterator cell = cells.begin();
834 cell != cells.end(); ++cell) {
835 os << std::setw(cell->printWidth)
836 << std::setprecision(cell->printPrecision)
837 << cell->itsExpr->evaluate();
843 os << std::string(lineLength,
'-') <<
'\n';
854 <<
", ORDER: " <<
order <<
".\n";
871 std::ostringstream os;
872 os << row << std::ends;
873 throw OpalException(
"Twiss::findRow()",
"Row \"" + os.str() +
874 "\" not found in twiss table \"" +
getOpalName() +
"\".");
881 static const double epsilon = 1.0e-8;
886 bool staticQ = (map[5] == map[5][0] + nrgy);
900 for(TLine::reverse_iterator row =
itsTable->rbegin();
906 row->mu[0] = mux + double(imux);
907 row->mu[1] = muy + double(imuy);
908 row->mu[2] = mut + double(imut);
915 if(! dynamic_cast<Beamline *>(&elem)) {
927 const double *row1 = matrix[0];
928 const double *row3 = matrix[2];
929 const double *row5 = matrix[4];
931 for(
int i = 0; i < 6; ++i) {
932 A11 += row1[i] *
curly_A[i][0];
933 A12 += row1[i] * curly_A[i][1];
934 A33 += row3[i] * curly_A[i][2];
935 A34 += row3[i] * curly_A[i][3];
936 A55 += row5[i] * curly_A[i][4];
937 A56 += row5[i] * curly_A[i][5];
941 if(mu - epsilon > mux) --imux;
944 if(mu - epsilon > muy) --imuy;
947 if(mu - epsilon > mut) --imut;
965 double mux1 = mux + double(imux);
966 double muy1 = muy + double(imuy);
967 double mut1 = mut + double(imut);
996 if(! dynamic_cast<Beamline *>(&elem)) {
1012 const double *row1 = matrix[0];
1013 const double *row3 = matrix[2];
1014 const double *row5 = matrix[4];
1019 for(
int i = 0; i < 6; ++i) {
1020 A11 += row1[i] *
curly_A[i][0];
1021 A12 += row1[i] * curly_A[i][1];
1022 A33 += row3[i] * curly_A[i][2];
1023 A34 += row3[i] * curly_A[i][3];
1024 A55 += row5[i] * curly_A[i][4];
1025 A56 += row5[i] * curly_A[i][5];
1029 if(mu + epsilon < mux) ++imux;
1032 if(mu + epsilon < muy) ++imuy;
1035 if(mu + epsilon < mut) ++imut;
1050 row->arc = arc - arc1;
1051 row->mu[0] = mux + double(imux) - mux1;
1052 row->mu[1] = muy + double(imuy) - muy1;
1053 row->mu[2] = mut + double(imut) - mut1;
1058 double betxmax = 0.0;
1059 double betymax = 0.0;
1072 double x =
getCO(*row, 0, 0);
1073 double y =
getCO(*row, 2, 0);
1074 double dx =
getDisp(*row, 0, 0);
1075 double dy =
getDisp(*row, 2, 0);
1112 const double *row1 = row.
matrix[2*i1];
1113 const double *row2 = row.
matrix[2*i1+1];
1119 for(
int i = 0; i < 6; ++i) {
1120 double t1 = row1[i];
1122 r12 += t1 * curly_A[i][2*i1+1];
1123 double t2 = row2[i];
1124 r21 += t2 * curly_A[i][2*i1];
1125 r22 += t2 * curly_A[i][2*i1+1];
1133 return (r11 * r11 + r12 * r12) / (r11 * r22 - r12 * r21);
1138 const double *row1 = row.
matrix[2*i1];
1139 const double *row2 = row.
matrix[2*i1+1];
1145 for(
int i = 0; i < 6; ++i) {
1146 double t1 = row1[i];
1148 r12 += t1 * curly_A[i][2*i1+1];
1149 double t2 = row2[i];
1150 r21 += t2 * curly_A[i][2*i1];
1151 r22 += t2 * curly_A[i][2*i1+1];
1160 return - (r11 * r21 + r12 * r22) / (r11 * r22 - r12 * r21);
1165 const double *row1 = row.
matrix[2*i1];
1169 for(
int i = 0; i < 6; ++i) {
1170 double t1 = row1[i];
1172 r12 += t1 * curly_A[i][2*i2+1];
1179 return (r11 * r11 + r12 * r12);
1184 const double *row1 = row.
matrix[2*i1];
1185 const double *row2 = row.
matrix[2*i1+1];
1191 for(
int i = 0; i < 6; ++i) {
1192 double t1 = row1[i];
1194 r12 += t1 * curly_A[i][2*i2+1];
1195 double t2 = row2[i];
1196 r21 += t2 * curly_A[i][2*i2];
1197 r22 += t2 * curly_A[i][2*i2+1];
1206 return (r11 * r21 + r12 * r22);
1211 const double *row1 = row.
matrix[2*i1+1];
1215 for(
int i = 0; i < 6; ++i) {
1216 double t1 = row1[i];
1218 r22 += t1 * curly_A[i][2*i2+1];
1225 return (r21 * r21 + r22 * r22);
1230 return row.
getCO()[i1];
1236 const double *row1 = row.
matrix[i1];
1237 double result = 0.0;
1239 for(
int i = 0; i < 6; ++i) {
1241 result += row1[i] *
curly_A[i][5];
1250 const double *row1 = row.
matrix[i1];
1251 double result = 0.0;
1253 for(
int i = 0; i < 6; ++i) {
1255 result += row1[i] *
curly_A[i][i2];
1282 const double E1 =
getEX();
1283 const double E2 =
getEY();
1284 const double E3 =
getET();
1286 (E1 * (eigen[i1][0] * eigen[i2][0] + eigen[i1][1] * eigen[i2][1]) +
1287 E2 * (eigen[i1][2] * eigen[i2][2] + eigen[i1][3] * eigen[i2][3]) +
1288 E3 * (eigen[i1][4] * eigen[i2][4] + eigen[i1][5] * eigen[i2][5]));
1293 return row.
matrix[i1][i2];
void setReal(Attribute &attr, double val)
Set real value.
double Round(double value)
Round the double argument.
std::vector< Cell > CellArray
An array of cell descriptors.
virtual bool matches(Table *rhs) const
Check compatibility.
virtual bool isDependent(const std::string &name) const
Check dependency.
virtual void fill()=0
Refill the buffer.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
virtual Expressions::PtrToScalar< double > makeColumnExpression(const std::string &colName) const
Return column expression.
virtual void print(std::ostream &, int precedence=99) const =0
Print expression.
TLine::const_iterator current
Interface for basic beam line object.
void operator=(const Scalar &)
double getET() const
Return emittance for mode 3.
TLine::const_iterator end() const
Access to last row.
RangeRep getRange(const Attribute &attr)
Get range value.
double getEY() const
Return emittance for mode 2.
FMatrix< double, 6, 6 > getSigma() const
Initial envelope (Sigma) matrix.
double getGAMik(const Row &, int i1, int i2) const
Mais-Ripken gamma functions.
FVector< double, 6 > orbit
The closed orbit after the element.
TLine::const_iterator begin() const
Access to first row.
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
void leave(const FlaggedElmPtr &) const
Leave an element or line.
The base class for all OPAL exceptions.
virtual std::vector< double > getRow(const PlaceRep &, const std::vector< std::string > &)
Return a table row, possible user-defined.
constexpr double two_pi
The value of .
double getBETik(const Row &, int i1, int i2) const
Mais-Ripken beta functions.
virtual double getElementLength() const
Get design length.
void enter(const FlaggedElmPtr &) const
Enter an element or line.
const FVector< double, 6 > & getCO() const
Closed orbit.
Row & findRow(const PlaceRep &row)
Attribute makeRange(const std::string &name, const std::string &help)
Create a range attribute.
double getET() const
Return emittance for mode 3.
void update()
Update all objects.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Build a map using a linear map for each element.
bool isActive() const
Return status.
bool dynamic
Flag dynamic table.
static LinearFun makeVariable(int var)
Make variable.
double getEY() const
Return emittance for mode 2.
double getEigen(const Row &, int i1, int i2) const
Eigenvectors.
const Row & getCurrent() const
Return current table row in iteration.
bool getBool(const Attribute &attr)
Return logical value.
void printTableBody(std::ostream &, const CellArray &) const
Print the body to this TWISS table.
bool isActive() const
Test for active range.
void printTitle(std::ostream &)
Print the page title.
Representation of a place within a beam line or sequence.
FMatrix< double, 6, 6 > curly_A
The initial curly A matrix.
static OpalData * getInstance()
Twiss(int size, const char *name, const char *help)
Exemplar constructor.
const std::string & getOpalName() const
Return object name.
void initialize()
Initialise data for search.
static BeamSequence * find(const std::string &name)
Find a BeamSequence by name.
double getMUi(const Row &, int i1, int=0) const
Three modes, "naive" Twiss functions.
FMatrix< double, 6, 6 > matrix
The transfer matrix up to and including the element.
FVector< T, N > constantTerm(const FVector< T, N > &P) const
Evaluate map at point [b]P[/b].
virtual double getElementLength() const
Get design length.
void enter(const FlaggedElmPtr &) const
Enter an element or line.
void setCounter(int) const
Set clone counter.
static Beam * find(const std::string &name)
Find named BEAM.
virtual CellArray getDefault() const
Return the default print columns.
virtual Beamline * fetchLine() const =0
Return the embedded CLASSIC beam line.
virtual std::vector< double > getColumn(const RangeRep &range, const std::string &col)
Return column [b]col[/b] of this table, limited by [b]range[/b].
virtual double getLength()
Return the length of the table.
virtual Scalar< T > * clone() const =0
Copy scalar expression.
virtual double getCell(const PlaceRep &row, const std::string &col)
Return a selected value in a selected row.
virtual void execute()
Check validity of the table definition.
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
double getBETi(const Row &, int i1, int=0) const
FVector< double, 6 > orbit
The initial closed orbit.
virtual void setMap(const LinearMap< double, 6 > &)=0
Reset the linear part of the accumulated map for restart.
virtual void execute()
Apply the algorithm to the top-level beamline.
void initialize()
Initialise data for search.
Representation of a range within a beam line or sequence.
void leave(const FlaggedElmPtr &) const
Leave an element or line.
An abstract sequence of beam line components.
double getDisp(const Row &, int i1, int=0) const
Dispersion.
virtual void printTable(std::ostream &, const CellArray &) const =0
Print list for the table.
Tps< T > sqrt(const Tps< T > &x)
Square root.
const FMatrix< double, 6, 6 > & getMatrix() const
Transfer matrix.
The base class for all OPAL beam lines and sequences.
double getEX() const
Return emittance for mode 1.
Structure for a row of the Twiss table.
double getEX() const
Return emittance for mode 1.
const PartData & getReference() const
Return the embedded CLASSIC PartData.
const PartData * reference
AbstractMapper * itsMapper
double getCO(const Row &, int i1, int=0) const
Closed orbit.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Descriptor for printing a table cell.
FMatrix< T, N, N > linearTerms() const
Extract linear terms at origin.
double getS() const
Arc length.
void printTableTitle(std::ostream &, const char *title) const
Print standard information about the TWISS table.
FMatrix< double, 6, 6 > getMatrix(const Row &) const
Accumulated transfer map.
virtual T evaluate() const =0
Evaluate.
FMatrix< double, 6, 6 > getCurlyA() const
Return initial curly A matrix.
virtual const Beamline * getLine() const
Return embedded CLASSIC beamline.
std::string::iterator iterator
Linear function in N variables of type T.
double getALFik(const Row &, int i1, int i2) const
Mais-Ripken alpha functions.
double getReal(const Attribute &attr)
Return real value.
FVector< double, 6 > getOrbit() const
Return initial closed orbit.
The base class for all OPAL tables.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
double getALFi(const Row &, int i1, int=0) const
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Build a map using a finite-length lens for each element.
double getS(const Row &, int=0, int=0) const
Arc length for given row.
virtual void getMap(LinearMap< double, 6 > &) const =0
Return the linear part of the accumulated map.
Inform & endl(Inform &inf)
A section of a beam line.
std::string getString(const Attribute &attr)
Get string value.
double getMUi(int i) const
Phase for mode i.