OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Insertion.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Insertion.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2.4.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: Insertion
10 // The class for the OPAL TWISSTRACK command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2004/11/12 20:10:11 $
15 // $Author: adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Tables/Insertion.h"
22 #include "Algorithms/Mapper.h"
23 #include "Attributes/Attributes.h"
25 #include "FixedAlgebra/FMatrix.h"
26 #include "FixedAlgebra/FVector.h"
27 #include "FixedAlgebra/FTps.h"
28 #include "FixedAlgebra/LinearMap.h"
29 #include "Structure/Beam.h"
31 #include <iomanip>
32 #include <iostream>
33 
34 using std::setw;
35 
36 
37 // Class Insertion
38 // ------------------------------------------------------------------------
39 
41  Twiss(SIZE, "TWISSTRACK",
42  "The \"TWISSTRACK\" command defines a table of lattice functions\n"
43  "which can be matched or tabulated for an insertion.") {
45  ("INIT", "If given, this table position is used to initialise\n"
46  "\t\t\t\tif not given, use the following parameters to initialise");
48  ("BETX", "Initial horizontal beta", 1.0);
50  ("ALFX", "Initial horizontal alpha");
52  ("BETY", "Initial vertical beta", 1.0);
54  ("ALFY", "Initial vertical alpha");
56  ("DX", "Initial horizontal dispersion");
58  ("DPX", "Initial slope of horizontal dispersion");
60  ("DY", "Initial vertical dispersion");
62  ("DPY", "Initial slope of vertical dispersion");
64  ("XC", "Initial horizontal position");
66  ("PXC", "Initial horizontal slope");
68  ("YC", "Initial vertical position");
70  ("PYC", "Initial vertical slope");
72  ("TC", "Initial time difference");
74  ("PTC", "Initial relative momentum error");
75 
76  // READ ONLY.
78  ("LENGTH", "Total length in m");
79  itsAttr[LENGTH].setReadOnly(true);
80 
82  ("MU1", "Phase for mode 1");
83  itsAttr[MU1].setReadOnly(true);
84 
86  ("MU2", "Phase for mode 2");
87  itsAttr[MU2].setReadOnly(true);
88 
90  ("MU3", "Phase for mode 3");
91  itsAttr[MU3].setReadOnly(true);
92 
94  ("DELTAP", "Differential momentum variation");
95  itsAttr[DELTAP].setReadOnly(true);
96 
98 }
99 
100 
101 Insertion::Insertion(const std::string &name, Insertion *parent):
102  Twiss(name, parent)
103 {}
104 
105 
107 {}
108 
109 
110 Insertion *Insertion::clone(const std::string &name) {
111  return new Insertion(name, this);
112 }
113 
114 
116  if(refill) {
117  // Set truncation order.
119 
120  // Reset the mapper.
121  if(itsAttr[INIT]) {
123  Table *init = Table::find(rowrep.getTabName());
124 
125  if(matches(init)) {
126  PlaceRep pinit = rowrep.getPosition();
127  Twiss *tinit = dynamic_cast<Twiss *>(init);
128  Row &row = tinit->findRow(pinit);
129  tinit->fill();
130  orbit = tinit->getOrbit(row);
131  curly_A = tinit->getCurlyA(row);
133  } else {
134  throw OpalException("Insertion::fill()",
135  "Table \"" + rowrep.getTabName() +
136  "\" is not suitable for initialising insertion \"" +
137  getOpalName() + "\".");
138  }
139  } else {
141  for(int i = 0; i < 6; ++i) B(i, i) = H(i, i) = 1.0;
142 
143  // Betatron matrix.
144  B(0, 0) = sqrt(Attributes::getReal(itsAttr[BETX]));
145  B(1, 1) = 1.0 / B(0, 0);
146  B(1, 0) = - Attributes::getReal(itsAttr[ALFX]) * B(1, 1);
147  B(2, 2) = sqrt(Attributes::getReal(itsAttr[BETY]));
148  B(3, 3) = 1.0 / B(2, 2);
149  B(3, 2) = - Attributes::getReal(itsAttr[ALFY]) * B(3, 3);
150  B(4, 4) = 1.0;
151  B(5, 5) = 1.0;
152 
153  // Dispersion matrix.
154  H(0, 5) = Attributes::getReal(itsAttr[DX]);
155  H(1, 5) = Attributes::getReal(itsAttr[DPX]);
156  H(2, 5) = Attributes::getReal(itsAttr[DY]);
157  H(3, 5) = Attributes::getReal(itsAttr[DPY]);
158  H(4, 0) = - H(1, 5);
159  H(4, 1) = H(0, 5);
160  H(4, 2) = - H(3, 5);
161  H(4, 3) = H(2, 5);
162 
163  curly_A = H * B;
171  }
172 
173  put();
174  refill = false;
175 
176  // Fill in the read-only data.
177  const Row &row = itsTable->back();
178  double arc = getS(row);
183  }
184 }
185 
186 
187 void Insertion::printTable(std::ostream &os, const CellArray &cells) const {
188  // Save the formatting flags.
189  std::streamsize old_prec = os.precision(6);
190  os.setf(std::ios::fixed, std::ios::floatfield);
191 
192  // Print table header.
193  printTableTitle(os, "Track lattice functions");
194 
195  // Print table body.
196  printTableBody(os, cells);
197 
198  // Write table specific summary.
199  const Row &row = itsTable->back();
200  os << "Insert length = " << setw(16) << getS(row)
201  << " Mux = " << setw(16) << getMUi(row, 0)
202  << " Muy = " << setw(16) << getMUi(row, 1)
203  << '\n'
204  << " "
205  << " BetaX(max) = " << setw(16) << Attributes::getReal(itsAttr[BETXMAX])
206  << " BetaY(max) = " << setw(16) << Attributes::getReal(itsAttr[BETYMAX]) << '\n'
207  << " "
208  << " x(max) = " << setw(16) << Attributes::getReal(itsAttr[XCMAX])
209  << " y(max) = " << setw(16) << Attributes::getReal(itsAttr[YCMAX]) << '\n'
210  << " "
211  << " x(rms) = " << setw(16) << Attributes::getReal(itsAttr[XCRMS])
212  << " y(rms) = " << setw(16) << Attributes::getReal(itsAttr[YCRMS]) << '\n'
213  << " "
214  << " Dx(max) = " << setw(16) << Attributes::getReal(itsAttr[DXMAX])
215  << " Dy(max) = " << setw(16) << Attributes::getReal(itsAttr[DYMAX]) << '\n'
216  << " "
217  << " Dx(rms) = " << setw(16) << Attributes::getReal(itsAttr[DXRMS])
218  << " Dy(rms) = " << setw(16) << Attributes::getReal(itsAttr[DYRMS]) << '\n';
219 
220  // Restore the formatting flags.
221  os.precision(old_prec);
222  os.setf(std::ios::fixed, std::ios::floatfield);
223 }
void setReal(Attribute &attr, double val)
Set real value.
Definition: Attributes.cpp:236
std::vector< Cell > CellArray
An array of cell descriptors.
Definition: Table.h:63
virtual bool matches(Table *rhs) const
Check compatibility.
Definition: Twiss.cpp:781
virtual void fill()=0
Refill the buffer.
bool refill
Refill flag.
Definition: Table.h:158
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Row & findRow(const PlaceRep &row)
Definition: Twiss.cpp:861
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
Representation of a table row reference.
Definition: TableRowRep.h:36
TableRowRep getTableRow(const Attribute &attr)
Get table row value.
Definition: Attributes.cpp:442
TLine * itsTable
Definition: Twiss.h:290
virtual void printTable(std::ostream &, const CellArray &) const
Print the table on an ASCII stream.
Definition: Insertion.cpp:187
void printTableBody(std::ostream &, const CellArray &) const
Print the body to this TWISS table.
Definition: Twiss.cpp:786
virtual void fill()
Fill the buffer using the defined algorithm.
Definition: Insertion.cpp:115
Representation of a place within a beam line or sequence.
Definition: PlaceRep.h:41
virtual Insertion * clone(const std::string &name)
Make clone.
Definition: Insertion.cpp:110
FMatrix< double, 6, 6 > curly_A
The initial curly A matrix.
Definition: Twiss.h:272
virtual ~Insertion()
Definition: Insertion.cpp:106
Insertion()
Exemplar construction.
Definition: Insertion.cpp:40
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
double getMUi(const Row &, int i1, int=0) const
Three modes, &quot;naive&quot; Twiss functions.
Definition: Twiss.cpp:1106
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
static Table * find(const std::string &name)
Find named Table.
Definition: Table.cpp:41
FVector< double, 6 > orbit
The initial closed orbit.
Definition: Twiss.h:269
virtual void setMap(const LinearMap< double, 6 > &)=0
Reset the linear part of the accumulated map for restart.
Class Twiss.
Definition: Twiss.h:41
PlaceRep getPosition() const
Return the row position representation.
Definition: TableRowRep.cpp:57
Attribute makeTableRow(const std::string &name, const std::string &help)
Create a table row attribute.
Definition: Attributes.cpp:437
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
Structure for a row of the Twiss table.
Definition: Twiss.h:49
AbstractMapper * itsMapper
Definition: Twiss.h:293
static void setGlobalTruncOrder(int order)
Set the global truncation order.
Definition: FTps.hpp:419
const std::string name
int order
Definition: Twiss.h:302
void printTableTitle(std::ostream &, const char *title) const
Print standard information about the TWISS table.
Definition: Twiss.cpp:847
FMatrix< double, 6, 6 > getCurlyA() const
Return initial curly A matrix.
Definition: Twiss.cpp:669
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
FVector< double, 6 > getOrbit() const
Return initial closed orbit.
Definition: Twiss.cpp:714
const std::string & getTabName() const
Return the table name.
Definition: TableRowRep.cpp:52
The TWISSTRACK command.
Definition: Insertion.h:28
The base class for all OPAL tables.
Definition: Table.h:42
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
double getS(const Row &, int=0, int=0) const
Arc length for given row.
Definition: Twiss.cpp:1101
void put()
Definition: Twiss.cpp:878