OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalBeamline.cpp
Go to the documentation of this file.
2 
3 #include "Utilities/Options.h"
4 #include "Utilities/Util.h"
6 #include "AbsBeamline/Bend2D.h"
8 
9 #include <boost/filesystem.hpp>
10 #include <boost/regex.hpp>
11 #include <fstream>
12 
14  elements_m(),
15  prepared_m(false),
16  containsSource_m(false)
17 {
18 }
19 
21  const Quaternion& rotation):
22  elements_m(),
23  prepared_m(false),
24  containsSource_m(false),
25  coordTransformationTo_m(origin, rotation)
26 {
27 }
28 
30  elements_m.clear();
31 }
32 
33 std::set<std::shared_ptr<Component>> OpalBeamline::getElements(const Vector_t &x) {
34  std::set<std::shared_ptr<Component> > elementSet;
35  FieldList::iterator it = elements_m.begin();
36  const FieldList::iterator end = elements_m.end();
37  for (; it != end; ++ it) {
38  std::shared_ptr<Component> element = (*it).getElement();
39  Vector_t r = (*it).getCoordTransformationTo().transformTo(x);
40 
41  if (element->isInside(r)) {
42  elementSet.insert(element);
43  }
44  }
45 
46  return elementSet;
47 }
48 
49 unsigned long OpalBeamline::getFieldAt(const unsigned int &index, const Vector_t &pos, const long &sindex, const double &t, Vector_t &E, Vector_t &B) {
50 
51  unsigned long rtv = 0x00;
52 
53  return rtv;
54 }
55 
56 unsigned long OpalBeamline::getFieldAt(const Vector_t &position,
57  const Vector_t &momentum,
58  const double &t,
59  Vector_t &Ef,
60  Vector_t &Bf) {
61  unsigned long rtv = 0x00;
62 
63  std::set<std::shared_ptr<Component>> elements = getElements(position);
64 
65  std::set<std::shared_ptr<Component>>::const_iterator it = elements.begin();
66  const std::set<std::shared_ptr<Component>>::const_iterator end = elements.end();
67 
68  for (; it != end; ++ it) {
69  ElementBase::ElementType type = (*it)->getType();
70  if (type == ElementBase::MONITOR ||
71  type == ElementBase::MARKER ||
72  type == ElementBase::CCOLLIMATOR ||
73  type == ElementBase::DIAGNOSTIC) continue;
74 
75  Vector_t localR = transformToLocalCS(*it, position);
76  Vector_t localP = rotateToLocalCS(*it, momentum);
77  Vector_t localE(0.0), localB(0.0);
78 
79  (*it)->applyToReferenceParticle(localR, localP, t, localE, localB);
80 
81  Ef += rotateFromLocalCS(*it, localE);
82  Bf += rotateFromLocalCS(*it, localB);
83  }
84 
85  // if(section.hasWake()) {
86  // rtv |= BEAMLINE_WAKE;
87  // }
88  // if(section.hasParticleMatterInteraction()) {
89  // rtv |= BEAMLINE_PARTICLEMATTERINTERACTION;
90  // }
91 
92  return rtv;
93 }
94 
95 void OpalBeamline::switchElements(const double &min, const double &max, const double &kineticEnergy, const bool &nomonitors) {
96 
97  FieldList::iterator fprev;
98  for(FieldList::iterator flit = elements_m.begin(); flit != elements_m.end(); ++ flit) {
99  // don't set online monitors if the centroid of the bunch is allready inside monitor
100  // or if explicitly not desired (eg during auto phasing)
101  if(flit->getElement()->getType() == ElementBase::MONITOR) {
102  double spos = (max + min) / 2.;
103  if(!nomonitors && spos < (*flit).getStart()) {
104  if(!(*flit).isOn() && max > (*flit).getStart()) {
105  (*flit).setOn(kineticEnergy);
106  }
107  }
108 
109  } else {
110  if(!(*flit).isOn() && max > (*flit).getStart() && min < (*flit).getEnd()) {
111  (*flit).setOn(kineticEnergy);
112  }
113 
114  //check if multiple degraders follow one another with no other elements in between
115  //if element is off and it is a degrader
116  if (!(*flit).isOn() && flit->getElement()->getType() == ElementBase::DEGRADER) {
117  //check if previous element: is on, is a degrader, ends where new element starts
118  if ((*fprev).isOn() && fprev->getElement()->getType() == ElementBase::DEGRADER &&
119  ((*fprev).getEnd() + 0.01 > (*flit).getStart()) ) {
120  (*flit).setOn(kineticEnergy);
121  }
122  }
123  }
124 
125  fprev = flit;
126  }
127 }
128 
130  if(eltype == ElementBase::ANY) {
131  for(FieldList::iterator flit = elements_m.begin(); flit != elements_m.end(); ++ flit) {
132  if((*flit).isOn() && min >= (*flit).getEnd()) {
133  (*flit).setOff();
134  }
135 
136  }
137  } else {
138  for(FieldList::iterator flit = elements_m.begin(); flit != elements_m.end(); ++ flit) {
139  if((*flit).isOn() && min >= (*flit).getEnd() && (*flit).getElement()->getType() == eltype) {
140  (*flit).setOff();
141  }
142  }
143  }
144 }
145 
147  for(FieldList::iterator flit = elements_m.begin(); flit != elements_m.end(); ++ flit)
148  (*flit).setOff();
149 }
150 
152  if (elements_m.size() == 0) {
153  prepared_m = true;
154  return;
155  }
156  prepared_m = true;
157 }
158 
159 void OpalBeamline::print(Inform &msg) const {
160 }
161 
163  std::swap(elements_m, rhs.elements_m);
164  std::swap(prepared_m, rhs.prepared_m);
166 }
167 
169  elements_m.insert(elements_m.end(),
170  rhs.elements_m.begin(),
171  rhs.elements_m.end());
172  prepared_m = false;
174 }
175 
176 
178  if (type == ElementBase::ANY) {
179  return elements_m;
180  }
181 
182  FieldList elements_of_requested_type;
183  for(FieldList::iterator fit = elements_m.begin(); fit != elements_m.end(); ++ fit) {
184  if((*fit).getElement()->getType() == type) {
185  elements_of_requested_type.push_back((*fit));
186  }
187  }
188  return elements_of_requested_type;
189 }
190 
192  static unsigned int order = 0;
193  const FieldList::iterator end = elements_m.end();
194 
195  unsigned int minOrder = order;
196  {
197  double endPriorPathLength = 0.0;
199 
200  elements_m.sort([](const ClassicField& a, const ClassicField& b) {
201  double edgeA = 0.0, edgeB = 0.0;
202  if (a.getElement()->isElementPositionSet())
203  edgeA = a.getElement()->getElementPosition();
204 
205  if (b.getElement()->isElementPositionSet())
206  edgeB = b.getElement()->getElementPosition();
207 
208  return edgeA < edgeB;
209  });
210  FieldList::iterator it = elements_m.begin();
211  for (; it != end; ++ it) {
212  if ((*it).isPositioned()) {
213  continue;
214  }
215  (*it).order_m = minOrder;
216  std::shared_ptr<Component> element = (*it).getElement();
217 
218  if (element->getType() != ElementBase::SBEND &&
219  element->getType() != ElementBase::RBEND &&
220  element->getType() != ElementBase::RBEND3D) {
221  continue;
222  }
223 
224  double beginThisPathLength = element->getElementPosition();
225  Vector_t beginThis3D(0, 0, beginThisPathLength - endPriorPathLength);
226  BendBase * bendElement = static_cast<BendBase*>(element.get());
227  double thisLength = bendElement->getChordLength();
228  double bendAngle = bendElement->getBendAngle();
229  double entranceAngle = bendElement->getEntranceAngle();
230  double arcLength = (thisLength * std::abs(bendAngle) / (2 * sin(std::abs(bendAngle) / 2)));
231 
232  double rotationAngleAboutZ = bendElement->getRotationAboutZ();
233  Quaternion_t rotationAboutZ(cos(0.5 * rotationAngleAboutZ),
234  sin(-0.5 * rotationAngleAboutZ) * Vector_t(0, 0, 1));
235 
236  Vector_t effectiveRotationAxis = rotationAboutZ.rotate(Vector_t(0, -1, 0));
237  effectiveRotationAxis /= euclidean_norm(effectiveRotationAxis);
238 
239  Quaternion_t rotationAboutAxis(cos(0.5 * bendAngle),
240  sin(0.5 * bendAngle) * effectiveRotationAxis);
241  Quaternion_t halfRotationAboutAxis(cos(0.25 * bendAngle),
242  sin(0.25 * bendAngle) * effectiveRotationAxis);
243  Quaternion_t entryFaceRotation(cos(0.5 * entranceAngle),
244  sin(0.5 * entranceAngle) * effectiveRotationAxis);
245 
246  if (!Options::idealized) {
247  std::vector<Vector_t> truePath = bendElement->getDesignPath();
248  Quaternion_t directionExitHardEdge(cos(0.5 * (0.5 * bendAngle - entranceAngle)),
249  sin(0.5 * (0.5 * bendAngle - entranceAngle)) * effectiveRotationAxis);
250  Vector_t exitHardEdge = thisLength * directionExitHardEdge.rotate(Vector_t(0, 0, 1));
251  double distanceEntryHETruePath = euclidean_norm(truePath.front());
252  double distanceExitHETruePath = euclidean_norm(rotationAboutZ.rotate(truePath.back()) - exitHardEdge);
253  double pathLengthTruePath = (*it).getEnd() - (*it).getStart();
254  arcLength = pathLengthTruePath - distanceEntryHETruePath - distanceExitHETruePath;
255  }
256 
257  Vector_t chord = thisLength * halfRotationAboutAxis.rotate(Vector_t(0, 0, 1));
258  Vector_t endThis3D = beginThis3D + chord;
259  double endThisPathLength = beginThisPathLength + arcLength;
260 
261  CoordinateSystemTrafo fromEndLastToBeginThis(beginThis3D,
262  (entryFaceRotation * rotationAboutZ).conjugate());
263  CoordinateSystemTrafo fromEndLastToEndThis(endThis3D,
264  rotationAboutAxis.conjugate());
265 
266  (*it).setCoordTransformationTo(fromEndLastToBeginThis * currentCoordTrafo);
267 
268  currentCoordTrafo = (fromEndLastToEndThis * currentCoordTrafo);
269 
270  endPriorPathLength = endThisPathLength;
271  }
272  }
273 
274  double endPriorPathLength = 0.0;
276 
277  FieldList::iterator it = elements_m.begin();
278  for (; it != end; ++ it) {
279  if ((*it).isPositioned()) continue;
280 
281  (*it).order_m = order ++;
282 
283  std::shared_ptr<Component> element = (*it).getElement();
284  double beginThisPathLength = element->getElementPosition();
285  double thisLength = element->getElementLength();
286  Vector_t beginThis3D(0, 0, beginThisPathLength - endPriorPathLength);
287 
288  if (element->getType() == ElementBase::SOURCE) {
289  beginThis3D(2) -= thisLength;
290  }
291  if (element->getType() == ElementBase::MONITOR) {
292  beginThis3D(2) -= 0.5 * thisLength;
293  }
294 
295  Vector_t endThis3D;
296  if (element->getType() == ElementBase::SBEND ||
297  element->getType() == ElementBase::RBEND ||
298  element->getType() == ElementBase::RBEND3D) {
299 
300  BendBase * bendElement = static_cast<BendBase*>(element.get());
301  thisLength = bendElement->getChordLength();
302  double bendAngle = bendElement->getBendAngle();
303 
304  double rotationAngleAboutZ = bendElement->getRotationAboutZ();
305  Quaternion_t rotationAboutZ(cos(0.5 * rotationAngleAboutZ),
306  sin(-0.5 * rotationAngleAboutZ) * Vector_t(0, 0, 1));
307 
308  Vector_t effectiveRotationAxis = rotationAboutZ.rotate(Vector_t(0, -1, 0));
309  effectiveRotationAxis /= euclidean_norm(effectiveRotationAxis);
310 
311  Quaternion_t rotationAboutAxis(cos(0.5 * bendAngle),
312  sin(0.5 * bendAngle) * effectiveRotationAxis);
313  Quaternion halfRotationAboutAxis(cos(0.25 * bendAngle),
314  sin(0.25 * bendAngle) * effectiveRotationAxis);
315 
316  double arcLength = (thisLength * std::abs(bendAngle) /
317  (2 * sin(bendAngle / 2)));
318  if (!Options::idealized) {
319  std::vector<Vector_t> truePath = bendElement->getDesignPath();
320  double entranceAngle = bendElement->getEntranceAngle();
321  Quaternion_t directionExitHardEdge(cos(0.5 * (0.5 * bendAngle - entranceAngle)),
322  sin(0.5 * (0.5 * bendAngle - entranceAngle)) * effectiveRotationAxis);
323  Vector_t exitHardEdge = thisLength * directionExitHardEdge.rotate(Vector_t(0, 0, 1));
324  double distanceEntryHETruePath = euclidean_norm(truePath.front());
325  double distanceExitHETruePath = euclidean_norm(rotationAboutZ.rotate(truePath.back()) - exitHardEdge);
326  double pathLengthTruePath = (*it).getEnd() - (*it).getStart();
327  arcLength = pathLengthTruePath - distanceEntryHETruePath - distanceExitHETruePath;
328  }
329 
330  endThis3D = (beginThis3D +
331  halfRotationAboutAxis.rotate(Vector_t(0, 0, thisLength)));
332  CoordinateSystemTrafo fromEndLastToEndThis(endThis3D,
333  rotationAboutAxis.conjugate());
334  currentCoordTrafo = fromEndLastToEndThis * currentCoordTrafo;
335 
336  endPriorPathLength = beginThisPathLength + arcLength;
337  } else {
338  double rotationAngleAboutZ = (*it).getElement()->getRotationAboutZ();
339  Quaternion_t rotationAboutZ(cos(0.5 * rotationAngleAboutZ),
340  sin(-0.5 * rotationAngleAboutZ) * Vector_t(0, 0, 1));
341 
342  CoordinateSystemTrafo fromLastToThis(beginThis3D, rotationAboutZ);
343 
344  (*it).setCoordTransformationTo(fromLastToThis * currentCoordTrafo);
345  }
346 
347  (*it).fixPosition();
348  }
349 
351 }
352 
354  if (Ippl::myNode() != 0 || OpalData::getInstance()->isOptimizerRun()) return;
355 
356  elements_m.sort([](const ClassicField& a, const ClassicField& b) {
357  return a.order_m < b.order_m;
358  });
359 
360  FieldList::iterator it = elements_m.begin();
361  FieldList::iterator end = elements_m.end();
362 
363  std::ofstream pos;
364  std::string fileName = "data/" + OpalData::getInstance()->getInputBasename() + "_ElementPositions.txt";
365  if (OpalData::getInstance()->getOpenMode() == OpalData::OPENMODE::APPEND &&
366  boost::filesystem::exists(fileName)) {
367  pos.open(fileName, std::ios_base::app);
368  } else {
369  pos.open(fileName);
370  }
371 
372  MeshGenerator mesh;
373  for (; it != end; ++ it) {
374  std::shared_ptr<Component> element = (*it).getElement();
375  CoordinateSystemTrafo toBegin = element->getEdgeToBegin() * (*it).getCoordTransformationTo();
376  CoordinateSystemTrafo toEnd = element->getEdgeToEnd() * (*it).getCoordTransformationTo();
377  Vector_t entry3D = toBegin.getOrigin();
378  Vector_t exit3D = toEnd.getOrigin();
379 
380  mesh.add(*(element.get()));
381 
382  if (element->getType() == ElementBase::SBEND ||
383  element->getType() == ElementBase::RBEND) {
384 
385  Bend2D * bendElement = static_cast<Bend2D*>(element.get());
386  std::vector<Vector_t> designPath = bendElement->getDesignPath();
387  toEnd = bendElement->getBeginToEnd_local() * (*it).getCoordTransformationTo();
388  exit3D = toEnd.getOrigin();
389 
390  unsigned int size = designPath.size();
391  unsigned int minNumSteps = std::max(20.0,
392  std::abs(bendElement->getBendAngle() / Physics::pi * 180));
393  unsigned int frequency = std::floor((double)size / minNumSteps);
394 
395  pos << std::setw(30) << std::left << std::string("\"ENTRY EDGE: ") + element->getName() + std::string("\"")
396  << std::setw(18) << std::setprecision(10) << entry3D(2)
397  << std::setw(18) << std::setprecision(10) << entry3D(0)
398  << std::setw(18) << std::setprecision(10) << entry3D(1)
399  << "\n";
400 
401  Vector_t position = (*it).getCoordTransformationTo().transformFrom(designPath.front());
402  pos << std::setw(30) << std::left << std::string("\"BEGIN: ") + element->getName() + std::string("\"")
403  << std::setw(18) << std::setprecision(10) << position(2)
404  << std::setw(18) << std::setprecision(10) << position(0)
405  << std::setw(18) << std::setprecision(10) << position(1)
406  << std::endl;
407 
408  for (unsigned int i = frequency; i + 1 < size; i += frequency) {
409 
410  position = (*it).getCoordTransformationTo().transformFrom(designPath[i]);
411  pos << std::setw(30) << std::left << std::string("\"MID: ") + element->getName() + std::string("\"")
412  << std::setw(18) << std::setprecision(10) << position(2)
413  << std::setw(18) << std::setprecision(10) << position(0)
414  << std::setw(18) << std::setprecision(10) << position(1)
415  << std::endl;
416  }
417 
418  position = (*it).getCoordTransformationTo().transformFrom(designPath.back());
419  pos << std::setw(30) << std::left << std::string("\"END: ") + element->getName() + std::string("\"")
420  << std::setw(18) << std::setprecision(10) << position(2)
421  << std::setw(18) << std::setprecision(10) << position(0)
422  << std::setw(18) << std::setprecision(10) << position(1)
423  << std::endl;
424 
425  pos << std::setw(30) << std::left << std::string("\"EXIT EDGE: ") + element->getName() + std::string("\"")
426  << std::setw(18) << std::setprecision(10) << exit3D(2)
427  << std::setw(18) << std::setprecision(10) << exit3D(0)
428  << std::setw(18) << std::setprecision(10) << exit3D(1)
429  << std::endl;
430  } else {
431  pos << std::setw(30) << std::left << std::string("\"BEGIN: ") + element->getName() + std::string("\"")
432  << std::setw(18) << std::setprecision(10) << entry3D(2)
433  << std::setw(18) << std::setprecision(10) << entry3D(0)
434  << std::setw(18) << std::setprecision(10) << entry3D(1)
435  << "\n";
436 
437  pos << std::setw(30) << std::left << std::string("\"END: ") + element->getName() + std::string("\"")
438  << std::setw(18) << std::setprecision(10) << exit3D(2)
439  << std::setw(18) << std::setprecision(10) << exit3D(0)
440  << std::setw(18) << std::setprecision(10) << exit3D(1)
441  << std::endl;
442  }
443  }
445  mesh.write(OpalData::getInstance()->getInputBasename());
446 }
447 
448 namespace {
449  std::string parseInput() {
450 
451  std::ifstream in(OpalData::getInstance()->getInputFn());
452  std::string source("");
453  std::string str;
454  char testBit;
455  const std::string commentFormat("");
456  const boost::regex empty("^[ \t]*$");
457  const boost::regex lineEnd(";");
458  const std::string lineEndFormat(";\n");
459  const boost::regex cppCommentExpr("//.*");
460  const boost::regex cCommentExpr("/\\*.*?\\*/"); // "/\\*(?>[^*/]+|\\*[^/]|/[^*])*(?>(?R)(?>[^*/]+|\\*[^/]|/[^*])*)*\\*/"
461  bool priorEmpty = true;
462 
463  in.get(testBit);
464  while (!in.eof()) {
465  in.putback(testBit);
466 
467  std::getline(in, str);
468  str = boost::regex_replace(str, cppCommentExpr, commentFormat);
469  str = boost::regex_replace(str, empty, commentFormat);
470  if (str.size() > 0) {
471  source += str;// + '\n';
472  priorEmpty = false;
473  } else if (!priorEmpty) {
474  source += "##EMPTY_LINE##";
475  priorEmpty = true;
476  }
477 
478  in.get(testBit);
479  }
480 
481  source = boost::regex_replace(source, cCommentExpr, commentFormat);
482  source = boost::regex_replace(source, lineEnd, lineEndFormat, boost::match_default | boost::format_all);
483 
484  return source;
485  }
486 
487  unsigned int getMinimalSignificantDigits(double num, const unsigned int maxDigits) {
488  char buf[32];
489  snprintf(buf, 32, "%.*f", maxDigits + 1, num);
490  std::string numStr(buf);
491  unsigned int length = numStr.length();
492 
493  unsigned int numDigits = maxDigits;
494  unsigned int i = 2;
495  while (i < maxDigits + 1 && numStr[length - i] == '0') {
496  --numDigits;
497  ++ i;
498  }
499 
500  return numDigits;
501  }
502 
503  std::string round2string(double num, const unsigned int maxDigits) {
504  char buf[64];
505 
506  snprintf(buf, 64, "%.*f", getMinimalSignificantDigits(num, maxDigits), num);
507 
508  return std::string(buf);
509  }
510 }
511 
513  if (Ippl::myNode() != 0 || OpalData::getInstance()->isOptimizerRun()) return;
514 
515  FieldList::iterator it = elements_m.begin();
516  FieldList::iterator end = elements_m.end();
517 
518  std::string input = parseInput();
519  std::ofstream pos("data/" + OpalData::getInstance()->getInputBasename() + "_3D.opal");
520 
521  for (; it != end; ++ it) {
522  std::string element = (*it).getElement()->getName();
523  const boost::regex replacePSI("(" + element + "\\s*:[^\\n]*)PSI\\s*=[^,;]*,?", boost::regex::icase);
524  input = boost::regex_replace(input, replacePSI, "\\1\\2");
525 
526  const boost::regex replaceELEMEDGE("(" + element + "\\s*:[^\\n]*)ELEMEDGE\\s*=[^,;]*(.)", boost::regex::icase);
527 
528  CoordinateSystemTrafo cst = (*it).getCoordTransformationTo();
529  Vector_t origin = cst.getOrigin();
530  Vector_t orient = Util::getTaitBryantAngles(cst.getRotation().conjugate(), element);
531  for (unsigned int d = 0; d < 3; ++ d)
532  orient(d) *= Physics::rad2deg;
533 
534  std::string x = (std::abs(origin(0)) > 1e-10? "X = " + round2string(origin(0), 10) + ", ": "");
535  std::string y = (std::abs(origin(1)) > 1e-10? "Y = " + round2string(origin(1), 10) + ", ": "");
536  std::string z = (std::abs(origin(2)) > 1e-10? "Z = " + round2string(origin(2), 10) + ", ": "");
537 
538  std::string theta = (orient(0) > 1e-10? "THETA = " + round2string(orient(0), 6) + " * PI / 180, ": "");
539  std::string phi = (orient(1) > 1e-10? "PHI = " + round2string(orient(1), 6) + " * PI / 180, ": "");
540  std::string psi = (orient(2) > 1e-10? "PSI = " + round2string(orient(2), 6) + " * PI / 180, ": "");
541  std::string coordTrafo = x + y + z + theta + phi + psi;
542  if (coordTrafo.length() > 2) {
543  coordTrafo = coordTrafo.substr(0, coordTrafo.length() - 2); // remove last ', '
544  }
545 
546  std::string position = ("\\1" + coordTrafo + "\\2");
547 
548  input = boost::regex_replace(input, replaceELEMEDGE, position);
549 
550  if ((*it).getElement()->getType() == ElementBase::RBEND ||
551  (*it).getElement()->getType() == ElementBase::SBEND) {
552  const Bend2D* dipole = static_cast<const Bend2D*>((*it).getElement().get());
553  double angle = dipole->getBendAngle();
554  double E1 = dipole->getEntranceAngle();
555  double E2 = dipole->getExitAngle();
556 
557  const boost::regex angleR("(" + element + "\\s*:[^\\n]*ANGLE\\s*=)[^,;]*(.)");
558  const std::string angleF("\\1 " + round2string(angle * 180 / Physics::pi, 6) + " / 180 * PI\\2");
559  const boost::regex E1R("(" + element + "\\s*:[^\\n]*E1\\s*=)[^,;]*(.)");
560  const std::string E1F("\\1 " + round2string(E1 * 180 / Physics::pi, 6) + " / 180 * PI\\2");
561  const boost::regex E2R("(" + element + "\\s*:[^\\n]*E2\\s*=)[^,;]*(.)");
562  const std::string E2F("\\1 " + round2string(E2 * 180 / Physics::pi, 6) + " / 180 * PI\\2");
563  const boost::regex noRotation("(" + element + "\\s*:[^\\n]*),\\s*ROTATION\\s*=[^,;]*(.)");
564  const std::string noRotationFormat("\\1\\2 ");
565 
566  input = boost::regex_replace(input, angleR, angleF);
567  input = boost::regex_replace(input, E1R, E1F);
568  input = boost::regex_replace(input, E2R, E2F);
569  input = boost::regex_replace(input, noRotation, noRotationFormat);
570  }
571  }
572 
573  const boost::regex empty("##EMPTY_LINE##");
574  const std::string emptyFormat("\n");
575  input = boost::regex_replace(input, empty, emptyFormat);
576 
577  pos << input << std::endl;
578 }
579 
581  auto it = elements_m.begin();
582  const auto end = elements_m.end();
583 
584  double designEnergy = 0.0;
585  for (; it != end; ++ it) {
586  std::shared_ptr<Component> element = (*it).getElement();
587  if (element->getType() == ElementBase::SBEND ||
588  element->getType() == ElementBase::RBEND) {
589  Bend2D * bendElement = static_cast<Bend2D*>(element.get());
590  designEnergy = bendElement->getDesignEnergy() * 1e-6;
591  }
592  (*it).setOn(designEnergy);
593  // element->goOnline(designEnergy);
594  }
595 }
elements
Definition: IndexMap.cpp:141
void merge(OpalBeamline &rhs)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
constexpr double e
The value of .
Definition: Physics.h:40
void prepareSections()
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &elementName)
Definition: Util.cpp:100
void switchElementsOff()
void write(const std::string &fname)
void switchElements(const double &, const double &, const double &kineticEnergy, const bool &nomonitors=false)
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:123
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
void compute3DLattice()
std::list< ClassicField > FieldList
Definition: ClassicField.h:47
CoordinateSystemTrafo coordTransformationTo_m
Definition: OpalBeamline.h:94
unsigned int order_m
Definition: ClassicField.h:39
double getChordLength() const
Definition: BendBase.h:76
static int myNode()
Definition: IpplInfo.cpp:794
Vector_t rotateFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Definition: OpalBeamline.h:203
std::vector< Vector_t > getDesignPath() const
Definition: BendBase.cpp:43
constexpr double rad2deg
The conversion factor from radians to degrees.
Definition: Physics.h:46
unsigned long getFieldAt(const unsigned int &, const Vector_t &, const long &, const double &, Vector_t &, Vector_t &)
static bool SortAsc(const ClassicField &fle1, const ClassicField &fle2)
Definition: ClassicField.h:26
double getDesignEnergy() const
Definition: BendBase.h:120
Vector_t transformToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Definition: OpalBeamline.h:185
double getBendAngle() const
Definition: BendBase.h:86
static OpalData * getInstance()
Definition: OpalData.cpp:209
void add(const ElementBase &element)
void activateElements()
bool containsSource_m
Definition: OpalBeamline.h:92
constexpr double pi
The value of .
Definition: Physics.h:31
Quaternion getRotation() const
std::shared_ptr< Component > getElement()
Definition: ClassicField.h:49
Definition: Bend2D.h:51
void print(Inform &) const
FieldList getElementByType(ElementBase::ElementType)
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6
void swap(OpalBeamline &rhs)
Vector_t getOrigin() const
virtual double getExitAngle() const
Definition: Bend2D.h:357
double getRotationAboutZ() const
Definition: ElementBase.h:700
Vector_t rotateToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Definition: OpalBeamline.h:197
std::set< std::shared_ptr< Component > > getElements(const Vector_t &x)
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
T euclidean_norm(const Vector< T > &)
Euclidean norm.
Definition: Vector.h:243
Vector_t rotate(const Vector_t &) const
Definition: Quaternion.cpp:122
CoordinateSystemTrafo getBeginToEnd_local() const
Definition: Bend2D.h:382
FieldList elements_m
Definition: OpalBeamline.h:90
void save3DLattice()
Quaternion conjugate() const
Definition: Quaternion.h:104
std::string::iterator iterator
Definition: MSLang.h:16
double getEntranceAngle() const
Definition: BendBase.h:97
std::string getInputBasename()
get input file name without extension
Definition: OpalData.cpp:717
bool idealized
Definition: Options.cpp:94
Definition: Inform.h:41
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:95
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Definition: PETE.h:816
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
void save3DInput()