OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Aperture.cpp
Go to the documentation of this file.
1 #include "Aperture/Aperture.h"
3 #include "Structure/Beam.h"
8 #include "Elements/OpalElement.h"
10 #include "Physics/Physics.h"
12 #include "AbsBeamline/RBend.h"
13 #include "AbsBeamline/SBend.h"
14 #include "AbsBeamline/Cyclotron.h"
15 #include "Utilities/Timer.h"
16 #include <iostream>
17 #include <fstream>
18 #include <sstream>
19 #include <iomanip>
20 #include <string>
21 
22 using namespace std;
23 
24 // Local structures.
25 // ------------------------------------------------------------------------
26 
27 namespace {
28 
29  //return the inverse of the "alpha,beta,gamma" transformation matrix
30 
31  FMatrix<double, 3, 3> invers(double c, double c_prim, double s, double s_prim) {
33  double det = -pow(c_prim, 3) * pow(s, 3) + 3 * c * s_prim * pow(c_prim, 2)
34  * pow(s, 2) - 3 * pow(c, 2) * c_prim * s * pow(s_prim, 2) + pow(c, 3) * pow(s_prim, 3);
35 
36  M(0, 0) = (-c_prim * s * pow(s_prim, 2) + c * pow(s_prim, 3)) / det;
37  M(0, 1) = (-2 * c_prim * pow(s, 2) * s_prim + 2 * c * s * pow(s_prim, 2)) / det;
38  M(0, 2) = (-c_prim * pow(s, 3) + c * pow(s, 2) * s_prim) / det;
39  M(1, 0) = (-pow(c_prim, 2) * s * s_prim + c * c_prim * pow(s_prim, 2)) / det;
40  M(1, 1) = (-pow(c_prim, 2) * pow(s, 2) + pow(c, 2) * pow(s_prim, 2)) / det;
41  M(1, 2) = (-c * c_prim * pow(s, 2) + pow(c, 2) * s * s_prim) / det;
42  M(2, 0) = (-pow(c_prim, 3) * s + c * pow(c_prim, 2) * s_prim) / det;
43  M(2, 1) = (-2 * c * pow(c_prim, 2) * s + 2 * pow(c, 2) * c_prim * s_prim) / det;
44  M(2, 2) = (-pow(c, 2) * c_prim * s + pow(c, 3) * s_prim) / det;
45 
46  return M;
47  }
48 
49  struct ColDesc {
50 
51  // Column name.
52  const char *colName;
53 
54  // Pointer to the row method which returns the column value.
55  double(Aperture::*get)(const Aperture::A_row &, int, int) const;
56 
57  // Default field width and precision.
58  int printWidth, printPrecision;
59 
60  // Indices to be given to get().
61  int ind_1, ind_2;
62  };
63 
64 
65  // The complete column entries table.
66  const ColDesc allColumns[] = {
67 
68  // "Naive" maximum Twiss.
69  { "BETXMAX", &Aperture::getBETXMAX, 10, 6, 0, 0 },
70  { "BETYMAX", &Aperture::getBETYMAX, 10, 6, 0, 0 },
71  { "APERTMIN", &Aperture::getAPERTMIN, 10, 6, 0, 0},
72  //{ "ALFY", &Aperture::getALFi, 10, 6, 1, 0 },
73  //{ "ALFT", &Aperture::getALFi, 10, 6, 2, 0 },
74  { 0, 0, 0, 0, 0, 0 }
75  };
76 
77 
78  // The default column entries table.
79  const ColDesc defaultColumns[] = {
80  // "Naive" maximum Twiss.
81  { "BETXMAX", &Aperture::getBETXMAX, 10, 6, 0, 0 },
82  { "BETYMAX", &Aperture::getBETYMAX, 10, 6, 0, 0 },
83  { "APERTMIN", &Aperture::getAPERTMIN, 10, 6, 0, 0},
84  { 0, 0, 0, 0, 0, 0 }
85  };
86 
87  const ColDesc *findCol(const Aperture &table, const std::string &colName) {
88  for(const ColDesc *col = allColumns; col->colName; ++col) {
89  if(colName == col->colName) {
90  return col;
91  }
92  }
93 
94  throw OpalException("Aperture::findCol()",
95  "Aperture table \"" + table.getOpalName() +
96  "\" has no column named \"" + colName + "\".");
97  }
98 
99 
100  // Local class Column.
101  // Returns the value for a given column in the current row of a given
102  // table.
103  class Column: public Expressions::Scalar<double> {
104 
105  public:
106 
107  //: Constructor.
108  // Identify the table by its name [b]tab[/b], and the column by its
109  // name [b]col[/b] and the function [b]col[/b].
110  // The row is specified as the ``current'' row of the table.
111  Column(const Aperture &tab, const std::string &colName, const ColDesc &desc);
112 
113  Column(const Column &);
114  virtual ~Column();
115 
116  //: Make clone.
117  virtual Expressions::Scalar<double> *clone() const;
118 
119  //: Evaluate.
120  virtual double evaluate() const;
121 
122  //: Print expression.
123  virtual void print(std::ostream &os, int precedence = 99) const;
124 
125  private:
126 
127  // Not implemented.
128  Column();
129  const Column &operator=(const Column &);
130 
131  // The Table referred.
132  const Aperture &itsTable;
133 
134  // Column name.
135  std::string colName;
136 
137  // The function returning the column value.
138  double(Aperture::*get)(const Aperture::A_row &, int, int) const;
139 
140  // The indices to be transmitted to get().
141  int ind_1, ind_2;
142  };
143 
144 
145  // Implementation.
146  // ------------------------------------------------------------------------
147 
148  Column::Column(const Aperture &tab, const std::string &colName, const ColDesc &desc):
149  itsTable(tab), colName(colName),
150  get(desc.get), ind_1(desc.ind_1), ind_2(desc.ind_2)
151  {}
152 
153 
154  Column::Column(const Column &rhs):
155  Scalar<double>(rhs),
156  itsTable(rhs.itsTable), colName(rhs.colName),
157  get(rhs.get), ind_1(rhs.ind_1), ind_2(rhs.ind_2)
158  {}
159 
160 
161  Column::~Column()
162  {}
163 
164 
165  Expressions::Scalar<double> *Column::clone() const {
166  return new Column(*this);
167  }
168 
169 
170  double Column::evaluate() const {
171  return (itsTable.*get)(itsTable.getCurrent(), ind_1, ind_2);
172  }
173 
174 
175  void Column::print(std::ostream &os, int) const {
176  os << colName;
177  }
178 
179 };
180 
182  DefaultVisitor(itsTable, false, false),
183  Table(SIZE, "APERTURE", "help"), itsTable() {
185  ("TABLE", "Name of the TWISS table to be used.");
187  ("BEAM", "The beam to be used", "UNNAMED_BEAM");
189  ("NSLICE", "the number of slices of the interpolation inside the optic element", 10);
191  ("STATIC", "recalculation if static equal false", true);
193  ("DATA", "The data needed for aperture calculation(co,deltap,BBeat,HALO)");
195  ("DEFAULTAPERTURE", "The default beam screen for markers and drift generated in sequences");
197  ("FILE", "Name of file to receive APERTURE output", "APERTURE.dat");
198 
200 }
201 Aperture::Aperture(const std::string &name, Aperture *parent):
202  DefaultVisitor(itsTable, false, false),
203  Table(name, parent), itsTable(name)
204 {}
205 
206 Aperture::A_row::A_row(const A_row &a): FlaggedElmPtr(a), Type_elm(a.Type_elm),
207  Orb(a.Orb), Interpol(a.Interpol) {}
208 
209 
210 inline double Aperture::A_row::getBeta_x(int ind) {
211  return Interpol[ind].Beta_x;
212 }
213 inline double Aperture::A_row::getBeta_y(int ind) {
214  return Interpol[ind].Beta_y;
215 }
216 
217 inline double Aperture::A_row::getDisp_x(int ind) {
218  return Interpol[ind].Disp_x;
219 }
220 inline double Aperture::A_row::getDisp_x_prim(int ind) {
221  return Interpol[ind].Disp_x_prim;
222 }
223 inline double Aperture::A_row::getDisp_y(int ind) {
224  return Interpol[ind].Disp_y;
225 }
226 inline double Aperture::A_row::getDisp_y_prim(int ind) {
227  return Interpol[ind].Disp_y_prim;
228 }
229 inline double Aperture::A_row::getApert(int ind) {
230  return Interpol[ind].apert;
231 }
232 inline std::string Aperture::A_row::getType_elm() {
233  return Type_elm;
234 }
235 inline double Aperture::A_row::getOrb() {
236  return Orb;
237 }
238 
239 //iterator used for the displacement in the list of optic elments
240 
242  return itsTable.begin();
243 }
244 Aperture::A_Tline::const_iterator Aperture::begin() const {
245  return itsTable.begin();
246 }
248  return itsTable.end();
249 }
250 Aperture::A_Tline::const_iterator Aperture::end() const {
251  return itsTable.end();
252 }
253 
254 double Aperture::getBETXMAX(const A_row &row, int i1, int i2) const {
255  double max;
256  double nslice = Attributes::getReal(itsAttr[NSLICE]);
257  max = row.Interpol[0].Beta_x;
258  for(int i = 1; i < nslice; ++i) {
259  if(max < row.Interpol[i].Beta_x) max = row.Interpol[i].Beta_x;
260  }
261  return max;
262 }
263 
264 double Aperture::getBETYMAX(const A_row &row, int i1, int i2) const {
265  double max;
266  double nslice = Attributes::getReal(itsAttr[NSLICE]);
267  max = row.Interpol[0].Beta_y;
268  for(int i = 1; i < nslice; ++i) {
269  if(max < row.Interpol[i].Beta_y) max = row.Interpol[i].Beta_y;
270 
271  }
272  return max;
273 }
274 
275 double Aperture::getAPERTMIN(const A_row &row, int i1, int i2) const {
276  double min;
277  double nslice = Attributes::getReal(itsAttr[NSLICE]);
278  min = row.Interpol[0].apert;
279  for(int i = 1; i < nslice; ++i) {
280  if(min > row.Interpol[i].apert) min = row.Interpol[i].apert;
281 
282  }
283  return min;
284 }
285 
286 
288  BMultipoleField f = m.getField();
289  double K = f.normal(2) * 0.299792458;
290 
291  const PartData &p = beam->getReference();
292 
293  data.kq = K / (p.getP() / 1e9);
294  data.k0s = 0;
295  data.l = m.getElementLength();
296  data.phi = 0;
297 
298  data.courb = 0;
299  data.type = "multi";
300 }
301 
302 void Aperture::visitRBend(const RBend &rb) {
303  const RBendGeometry &geom = rb.getGeometry();
304  data.l = geom.getElementLength();
305  if(data.l != 0) {
306  data.phi = geom.getBendAngle();
308  data.e2 = rb.getExitFaceRotation();
309  data.type = "rbend";
310  data.courb = 2 * sin(data.phi / 2) / data.l;
311  data.l = data.phi / data.courb;
312 
313  BMultipoleField f = rb.getField();
314  double K = f.normal(2) * 0.299792458;
315 
316  const PartData &p = beam->getReference();
317 
318 
319  data.kq = K / (p.getP() / 1e9);
320  data.k0s = f.skew(1) * 0.299792458 / (p.getP() / 1e9);
321  }
322 }
323 
325  ERRORMSG("MSplit::visitCyclotron(const Cyclotron &cy) not implemented");
326 }
327 
328 
329 void Aperture::visitSBend(const SBend &sb) {
330  const PlanarArcGeometry &geom = sb.getGeometry();
331  data.l = geom.getElementLength();
332  if(data.l != 0) {
333  data.phi = geom.getBendAngle();
335  data.e2 = sb.getExitFaceRotation();
336  data.type = "sbend";
337  data.courb = data.phi / data.l;
338 
339  BMultipoleField f = sb.getField();
340  double K = f.normal(2) * 0.299792458;
341  const PartData &p = beam->getReference();
342 
343  data.kq = K / (p.getP() / 1e9);
344  data.k0s = f.skew(1) * 0.299792458 / (p.getP() / 1e9);
345 
346  }
347 
348 }
349 
351  data.type = "drift";
352  data.l = eb.getElementLength();
353  data.courb = 0;
354  data.phi = 0;
355  data.kq = 0;
356  data.k0s = 0;
357 }
358 
359 
361  double Kx, Ky;
362 
363  if(data.l != 0) {
366 
367  Kx = data.kq + pow(data.courb, 2);
368  Ky = -data.kq + pow(data.k0s, 2);
369 
370  a.Interpol[nslice-1].Beta_x = tp->getBETi(*i, 0, 0);
371  a.Interpol[nslice-1].Beta_y = tp->getBETi(*i, 1, 0);
372  a.Interpol[nslice-1].Disp_x = tp->getDisp(*i, 0, 0);
373  a.Interpol[nslice-1].Disp_y = tp->getDisp(*i, 2, 0);
374  a.Interpol[nslice-1].Disp_x_prim = tp->getDisp(*i, 1, 0);
375  a.Interpol[nslice-1].Disp_y_prim = tp->getDisp(*i, 3, 0);
376 
377  Euler_x(0) = tp->getBETi(*i, 0, 0);
378  Euler_x(1) = tp->getALFi(*i, 0, 0);
379  Euler_x(2) = (1 + pow(Euler_x(1), 2)) / Euler_x(0);
380  Euler_y(0) = tp->getBETi(*i, 1, 0);
381  Euler_y(1) = tp->getALFi(*i, 1, 0);
382  Euler_y(2) = (1 + pow(Euler_y(1), 2)) / Euler_y(0);
383 
384  Dispx(0) = tp->getDisp(*i, 0, 0);
385  Dispx(1) = tp->getDisp(*i, 1, 0);
386  Dispy(0) = tp->getDisp(*i, 2, 0);
387  Dispy(1) = tp->getDisp(*i, 3, 0);
388 
389  if(data.type.compare("rbend") == 0) {
390  //propagation of x twiss function through the exit face
391  Transf_mat(0, 0) = 1;
392  Transf_mat(0, 1) = 0;
393  Transf_mat(1, 0) = data.courb * tan(data.e2 + data.phi / 2);
394  Transf_mat(1, 1) = 1;
395  Transf_mat(0, 2) = 0;
396  Transf_mat(1, 2) = 0;
397 
398  Mx = invers(Transf_mat(0, 0), Transf_mat(1, 0), Transf_mat(0, 1), Transf_mat(1, 1));
399 
400  Euler_x(0) = Mx(0, 0) * tp->getBETi(*i, 0, 0) + Mx(0, 1) * tp->getALFi(*i, 0, 0) + Mx(0, 2) *
401  (1 + pow(tp->getALFi(*i, 0, 0), 2)) / tp->getBETi(*i, 0, 0);
402  Euler_x(1) = Mx(1, 0) * tp->getBETi(*i, 0, 0) + Mx(1, 1) * tp->getALFi(*i, 0, 0) + Mx(1, 2) *
403  (1 + pow(tp->getALFi(*i, 0, 0), 2)) / tp->getBETi(*i, 0, 0);
404  Euler_x(2) = (1 + pow(Euler_x(1), 2)) / Euler_x(0);
405 
406  Dispx(0) = (Transf_mat(1, 1) * (tp->getDisp(*i, 0, 0) - Transf_mat(0, 2)) +
407  Transf_mat(0, 1) * (Transf_mat(1, 2) - tp->getDisp(*i, 1, 0))) /
408  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
409  Dispx(1) = (Transf_mat(0, 0) * (tp->getDisp(*i, 1, 0) - Transf_mat(1, 2)) +
410  Transf_mat(1, 0) * (Transf_mat(0, 2) - tp->getDisp(*i, 0, 0))) /
411  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
412 
413  //propagation of y twiss function through the exit face
414 
415  Transf_mat(3, 3) = 1;
416  Transf_mat(3, 4) = 0;
417  Transf_mat(4, 3) = -data.courb * tan(data.e2 + data.phi / 2);
418  Transf_mat(4, 4) = 1;
419  Transf_mat(3, 5) = 0;
420  Transf_mat(4, 5) = 0;
421 
422  My = invers(Transf_mat(3, 3), Transf_mat(4, 3), Transf_mat(3, 4), Transf_mat(4, 4));
423 
424  Euler_y(0) = My(0, 0) * tp->getBETi(*i, 1, 0) + My(0, 1) * tp->getALFi(*i, 1, 0) + My(0, 2) *
425  (1 + pow(tp->getALFi(*i, 1, 0), 2)) / tp->getBETi(*i, 1, 0);
426  Euler_y(1) = My(1, 0) * tp->getBETi(*i, 1, 0) + My(1, 1) * tp->getALFi(*i, 1, 0) + My(1, 2) *
427  (1 + pow(tp->getALFi(*i, 1, 0), 2)) / tp->getBETi(*i, 1, 0);
428  Euler_y(2) = (1 + pow(Euler_y(1), 2)) / Euler_y(0);
429 
430  Dispy(0) = (Transf_mat(4, 4) * (tp->getDisp(*i, 2, 0) - Transf_mat(3, 5)) +
431  Transf_mat(3, 4) * (Transf_mat(4, 5) - tp->getDisp(*i, 3, 0))) /
432  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
433  Dispy(1) = (Transf_mat(3, 3) * (tp->getDisp(*i, 3, 0) - Transf_mat(4, 5)) +
434  Transf_mat(4, 3) * (Transf_mat(3, 5) - tp->getDisp(*i, 2, 0))) /
435  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
436 
437  } else if(data.type.compare("sbend") == 0) {
438  //propagation of x twiss function through the exit face
439  Transf_mat(0, 0) = 1;
440  Transf_mat(0, 1) = 0;
441  Transf_mat(1, 0) = data.courb * tan(data.e2);
442  Transf_mat(1, 1) = 1;
443  Transf_mat(0, 2) = 0;
444  Transf_mat(1, 2) = 0;
445 
446  Mx = invers(Transf_mat(0, 0), Transf_mat(1, 0), Transf_mat(0, 1), Transf_mat(1, 1));
447 
448  Euler_x(0) = Mx(0, 0) * tp->getBETi(*i, 0, 0) + Mx(0, 1) * tp->getALFi(*i, 0, 0) + Mx(0, 2) *
449  (1 + pow(tp->getALFi(*i, 0, 0), 2)) / tp->getBETi(*i, 0, 0);
450  Euler_x(1) = Mx(1, 0) * tp->getBETi(*i, 0, 0) + Mx(1, 1) * tp->getALFi(*i, 0, 0) + Mx(1, 2) *
451  (1 + pow(tp->getALFi(*i, 0, 0), 2)) / tp->getBETi(*i, 0, 0);
452  Euler_x(2) = (1 + pow(Euler_x(1), 2)) / Euler_x(0);
453 
454  Dispx(0) = (Transf_mat(1, 1) * (tp->getDisp(*i, 0, 0) - Transf_mat(0, 2)) +
455  Transf_mat(0, 1) * (Transf_mat(1, 2) - tp->getDisp(*i, 1, 0))) /
456  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
457  Dispx(1) = (Transf_mat(0, 0) * (tp->getDisp(*i, 1, 0) - Transf_mat(1, 2)) +
458  Transf_mat(1, 0) * (Transf_mat(0, 2) - tp->getDisp(*i, 0, 0))) /
459  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
460 
461  //propagation of y twiss function through the exit face
462 
463  Transf_mat(3, 3) = 1;
464  Transf_mat(3, 4) = 0;
465  Transf_mat(4, 3) = -data.courb * tan(data.e2);
466  Transf_mat(4, 4) = 1;
467  Transf_mat(3, 5) = 0;
468  Transf_mat(4, 5) = 0;
469 
470  My = invers(Transf_mat(3, 3), Transf_mat(4, 3), Transf_mat(3, 4), Transf_mat(4, 4));
471 
472  Euler_y(0) = My(0, 0) * tp->getBETi(*i, 1, 0) + My(0, 1) * tp->getALFi(*i, 1, 0) + My(0, 2) *
473  (1 + pow(tp->getALFi(*i, 1, 0), 2)) / tp->getBETi(*i, 1, 0);
474  Euler_y(1) = My(1, 0) * tp->getBETi(*i, 1, 0) + My(1, 1) * tp->getALFi(*i, 1, 0) + My(1, 2) *
475  (1 + pow(tp->getALFi(*i, 1, 0), 2)) / tp->getBETi(*i, 1, 0);
476  Euler_y(2) = (1 + pow(Euler_y(1), 2)) / Euler_y(0);
477 
478  Dispy(0) = (Transf_mat(4, 4) * (tp->getDisp(*i, 2, 0) - Transf_mat(3, 5)) +
479  Transf_mat(3, 4) * (Transf_mat(4, 5) - tp->getDisp(*i, 3, 0))) /
480  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
481  Dispy(1) = (Transf_mat(3, 3) * (tp->getDisp(*i, 3, 0) - Transf_mat(4, 5)) +
482  Transf_mat(4, 3) * (Transf_mat(3, 5) - tp->getDisp(*i, 2, 0))) /
483  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
484 
485  }
486 
487  if(abs(Kx) < 1e-6) {
488  for(int j = 1; j <= nslice - 1; ++j) {
489 
490  //expansion of the transformation matrix coefficients at third order
491  Transf_mat(0, 0) = 1 - Kx * pow(data.l * j / nslice, 2) / 2;
492  Transf_mat(0, 1) = data.l * j / nslice * (1 - Kx / 6 * pow(data.l * j / nslice, 2));
493  Transf_mat(1, 0) = -Kx * Transf_mat(0, 1);
494  Transf_mat(1, 1) = Transf_mat(0, 0);
495  Transf_mat(0, 2) = data.courb / 2 * pow(data.l * j / nslice, 2);
496  Transf_mat(1, 2) = data.courb * data.l * j / nslice * (1 - Kx / 6 * pow(data.l * j / nslice, 2));
497 
498  Mx = invers(Transf_mat(0, 0), Transf_mat(1, 0), Transf_mat(0, 1), Transf_mat(1, 1));
499 
500  //Filling of the vectors containing Beta et Disp inside the element
501 
502  a.Interpol[nslice-j-1].Beta_x = Mx(0, 0) * Euler_x(0) + Mx(0, 1) * Euler_x(1) + Mx(0, 2) * Euler_x(2);
503 
504  a.Interpol[nslice-j-1].Disp_x = (Transf_mat(1, 1) * (Dispx(0) - Transf_mat(0, 2)) +
505  Transf_mat(0, 1) * (Transf_mat(1, 2) - Dispx(1))) /
506  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
507  a.Interpol[nslice-j-1].Disp_x_prim = (Transf_mat(0, 0) * (Dispx(1) - Transf_mat(1, 2)) +
508  Transf_mat(1, 0) * (Transf_mat(0, 2) - Dispx(0))) /
509  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
510 
511  }
512  } else if(Kx > 0) {
513  for(int j = 1; j <= nslice - 1; ++j) {
514  Transf_mat(0, 0) = cos(data.l / nslice * j * sqrt(Kx));
515  Transf_mat(0, 1) = sin(data.l / nslice * j * sqrt(Kx)) / sqrt(Kx);
516  Transf_mat(1, 0) = -Kx * Transf_mat(0, 1);
517  Transf_mat(1, 1) = Transf_mat(0, 0);
518  Transf_mat(0, 2) = data.courb * (1 - cos(data.l / nslice * j * sqrt(Kx))) / Kx;
519  Transf_mat(1, 2) = data.courb * sin(data.l / nslice * j * sqrt(Kx)) / sqrt(Kx);
520 
521  Mx = invers(Transf_mat(0, 0), Transf_mat(1, 0), Transf_mat(0, 1), Transf_mat(1, 1));
522  a.Interpol[nslice-j-1].Beta_x = Mx(0, 0) * Euler_x(0) + Mx(0, 1) * Euler_x(1) + Mx(0, 2) * Euler_x(2);
523 
524  a.Interpol[nslice-j-1].Disp_x = (Transf_mat(1, 1) * (Dispx(0) - Transf_mat(0, 2)) +
525  Transf_mat(0, 1) * (Transf_mat(1, 2) - Dispx(1))) /
526  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
527  a.Interpol[nslice-j-1].Disp_x_prim = (Transf_mat(0, 0) * (Dispx(1) - Transf_mat(1, 2)) +
528  Transf_mat(1, 0) * (Transf_mat(0, 2) - Dispx(0))) /
529  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
530  }
531  }
532 
533  else { //if(Kx<0)
534  for(int j = 1; j <= nslice - 1; ++j) {
535  Transf_mat(0, 0) = cosh(data.l / nslice * j * sqrt(-Kx));
536  Transf_mat(0, 1) = sinh(data.l / nslice * j * sqrt(-Kx)) / sqrt(-Kx);
537  Transf_mat(1, 0) = -Kx * Transf_mat(0, 1);
538  Transf_mat(1, 1) = Transf_mat(0, 0);
539  Transf_mat(0, 2) = data.courb * (1 - cosh(data.l / nslice * j * sqrt(-Kx))) / -Kx;
540  Transf_mat(1, 2) = data.courb * sinh(data.l / nslice * j * sqrt(-Kx)) / sqrt(-Kx);
541 
542  Mx = invers(Transf_mat(0, 0), Transf_mat(1, 0), Transf_mat(0, 1), Transf_mat(1, 1));
543  a.Interpol[nslice-j-1].Beta_x = Mx(0, 0) * Euler_x(0) + Mx(0, 1) * Euler_x(1) + Mx(0, 2) * Euler_x(2);
544 
545  a.Interpol[nslice-j-1].Disp_x = (Transf_mat(1, 1) * (Dispx(0) - Transf_mat(0, 2)) +
546  Transf_mat(0, 1) * (Transf_mat(1, 2) - Dispx(1))) /
547  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
548  a.Interpol[nslice-j-1].Disp_x_prim = (Transf_mat(0, 0) * (Dispx(1) - Transf_mat(1, 2)) +
549  Transf_mat(1, 0) * (Transf_mat(0, 2) - Dispx(0))) /
550  (Transf_mat(1, 1) * Transf_mat(0, 0) - Transf_mat(1, 0) * Transf_mat(0, 1));
551  }
552  }
553  if(abs(Ky) < 1e-6) {
554  for(int j = 1; j <= nslice - 1; ++j) {
555  //expansion of the transformation matrix coefficients at third order
556 
557  Transf_mat(3, 3) = 1 - Ky * pow(data.l * j / nslice, 2) / 2;
558  Transf_mat(3, 4) = data.l * j / nslice * (1 - Ky / 6 * pow(data.l * j / nslice, 2));
559  Transf_mat(4, 3) = -Ky * Transf_mat(3, 4);
560  Transf_mat(4, 4) = Transf_mat(3, 3);
561  Transf_mat(3, 5) = data.k0s / 2 * pow(data.l * j / nslice, 2);
562  Transf_mat(4, 5) = data.k0s * data.l * j / nslice * (1 - Ky / 6 * pow(data.l * j / nslice, 2));
563 
564  My = invers(Transf_mat(3, 3), Transf_mat(4, 3), Transf_mat(3, 4), Transf_mat(4, 4));
565  a.Interpol[nslice-j-1].Beta_y = My(0, 0) * Euler_y(0) + My(0, 1) * Euler_y(1) + My(0, 2) * Euler_y(2);
566 
567  a.Interpol[nslice-j-1].Disp_y = (Transf_mat(4, 4) * (Dispy(0) - Transf_mat(3, 5)) +
568  Transf_mat(3, 4) * (Transf_mat(4, 5) - Dispy(1))) /
569  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
570  a.Interpol[nslice-j-1].Disp_y_prim = (Transf_mat(3, 3) * (Dispy(1) - Transf_mat(4, 5)) +
571  Transf_mat(4, 3) * (Transf_mat(3, 5) - Dispy(0))) /
572  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
573  }
574 
575  } else if(Ky > 0) {
576  for(int j = 1; j <= nslice - 1; ++j) {
577  Transf_mat(3, 3) = cos(data.l / nslice * j * sqrt(Ky));
578  Transf_mat(3, 4) = sin(data.l / nslice * j * sqrt(Ky)) / sqrt(Ky);
579  Transf_mat(4, 3) = -Ky * Transf_mat(3, 4);
580  Transf_mat(4, 4) = Transf_mat(3, 3);
581  Transf_mat(3, 5) = data.k0s * (1 - cos(data.l / nslice * j * sqrt(Ky))) / Ky;
582  Transf_mat(4, 5) = data.k0s * sin(data.l / nslice * j * sqrt(Ky)) / sqrt(Ky);
583 
584  My = invers(Transf_mat(3, 3), Transf_mat(4, 3), Transf_mat(3, 4), Transf_mat(4, 4));
585  a.Interpol[nslice-j-1].Beta_y = My(0, 0) * Euler_y(0) + My(0, 1) * Euler_y(1) + My(0, 2) * Euler_y(2);
586 
587  a.Interpol[nslice-j-1].Disp_y = (Transf_mat(4, 4) * (Dispy(0) - Transf_mat(3, 5)) +
588  Transf_mat(3, 4) * (Transf_mat(4, 5) - Dispy(1))) /
589  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
590  a.Interpol[nslice-j-1].Disp_y_prim = (Transf_mat(3, 3) * (Dispy(1) - Transf_mat(4, 5)) +
591  Transf_mat(4, 3) * (Transf_mat(3, 5) - Dispy(0))) /
592  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
593  }
594  }
595 
596  else { //if(Ky<0)
597  for(int j = 1; j <= nslice - 1; ++j) {
598  Transf_mat(3, 3) = cosh(data.l / nslice * j * sqrt(-Ky));
599  Transf_mat(3, 4) = sinh(data.l / nslice * j * sqrt(-Ky)) / sqrt(-Ky);
600  Transf_mat(4, 3) = -Ky * Transf_mat(3, 4);
601  Transf_mat(4, 4) = Transf_mat(3, 3);
602  Transf_mat(3, 5) = data.k0s * (1 - cosh(data.l / nslice * j * sqrt(-Ky))) / -Ky;
603  Transf_mat(4, 5) = data.k0s * sinh(data.l / nslice * j * sqrt(-Ky)) / sqrt(-Ky);
604 
605  My = invers(Transf_mat(3, 3), Transf_mat(4, 3), Transf_mat(3, 4), Transf_mat(4, 4));
606  a.Interpol[nslice-j-1].Beta_y = My(0, 0) * Euler_y(0) + My(0, 1) * Euler_y(1) + My(0, 2) * Euler_y(2);
607 
608  a.Interpol[nslice-j-1].Disp_y = (Transf_mat(4, 4) * (Dispy(0) - Transf_mat(3, 5)) +
609  Transf_mat(3, 4) * (Transf_mat(4, 5) - Dispy(1))) /
610  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
611  a.Interpol[nslice-j-1].Disp_y_prim = (Transf_mat(3, 3) * (Dispy(1) - Transf_mat(4, 5)) +
612  Transf_mat(4, 3) * (Transf_mat(3, 5) - Dispy(0))) /
613  (Transf_mat(4, 4) * Transf_mat(3, 3) - Transf_mat(4, 3) * Transf_mat(3, 4));
614  }
615  }
616 
617  } else {
618  for(int j = 0; j < nslice; ++j) {
619  a.Interpol[j].Beta_x = tp->getBETi(*i, 0, 0);
620  a.Interpol[j].Beta_y = tp->getBETi(*i, 1, 0);
621  a.Interpol[j].Disp_x = tp->getDisp(*i, 0, 0);
622  a.Interpol[j].Disp_y = tp->getDisp(*i, 2, 0);
623  a.Interpol[j].Disp_x_prim = tp->getDisp(*i, 1, 0);
624  a.Interpol[j].Disp_y_prim = tp->getDisp(*i, 3, 0);
625  }
626  }
627 
628  const std::string &nam1 = a.getElement()->getName();
629 
630 
631  if(nam1 == "[DRIFT]") {
632  a.Type_elm = "DRIFT";
633  std::vector<double> dat = Attributes::getRealArray(itsAttr[DEFAULTAPERTURE]);
634 
635  tolerance_x = dat[0];
636  tolerance_y = dat[1];
637  offsetx = dat[2];
638  offsety = dat[3];
639  dat.erase(dat.begin(), dat.begin() + 4);
640  ShapeBeamScreen = getShape(dat);
641  } else {
642  OpalElement &elem = dynamic_cast<OpalElement &>(*Element::find(nam1));
643  a.Type_elm = elem.getBaseObject()->getOpalName();
644  if(a.Type_elm == "MARKER") {
645  std::vector<double> dat = Attributes::getRealArray(itsAttr[DEFAULTAPERTURE]);
646  tolerance_x = dat[0];
647  tolerance_y = dat[1];
648  offsetx = dat[2];
649  offsety = dat[3];
650  dat.erase(dat.begin(), dat.begin() + 4);
651  ShapeBeamScreen = getShape(dat);
652  } else {
653  auto vec = elem.getApert();
654 
655  tolerance_x = vec.second[0];
656  tolerance_y = vec.second[1];
657  offsetx = vec.second[2];
658  offsety = vec.second[3];
659  vec.second.erase(vec.second.begin(), vec.second.begin() + 4);
660  ShapeBeamScreen = getShape(vec.second);
661 
662  }
663  }
664 
665  if(data.l != 0) {
666  for(int j = 0; j < nslice; ++j) {
667  a.Interpol[j].delta_x = K_beta * delta_p * a.Interpol[j].Disp_x + tolerance_x + offsetx;
668  a.Interpol[j].delta_y = K_beta * delta_p * a.Interpol[j].Disp_y + tolerance_y + offsety;
669  calcul_Apert(a, j, tp);
670  }
671  } else {
672  a.Interpol[0].delta_x = K_beta * delta_p * a.Interpol[0].Disp_x + tolerance_x + offsetx;
673  a.Interpol[0].delta_y = K_beta * delta_p * a.Interpol[0].Disp_y + tolerance_y + offsety;
674  calcul_Apert(a, 0, tp);
675  for(int j = 1; j < nslice; ++j) {
676  a.Interpol[j].delta_x = a.Interpol[0].delta_x;
677  a.Interpol[j].delta_y = a.Interpol[0].delta_y;
678  a.Interpol[j].apert = a.Interpol[0].apert;
679  }
680  }
681  a.Orb = tp->getS(*i, 0, 0);
682 }
683 
684 void Aperture::calcul_Apert(A_row &a, int slice, Twiss *tp) {
685  int pt_halo = ShapeHalo.size() - 1;
686 
687  //non normalised edge of the halo induced by the the two collimators
688  double *Pn = new double[pt_halo], *Qn = new double[pt_halo];
689  double x = 0.0;
690 
691  int pt_delta(5);
692  double *Apert = new double[pt_halo*pt_delta];
693 
694  double deltax, deltay;
695 
696  for(int k = 0; k < pt_delta; ++k) {
697  deltax = a.Interpol[slice].delta_x + co * cos(k * Physics::pi / 8);
698  deltay = a.Interpol[slice].delta_y + co * sin(k * Physics::pi / 8);
699 
700  const PartData &p = beam->getReference();
701 
702  for(int i = 0; i < pt_halo; ++i) {
703  Pn[i] = sqrt(p.getM() * tp->getEX() / p.getP() * a.Interpol[slice].Beta_x) * ShapeHalo[i].x;
704  Qn[i] = sqrt(p.getM() * tp->getEY() / p.getP() * a.Interpol[slice].Beta_y) * ShapeHalo[i].y;
705  double a_d = Qn[i] / Pn[i];
706  double b_d = deltay - a_d * deltax;
707 
708  int size = ShapeBeamScreen.size();
709  for(int j = 0; j < size - 1; ++j) {
710 
711  double a_arc = (ShapeBeamScreen[j+1].y - ShapeBeamScreen[j].y) / (ShapeBeamScreen[j+1].x - ShapeBeamScreen[j].x);
712  double b_arc = (ShapeBeamScreen[j].y * ShapeBeamScreen[j+1].x - ShapeBeamScreen[j+1].y * ShapeBeamScreen[j].x) /
713  (ShapeBeamScreen[j+1].x - ShapeBeamScreen[j].x);
714 
715  x = (b_d - b_arc) / (a_arc - a_d);
716  double y = a_d * x + b_d;
717 
718  double ang = atan2(y, x);
719  double ang1 = atan2(ShapeBeamScreen[j].y, ShapeBeamScreen[j].x);
720  double ang2 = atan2(ShapeBeamScreen[j+1].y, ShapeBeamScreen[j+1].x);
721 
722  if((ang > ang1) && (ang <= ang2)) break;
723  }
724  Apert[i+k*pt_halo] = n1 * (x - deltax) / Pn[i];
725  }
726  }
727  a.Interpol[slice].apert = Apert[0];
728  for(int i = 1; i < pt_halo * pt_delta; ++i) {
729  if(a.Interpol[slice].apert > Apert[i]) a.Interpol[slice].apert = Apert[i];
730  }
731 
732  delete [] Apert;
733  delete [] Qn;
734  delete [] Pn;
735 }
736 
737 vector<Aperture::coord> Aperture::getShape(vector<double> vec) {
738  vector<coord> S;
739  coord pt;
740  double nb_pt(11);
741 
742  double r = vec[0];
743  double h = vec[1];
744  double v = vec[2];
745 
746  if((r > -1.5) && (r < -0.5)) {
747  double ang = atan2(v, h);
748  for(int i = 0; i < nb_pt; ++i) {
749  if(i *Physics::pi / 20 <= ang) {
750  pt.x = h;
751  pt.y = h * tan(i * Physics::pi / 20);
752  S.push_back(pt);
753  } else {
754  pt.x = v / tan(i * Physics::pi / 20);
755  pt.y = v;
756  S.push_back(pt);
757  }
758  }
759  } else if((r > -10.5) && (r < -9.5)) {
760  vector<double>::iterator iter = vec.begin();
761  ++iter;
762  while(iter != vec.end()) {
763  pt.x = *iter;
764  pt.y = *(iter + 1);
765  S.push_back(pt);
766  iter = iter + 2;
767  }
768  } else {
769  if((r != 0) && (h == 0) && (v == 0)) {
770  for(int i = 0; i < nb_pt; ++i) {
771  pt.x = r * cos(i * Physics::pi / 20);
772  pt.y = r * sin(i * Physics::pi / 20);
773  S.push_back(pt);
774  }
775  } else if((r != 0) && (h != 0) && (v == 0)) {
776  double ang = acos(h / r);
777  for(int i = 0; i < nb_pt; ++i) {
778  if(i *Physics::pi / 20 <= ang) {
779  pt.x = h;
780  pt.y = h * tan(i * Physics::pi / 20);
781  S.push_back(pt);
782  } else {
783  pt.x = r * cos(i * Physics::pi / 20);
784  pt.y = r * sin(i * Physics::pi / 20);
785  S.push_back(pt);
786  }
787  }
788  } else if((r != 0) && (h == 0) && (v != 0)) {
789  double ang = asin(v / r);
790  for(int i = 0; i < nb_pt; ++i) {
791  if(i *Physics::pi / 20 <= ang) {
792  pt.x = r * cos(i * Physics::pi / 20);
793  pt.y = r * sin(i * Physics::pi / 20);
794  S.push_back(pt);
795  } else {
796  pt.x = r / tan(i * Physics::pi / 20);
797  pt.y = v;
798  S.push_back(pt);
799  }
800  }
801  } else if((r != 0) && (h != 0) && (v != 0)) {
802  double ang1 = acos(h / r);
803  double ang2 = asin(v / r);
804  for(int i = 0; i < nb_pt; ++i) {
805  if(i *Physics::pi / 20 <= ang1) {
806  pt.x = h;
807  pt.y = h * tan(i * Physics::pi / 20);
808  S.push_back(pt);
809  } else if((i * Physics::pi / 20 > ang1) && (i *Physics::pi / 20 <= ang2)) {
810  pt.x = r * cos(i * Physics::pi / 20);
811  pt.y = r * sin(i * Physics::pi / 20);
812  S.push_back(pt);
813  } else { //i*Physics::pi/20>ang2
814  pt.x = r / tan(i * Physics::pi / 20);
815  pt.y = v;
816  S.push_back(pt);
817  }
818  }
819  } else { //(r=0,h!=0,v!=0) case(000)(0x0)(00x) uninteresting
820  for(int i = 0; i < nb_pt; ++i) {
821  pt.x = h * cos(i * Physics::pi / 20);
822  pt.y = v * sin(i * Physics::pi / 20);
823  S.push_back(pt);
824  }
825  }
826  }
827 
828  return S;
829 }
830 
832 
833  const std::string &beamName = Attributes::getString(itsAttr[BEAM]);
834  beam = Beam::find(beamName);
835 
836  std::vector<double> dat = Attributes::getRealArray(itsAttr[DATA]);
837  co = dat[0];
838  delta_p = dat[1];
839  K_beta = dat[2];
840  n1 = dat[3];
841  dat.erase(dat.begin(), dat.begin() + 4);
842  ShapeHalo = getShape(dat);
843 
844  //fill the table
845  fill();
847 
848  //output of the Aperture command
849  double nslice = Attributes::getReal(itsAttr[NSLICE]);
850  std::string file_out = Attributes::getString(itsAttr[FILE]);
851  ofstream outFile(file_out.c_str());
852  if(!outFile) {
853  cerr << "Aperture: unable to open output file:" << file_out << endl;
854  exit(-1);
855  }
856 
857  outFile.setf(std::ios::scientific, std::ios::floatfield);
858 
859  OPALTimer::Timer timer;
860  outFile << "@ NAME %s " << getOpalName() << endl;
861  outFile << "@ DATE %s " << timer.date() << endl;
862  outFile << "@ TIME %s " << timer.time() << endl;
863  outFile << "@ ORIGIN %s OPAL_9.5/7\n";
864  outFile << "@ COMMENT %s " << endl;
865  outFile << "@ NSLICE %e " << nslice << endl;
866 
867  outFile << "*" << setw(15) << "NAME" << setw(15) << "Type" << setw(15) << "S" << setw(15) << "L" << setw(15) << "Apert" << endl;
868  outFile << "$" << setw(15) << "%23s" << setw(15) << "%12s" << setw(15) << "%e" << setw(15) << "%e" << setw(15) << "%e" << endl;
869 
870 }
871 
873  if(refill) {
874  run();
875  refill = false;
876  }
877 }
878 
880  itsTable.erase(itsTable.begin(), itsTable.end());
881  double nslice = Attributes::getReal(itsAttr[NSLICE]);
882 
884  Table *t = Table::find(itsLine);
885  tp = dynamic_cast<Twiss *>(t);
886 
887  if(tp == 0) {
888  throw OpalException("Aperture::execute()", "Unknown Twiss Table\"" + itsLine + "\".");
889  }
890  tp->fill();
891 
892  vector<double> dat = Attributes::getRealArray(itsAttr[DEFAULTAPERTURE]);
893  if(dat.size() != 0) {
894  i = tp->begin();
895  while(i != tp->end()) {
896  const std::string nam = i->getElement()->getName();
897  if(nam == "[DRIFT]") {
898  A_row row(*i, static_cast<int>(nslice));
899  i->accept(*this);
900  calcul(i, row, static_cast<int>(nslice), tp);
901  itsTable.append(row);
902  i++;
903  } else {
904  OpalElement &elem = dynamic_cast<OpalElement &>(*Element::find(nam));
905  std::string Typ = elem.getBaseObject()->getOpalName();
906  if((elem.getApert().second.size() == 0) && (Typ != "MARKER")) i++;
907  else {
908  A_row row(*i, static_cast<int>(nslice));
909  i->accept(*this);
910  calcul(i, row, static_cast<int>(nslice), tp);
911  itsTable.append(row);
912  i++;
913  }
914  }
915  }
916 
917  } else {
918  i = tp->begin();
919  while(i != tp->end()) {
920  const std::string nam = i->getElement()->getName();
921  if(nam == "[DRIFT]") i++;
922  else {
923  OpalElement &elem = dynamic_cast<OpalElement &>(*Element::find(nam));
924  std::string Typ = elem.getBaseObject()->getOpalName();
925  if(Typ == "MARKER") i++;
926  else if(elem.getApert().second.size() == 0) i++;
927  else {
928  A_row row(*i, static_cast<int>(nslice));
929  i->accept(*this);
930  calcul(i, row, static_cast<int>(nslice), tp);
931  itsTable.append(row);
932  i++;
933  }
934  }
935  }
936  }
937 
938 }
939 
941  return *current;
942 }
943 
945  return itsTable.getElementLength();
946 }
947 
948 double Aperture::getCell(const PlaceRep &place, const std::string &colName) {
949  A_row &row = findRow(place);
950  const ColDesc *col = findCol(*this, colName);
951  return (this->*(col->get))(row, col->ind_1, col->ind_2);
952 }
953 const Beamline *Aperture::getLine() const {
954  return &itsTable;
955 }
957  CellArray columns;
958  for(const ColDesc *col = defaultColumns; col->colName; ++col) {
960  new Column(*this, col->colName, *col);
961  columns.push_back(Cell(expr, col->printWidth, col->printPrecision));
962  }
963  return columns;
964 }
965 std::vector<double> Aperture::getColumn(const RangeRep &rng, const std::string
966  &colName) {
967  const ColDesc *col = findCol(*this, colName);
968  RangeRep range(rng);
969  range.initialize();
970  std::vector<double> column;
971 
972  for(A_Tline::const_iterator row = begin(); row != end(); ++row) {
973  range.enter(*row);
974  if(range.isActive()) {
975  column.push_back((this->*(col->get))(*row, col->ind_1, col->ind_2));
976  }
977  range.leave(*row);
978  }
979 
980  return column;
981 }
982 std::vector<double> Aperture::getRow(const PlaceRep &pos, const
983  std::vector<std::string> &cols) {
984  A_row &row = findRow(pos);
985  std::vector<double> result;
986 
987  if(cols.empty()) {
988  // Standard column selection.
989  for(const ColDesc *col = defaultColumns; col->colName != 0; ++col) {
990  result.push_back((this->*col->get)(row, col->ind_1, col->ind_2));
991  }
992  } else {
993  // User column selection.
994  for(std::vector<std::string>::const_iterator iter = cols.begin();
995  iter != cols.end(); ++iter) {
996  const ColDesc *col = findCol(*this, *iter);
997  result.push_back((this->*(col->get))(row, col->ind_1, col->ind_2));
998  }
999  }
1000 
1001  return result;
1002 }
1003 bool Aperture::isDependent(const std::string &name) const {
1004  // Test if name refers to USE attribute.
1005  if(itsLine == name) return true;
1006 
1007  // Test if name occurs in table.
1008  for(A_Tline::const_iterator row = begin(); row != end(); ++row) {
1009  if(row->getElement()->getName() == name) return true;
1010  }
1011 
1012  // Otherwise replacement is not required.
1013  return false;
1014 }
1015 bool Aperture::matches(Table *rhs) const { return false; }
1017  const ColDesc *col = findCol(*this, colname);
1018  return new Column(*this, colname, *col);
1019 }
1020 Object *Aperture::clone(const std::string &name) {
1021  return new Aperture(name, this);
1022 }
1023 
1024 void Aperture::printTable(std::ostream &, const CellArray &)const {};
1025 
1027  PlaceRep row(place);
1028  row.initialize();
1029 
1030  for(A_Tline::iterator i = begin(); i != end(); ++i) {
1031  row.enter(*i);
1032  if(row.isActive()) return *i;
1033  row.leave(*i);
1034  }
1035 
1036  std::ostringstream os;
1037  os << row << std::ends;
1038  throw OpalException("Aperture::findRow()", "A_row \"" + os.str() +
1039  "\" not found in twiss table \"" + getOpalName() + "\".");
1040 }
virtual std::vector< double > getRow(const PlaceRep &pos, const std::vector< std::string > &cols)
Return a table row.
Definition: Aperture.cpp:982
virtual double getExitFaceRotation() const =0
Get exit pole face rotation.
std::vector< Cell > CellArray
An array of cell descriptors.
Definition: Table.h:63
void calcul_Apert(A_row &a, int slice, Twiss *tp)
Definition: Aperture.cpp:684
virtual BMultipoleField & getField() override=0
Get multipole expansion of field.
A scalar expression.
Definition: Expressions.h:79
virtual void fill()=0
Refill the buffer.
double courb
Definition: Aperture.h:23
double getBeta_y(int ind)
Definition: Aperture.cpp:213
double getDisp_y_prim(int ind)
Definition: Aperture.cpp:226
virtual Expressions::PtrToScalar< double > makeColumnExpression(const std::string &colname) const
Definition: Aperture.cpp:1016
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
bool refill
Refill flag.
Definition: Table.h:158
double getOrb()
Definition: Aperture.cpp:235
PETE_TUTree< FnArcCos, typename T::PETE_Expr_t > acos(const PETE_Expr< T > &l)
Definition: PETE.h:808
constexpr double e
The value of .
Definition: Physics.h:40
Twiss * tp
Definition: Aperture.h:156
Interface for basic beam line object.
Definition: ElementBase.h:128
double getDisp_x_prim(int ind)
Definition: Aperture.cpp:220
TLine::const_iterator end() const
Access to last row.
Definition: Twiss.cpp:561
double normal(int) const
Get component.
virtual BMultipoleField & getField() override=0
Get multipole expansion of field.
A templated representation for matrices.
Definition: IdealMapper.h:26
double getEY() const
Return emittance for mode 2.
Definition: Twiss.cpp:684
virtual void visitSBend(const SBend &)
Apply the algorithm to a sector bend.
Definition: Aperture.cpp:329
virtual BMultipoleField & getField() override=0
Get multipole field.
A_row & findRow(const PlaceRep &row)
Definition: Aperture.cpp:1026
T det(const AntiSymTenzor< T, 3 > &t)
Interface for a Cyclotron.
Definition: Cyclotron.h:91
TLine::const_iterator begin() const
Access to first row.
Definition: Twiss.cpp:551
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:123
void leave(const FlaggedElmPtr &) const
Leave an element or line.
Definition: RangeRep.cpp:81
A simple arc in the XZ plane.
double tolerance_y
Definition: Aperture.h:30
The base class for all OPAL exceptions.
Definition: OpalException.h:28
std::string getType_elm()
Definition: Aperture.cpp:232
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
A_Tline itsTable
Definition: Aperture.h:153
const A_row & getCurrent() const
Definition: Aperture.cpp:940
#define ERRORMSG(msg)
Definition: IpplInfo.h:399
void execute()
Apply the algorithm to the top-level beamline.
Definition: Aperture.cpp:831
double co
Definition: Aperture.h:28
virtual bool isDependent(const std::string &name) const
Find out if table depends on the object identified by [b]name[/b].
Definition: Aperture.cpp:1003
virtual double getElementLength() const
Get design length.
Definition: TBeamline.h:311
void enter(const FlaggedElmPtr &) const
Enter an element or line.
Definition: RangeRep.cpp:71
Particle reference data.
Definition: PartData.h:38
double k0s
Definition: Aperture.h:23
double offsetx
Definition: Aperture.h:30
Definition: RBend.h:73
virtual PlanarArcGeometry & getGeometry() override=0
Get SBend geometry.
virtual const std::string & getName() const
Get element name.
Definition: ElementBase.cpp:95
double tolerance_x
Definition: Aperture.h:30
Tps< T > tan(const Tps< T > &x)
Tangent.
Definition: TpsMath.h:147
virtual double getEntryFaceRotation() const =0
Get pole entry face rotation.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
void run()
Definition: Aperture.cpp:879
std::pair< ElementBase::ApertureType, std::vector< double > > getApert() const
bool isActive() const
Return status.
Definition: PlaceRep.cpp:98
double e1
Definition: Aperture.h:23
bool dynamic
Flag dynamic table.
Definition: Table.h:153
Default algorithms.
double kq
Definition: Aperture.h:23
double n1
Definition: Aperture.h:28
Twiss::TLine::iterator i
Definition: Aperture.h:157
Interface for general multipole.
Definition: Multipole.h:46
std::string date() const
Return date.
Definition: Timer.cpp:35
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
A_Tline::const_iterator begin() const
Definition: Aperture.cpp:244
bool isActive() const
Test for active range.
Definition: RangeRep.cpp:66
Tps< T > cosh(const Tps< T > &x)
Hyperbolic cosine.
Definition: TpsMath.h:222
virtual double getExitFaceRotation() const =0
Get exit pole face rotation.
double getBendAngle() const
Get angle.
const Object * getBaseObject() const
Return the object&#39;s base type object.
Definition: Object.cpp:277
Representation of a place within a beam line or sequence.
Definition: PlaceRep.h:41
std::string itsLine
Definition: Aperture.h:174
double getBETXMAX(const A_row &, int i1=0, int i2=0) const
Definition: Aperture.cpp:254
virtual double getLength()
Return the length of the table.
Definition: Aperture.cpp:944
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
void initialize()
Initialise data for search.
Definition: RangeRep.cpp:55
FVector< double, 3 > Euler_x
Definition: Aperture.h:163
A_Tline::const_iterator current
Definition: Aperture.h:172
virtual std::vector< double > getColumn(const RangeRep &rng, const std::string &colName)
Return column [b]col[/b] of this table, limited by [b]range[/b].
Definition: Aperture.cpp:965
constexpr double pi
The value of .
Definition: Physics.h:31
virtual void visitCyclotron(const Cyclotron &)
Apply the algorithm to an cyclotron.
Definition: Aperture.cpp:324
virtual const Beamline * getLine() const
Return embedded CLASSIC beamline.
Definition: Aperture.cpp:953
double offsety
Definition: Aperture.h:30
double skew(int) const
Get component.
std::string Type_elm
Definition: Aperture.h:67
struct Aperture::Data data
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:511
double l
Definition: Aperture.h:23
FMatrix< double, 6, 6 > Transf_mat
Definition: Aperture.h:160
void enter(const FlaggedElmPtr &) const
Enter an element or line.
Definition: PlaceRep.cpp:70
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
std::vector< Aperture::coord > getShape(std::vector< double > vec)
Definition: Aperture.cpp:737
static Beam * find(const std::string &name)
Find named BEAM.
Definition: Beam.cpp:150
const Beam * beam
Definition: Aperture.h:155
A_Tline::const_iterator end() const
Definition: Aperture.cpp:250
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
Base class for all beam line elements.
Definition: OpalElement.h:41
Definition: SBend.h:68
static Table * find(const std::string &name)
Find named Table.
Definition: Table.cpp:41
double phi
Definition: Aperture.h:23
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:258
double Orb
Definition: Aperture.h:68
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 getDisp_x(int ind)
Definition: Aperture.cpp:217
double getBETi(const Row &, int i1, int=0) const
Definition: Twiss.cpp:1111
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
std::vector< coord > ShapeHalo
Definition: Aperture.h:38
virtual void fill()
Refill the buffer.
Definition: Aperture.cpp:872
void initialize()
Initialise data for search.
Definition: PlaceRep.cpp:64
Representation of a range within a beam line or sequence.
Definition: RangeRep.h:34
void leave(const FlaggedElmPtr &) const
Leave an element or line.
Definition: PlaceRep.cpp:84
virtual double getElementLength() const
Get element length.
Class Twiss.
Definition: Twiss.h:41
An abstract sequence of beam line components.
Definition: Beamline.h:37
virtual double getElementLength() const
Get element length.
FVector< double, 2 > Dispx
Definition: Aperture.h:167
double getDisp(const Row &, int i1, int=0) const
Dispersion.
Definition: Twiss.cpp:1234
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
virtual double getEntryFaceRotation() const =0
Get pole entry face rotation.
double K_beta
Definition: Aperture.h:28
The geometry for a RBend element.
Definition: RBendGeometry.h:41
virtual void visitMultipole(const Multipole &)
Apply the algorithm to a multipole.
Definition: Aperture.cpp:287
double getP() const
The constant reference momentum per particle.
Definition: PartData.h:117
static Element * find(const std::string &name)
Find named Element.
Definition: Element.cpp:37
double getDisp_y(int ind)
Definition: Aperture.cpp:223
std::vector< pt_interpol > Interpol
Definition: Aperture.h:78
Definition: Vec.h:21
double e2
Definition: Aperture.h:23
virtual void applyDefault(const ElementBase &)
Definition: Aperture.cpp:350
The magnetic field of a multipole.
std::string time() const
Return time.
Definition: Timer.cpp:42
double getEX() const
Return emittance for mode 1.
Definition: Twiss.cpp:679
const PartData & getReference() const
Return the embedded CLASSIC PartData.
Definition: Beam.cpp:183
virtual Object * clone(const std::string &name)
Return a clone.
Definition: Aperture.cpp:1020
double getM() const
The constant mass per particle.
Definition: PartData.h:112
The base class for all OPAL objects.
Definition: Object.h:48
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
Descriptor for printing a table cell.
Definition: Table.h:47
double getBETYMAX(const A_row &, int i1=0, int i2=0) const
Definition: Aperture.cpp:264
double delta_p
Definition: Aperture.h:28
virtual void append(const T &)
Append a T object.
Definition: TBeamline.h:434
virtual double getCell(const PlaceRep &place, const std::string &colName)
Return value in selected table cell.
Definition: Aperture.cpp:948
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:253
PETE_TUTree< FnArcSin, typename T::PETE_Expr_t > asin(const PETE_Expr< T > &l)
Definition: PETE.h:809
std::vector< coord > ShapeBeamScreen
Definition: Aperture.h:37
virtual RBendGeometry & getGeometry() override=0
Get RBend geometry.
virtual double getBendAngle() const
Get angle.
double getBeta_x(int ind)
Definition: Aperture.cpp:210
std::string::iterator iterator
Definition: MSLang.h:16
double getAPERTMIN(const A_row &row, int i1=0, int i2=0) const
Definition: Aperture.cpp:275
FVector< double, 2 > Dispy
Definition: Aperture.h:168
virtual CellArray getDefault() const
Return the default print columns.
Definition: Aperture.cpp:956
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
virtual bool matches(Table *rhs) const
Check that [b]rhs[/b] is of same type as [b]this[/b].
Definition: Aperture.cpp:1015
The base class for all OPAL tables.
Definition: Table.h:42
FVector< double, 3 > Euler_y
Definition: Aperture.h:164
#define K
Definition: integrate.cpp:118
std::string type
Definition: Aperture.h:24
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
ElementBase * getElement() const
Get the element pointer.
Definition: ElmPtr.h:58
virtual void printTable(std::ostream &, const CellArray &) const
Print list for the table.
Definition: Aperture.cpp:1024
double getApert(int ind)
Definition: Aperture.cpp:229
double getALFi(const Row &, int i1, int=0) const
Definition: Twiss.cpp:1137
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
void calcul(Twiss::TLine::iterator i, A_row &a, int order, Twiss *tp)
Definition: Aperture.cpp:360
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:95
double getS(const Row &, int=0, int=0) const
Arc length for given row.
Definition: Twiss.cpp:1101
Tps< T > sinh(const Tps< T > &x)
Hyperbolic sine.
Definition: TpsMath.h:204
virtual void visitRBend(const RBend &)
Apply the algorithm to a rectangular bend.
Definition: Aperture.cpp:302
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
A section of a beam line.
Definition: FlaggedElmPtr.h:36
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307