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