OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Dynamic.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Dynamic.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: Dynamic
10 // The class for the OPAL DYNAMIC command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2001/08/13 15:19:44 $
15 // $Author: jowett $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "PhysicsActions/Dynamic.h"
22 #include "Algorithms/LieMapper.h"
23 #include "Attributes/Attributes.h"
27 #include "FixedAlgebra/FTps.h"
28 #include "Physics/Physics.h"
29 #include "Structure/Beam.h"
31 #include "Utilities/Round.h"
32 #include <cmath>
33 #include <fstream>
34 #include <iomanip>
35 #include <iostream>
36 using namespace std;
37 using std::complex;
38 
39 
40 // Class Dynamic
41 // ------------------------------------------------------------------------
42 
43 // The attributes of class Dynamic.
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, "DYNAMIC",
57  "The \"DYNAMIC\" command analyses a dynamic 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", "DYNAMIC");
65  ("ORDER", "Order of the analysis; must be at least 2", 6.0);
66 
68 }
69 
70 
71 Dynamic::Dynamic(const std::string &name, Dynamic *parent):
72  Action(name, parent)
73 {}
74 
75 
77 {}
78 
79 
80 Dynamic *Dynamic::clone(const std::string &name) {
81  return new Dynamic(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("Dynamic::execute()",
95  "Unable to open file \"" + file + "\".");
96  }
97 
98  // Reference for beam.
99  const PartData &reference = beam->getReference();
100 
101  // Compute transfer map.
102  int order = std::max(int(Round(Attributes::getReal(itsAttr[ORDER]))), 1);
104  LieMapper mapper(*use->fetchLine(), reference, false, false, order);
105  mapper.execute();
106  DragtFinnMap<3> map;
107  mapper.getMap(map);
108  os << "Accumulated map:\n" << map;
109 
110  // Find fixed point.
111  FVector<double, 6> fixedPoint;
112  DragtFinnMap<3> closedOrbitMap;
113  map.dynamicFixedPoint(fixedPoint, closedOrbitMap);
114  std::streamsize old_prec = os.precision(12);
115  os << "Fixed point:\n";
116  for(int i = 0; i < 6; i++) {
117  os << std::setw(24) << fixedPoint[i];
118  }
119  os << "\nMap around fixed point:\n";
120  os << closedOrbitMap;
121 
122  // Print normal form.
123  // const DragtFinnNormalForm<3> normal(map);
124  // const FVector<complex<double>,6> &lambda = normal.eigenValues();
125 
126  // 21-06-2000 remove const in order to hope KCC likes it ....!
127  DragtFinnNormalForm<3> normal(map);
128  const FVector<complex<double>, 6> &lambda = normal.eigenValues();
129 
130  os << "\nEigenvalues of the linear map:\n";
131 
132  for(int i = 0; i < 6; i++) {
133  os << lambda[i] << '\n';
134  }
135 
136  os << "\nFactorised Lie transformation script(N) for normal form map:\n"
137  << normal.normalForm();
138 
139  os << "\nFactorised Lie Transformation script(A) for normalising map:\n"
140  << normal.normalisingMap();
141 
142  // Print fractional tunes.
143  int freedom = normal.degreesOfFreedom();
144  os << "\nFractional tunes:\n";
145  for(int mode = 0; mode < freedom; mode++) {
146  os << std::setw(24) << std::arg(lambda[2*mode]) / Physics::two_pi;
147  }
148  os << '\n';
149 
150  // Print logarithmic excitation constants.
151  os << "\nExcitation constants:\n";
152  for(int mode = 0; mode < freedom; mode++) {
153  os << std::setw(24) << log(std::norm(lambda[2*mode])) / 2.0;
154  }
155  os << '\n';
156 
157  // Normalised anharmonicities.
158  {
159  FMatrix<double, 3, 3> QQ = normal.anharmonicity();
160  os << "\nNormalised anharmonicites:\n";
161 
162  for(int mode1 = 1; mode1 <= freedom; mode1++) {
163  for(int mode2 = mode1; mode2 <= freedom; mode2++) {
164  os << "dQ" << mode1 << "/dE" << mode2 << " = "
165  << std::setw(24) << QQ(mode1 - 1, mode2 - 1) << '\n';
166  }
167  }
168  }
169 
170  // Invariant polynomials.
171  for(int mode = 1; mode <= freedom; mode++) {
172  os << "\nInvariant polynomial for mode " << mode << ":\n"
173  << normal.invariant(mode - 1);
174  }
175 
176  os << std::flush;
177  os.precision(old_prec);
178 }
double Round(double value)
Round the double argument.
Definition: Round.cpp:23
virtual void execute()
Execute the command.
Definition: Dynamic.cpp:85
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
virtual ~Dynamic()
Definition: Dynamic.cpp:76
int degreesOfFreedom() const
Get number of stable degrees of freedom.
static BeamSequence * find(const std::string &name)
Find a BeamSequence by name.
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.
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 Beamline * fetchLine() const =0
Return the embedded CLASSIC beam line.
virtual Dynamic * clone(const std::string &name)
Make clone.
Definition: Dynamic.cpp:80
arg(a))
virtual void execute()
Apply the algorithm to the top-level beamline.
The base class for all OPAL beam lines and sequences.
Definition: BeamSequence.h:32
Dynamic()
Exemplar constructor.
Definition: Dynamic.cpp:55
const PartData & getReference() const
Return the embedded CLASSIC PartData.
Definition: Beam.cpp:183
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
void dynamicFixedPoint(FVector< double, 2 *N > &fp, DragtFinnMap &map)
Compute dynamic fixed point.
Definition: DragtFinnMap.h:835
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
The DYNAMIC command.
Definition: Dynamic.h:28
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.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307