OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Static.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Static.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: Static
10 // The class for the OPAL STATIC command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2001/08/13 15:22:04 $
15 // $Author: jowett $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "PhysicsActions/Static.h"
23 #include "Algorithms/LieMapper.h"
24 #include "Attributes/Attributes.h"
27 #include "FixedAlgebra/FStaticFP.h"
28 #include "FixedAlgebra/FTps.h"
29 #include "Physics/Physics.h"
30 #include "Structure/Beam.h"
32 #include "Utilities/Round.h"
33 #include <fstream>
34 #include <iomanip>
35 #include <iostream>
36 
37 using std::complex;
38 
39 
40 // Class Static
41 // ------------------------------------------------------------------------
42 
43 // The attributes of class Static.
44 namespace {
45  enum {
46  LINE, // The lattice to be used.
47  BEAM, // The beam to be used.
48  FNAME, // The name of the output file.
49  ORDER, // The desired order.
50  SIZE
51  };
52 }
53 
54 
56  Action(SIZE, "STATIC",
57  "The \"STATIC\" command analyses a static transfer map.") {
59  ("LINE", "Name of the lattice to be analysed");
61  ("BEAM", "Name of the beam to be used");
63  ("FILE", "Name of the file to be written", "STATIC");
65  ("ORDER", "Order of the analysis; must be at least 2", 2.0);
66 
68 }
69 
70 
71 Static::Static(const std::string &name, Static *parent):
72  Action(name, parent)
73 {}
74 
75 
77 {}
78 
79 
80 Static *Static::clone(const std::string &name) {
81  return new Static(name, this);
82 }
83 
84 
86  // Find BeamSequence and Beam definitions.
89 
90  // Open output file.
91  std::string file = Attributes::getString(itsAttr[FNAME]);
92  std::ofstream os(file.c_str());
93  if(os.bad()) {
94  throw OpalException("Static::execute()",
95  "Unable to open file \"" + file + "\".");
96  }
97 
98  // Reference attribute.
99  const PartData &reference = beam->getReference();
100 
101  // Compute transfer map.
102  // JMJ comment: minimum sensible order is 2
103  int order = std::max(int(Round(Attributes::getReal(itsAttr[ORDER]))), 2);
104  LieMapper mapper(*use->fetchLine(), reference, false, false, order);
106  std::cout << "mapper.execute(); start " << std::endl;
107  mapper.execute();
108  std::cout << "mapper.execute(); done " << std::endl;
109  DragtFinnMap<3> map;
110  mapper.getMap(map);
111  os << "Accumulated map:\n" << map;
112  std::cout << "Accumulated map done " << std::endl;
113 
114  // Print fixed point and map around it.
115  std::streamsize old_prec = os.precision(12);
116  FVector<double, 6> fixedPoint;
117  DragtFinnMap<3> dispersionMap;
118  {
119  DragtFinnMap<3> temp;
120  map.staticFixedPoint(fixedPoint, temp);
121  temp.removeDispersion(dispersionMap, map);
122  }
123  os << "Fixed point:\n";
124  for(int i = 0; i < 4; i++) {
125  os << std::setw(24) << fixedPoint[i];
126  }
127  os << "\nDispersion map:\n" << dispersionMap
128  << "\nMap with dispersion removed:\n" << map;
129 
130  // Print normal form.
131  // const DragtFinnNormalForm<3> normal(map);
132  // const FVector<complex<double>,6> &lambda = normal.eigenValues();
133 
134  // 21-06-2000, remove const
135  DragtFinnNormalForm<3> normal(map);
136  const FVector<complex<double>, 6> &lambda = normal.eigenValues();
137  os << "\nEigenvalues of the linear map:\n";
138 
139  for(int i = 0; i < 4; i++) {
140  os << lambda[i] << '\n';
141  }
142 
143  os << "\nFactorised Lie transformation script(N) for normal form map:\n"
144  << normal.normalForm();
145 
146  os << "\nFactorised Lie Transformation script(A) for normalising map:\n"
147  << normal.normalisingMap();
148 
149  // Print fractional tunes.
150  int freedom = normal.degreesOfFreedom();
151  os << "\nFractional tunes:\n";
152  for(int mode = 0; mode < freedom; mode++) {
153  os << std::setw(24) << std::arg(lambda[2*mode]) / Physics::two_pi;
154  }
155  os << '\n';
156 
157  // Print logarithmic excitation constants.
158  os << "\nExcitation constants:\n";
159  for(int mode = 0; mode < freedom; mode++) {
160  os << std::setw(24) << log(std::norm(lambda[2*mode])) / 2.0;
161  }
162  os << '\n';
163 
164  // Normalised anharmonicities.
165  {
166  FMatrix<double, 3, 3> QQ = normal.anharmonicity();
167  os << "\nNormalised anharmonicites:\n";
168 
169  for(int mode1 = 1; mode1 <= freedom; mode1++) {
170  for(int mode2 = mode1; mode2 <= freedom; mode2++) {
171  os << "dQ" << mode1 << "/dE" << mode2 << " = "
172  << std::setw(24) << QQ(mode1 - 1, mode2 - 1) << '\n';
173  }
174  }
175 
176  // Invariant polynomials.
177  for(int mode = 1; mode <= freedom; mode++) {
178  os << "\nInvariant polynomial for mode " << mode << ":\n"
179  << normal.invariant(mode - 1);
180  }
181 
182  os << std::flush;
183  }
184 
185  os.precision(old_prec);
186 }
double Round(double value)
Round the double argument.
Definition: Round.cpp:23
virtual Static * clone(const std::string &name)
Make clone.
Definition: Static.cpp:80
Build a Lie-algebraic map using a finite-length lens for each elements.
Definition: LieMapper.h:60
MMatrix< m_complex > complex(MMatrix< double > real)
Definition: MMatrix.cpp:407
A templated representation for matrices.
Definition: IdealMapper.h:26
The base class for all OPAL actions.
Definition: Action.h:30
FLieGenerator< double, N > invariant(int i) const
Get invariant polynomial for mode i.
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:123
The base class for all OPAL exceptions.
Definition: OpalException.h:28
constexpr double two_pi
The value of .
Definition: Physics.h:34
Particle reference data.
Definition: PartData.h:38
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
Tps< T > log(const Tps< T > &x)
Natural logarithm.
Definition: TpsMath.h:182
int degreesOfFreedom() const
Get number of stable degrees of freedom.
static BeamSequence * find(const std::string &name)
Find a BeamSequence by name.
virtual void execute()
Execute the command.
Definition: Static.cpp:85
const DragtFinnMap< N > & normalisingMap() const
Get normalising map as a Lie transform.
Normal form of a truncated Taylor series map.
const FVector< std::complex< double >, 2 *N > & eigenValues() const
Get eigenvalues of the linear part as a complex vector.
void removeDispersion(DragtFinnMap &dm, DragtFinnMap &map)
Split map into dispersion map and non-dispersive part.
Definition: DragtFinnMap.h:892
static Beam * find(const std::string &name)
Find named BEAM.
Definition: Beam.cpp:150
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
FMatrix< double, N, N > anharmonicity() const
Get anharmonicities as a matrix.
virtual ~Static()
Definition: Static.cpp:76
virtual Beamline * fetchLine() const =0
Return the embedded CLASSIC beam line.
Static()
Exemplar constructor.
Definition: Static.cpp:55
arg(a))
int precision() const
Definition: Inform.h:115
The base class for all OPAL beam lines and sequences.
Definition: BeamSequence.h:32
The STATIC command.
Definition: Static.h:28
const PartData & getReference() const
Return the embedded CLASSIC PartData.
Definition: Beam.cpp:183
void staticFixedPoint(FVector< double, 2 *N > &fp, DragtFinnMap &map)
Compute static fixed point.
Definition: DragtFinnMap.h:858
The BEAM definition.
Definition: Beam.h:35
static void setGlobalTruncOrder(int order)
Set the global truncation order.
Definition: FTps.hpp:419
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
const DragtFinnMap< N > & normalForm() const
Get normal-form map as a Lie transform.
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307