213 static unsigned int order = 0;
216 unsigned int minOrder = order;
218 double endPriorPathLength = 0.0;
222 for (; it !=
end; ++ it) {
223 std::shared_ptr<Component> element = (*it).getElement();
224 if (element->isPositioned()) {
227 (*it).order_m = minOrder;
235 double beginThisPathLength = element->getElementPosition();
236 Vector_t beginThis3D({0, 0, beginThisPathLength - endPriorPathLength});
239 double bendAngle = bendElement->getBendAngle();
240 double entranceAngle = bendElement->getEntranceAngle();
241 double arcLength = (thisLength * std::abs(bendAngle) / (2 *
sin(std::abs(bendAngle) / 2)));
243 double rotationAngleAboutZ = bendElement->getRotationAboutZ();
245 sin(-0.5 * rotationAngleAboutZ) *
Vector_t({0, 0, 1}));
251 sin(0.5 * bendAngle) * effectiveRotationAxis);
253 sin(0.25 * bendAngle) * effectiveRotationAxis);
255 sin(0.5 * entranceAngle) * effectiveRotationAxis);
258 std::vector<Vector_t> truePath = bendElement->getDesignPath();
259 Quaternion_t directionExitHardEdge(
cos(0.5 * (0.5 * bendAngle - entranceAngle)),
260 sin(0.5 * (0.5 * bendAngle - entranceAngle)) * effectiveRotationAxis);
262 double distanceEntryHETruePath =
euclidean_norm(truePath.front());
263 double distanceExitHETruePath =
euclidean_norm(rotationAboutZ.
rotate(truePath.back()) - exitHardEdge);
264 double pathLengthTruePath = (*it).getEnd() - (*it).getStart();
265 arcLength = pathLengthTruePath - distanceEntryHETruePath - distanceExitHETruePath;
269 Vector_t endThis3D = beginThis3D + chord;
270 double endThisPathLength = beginThisPathLength + arcLength;
273 (entryFaceRotation * rotationAboutZ).conjugate());
277 element->setCSTrafoGlobal2Local(fromEndLastToBeginThis * currentCoordTrafo);
279 currentCoordTrafo = (fromEndLastToEndThis * currentCoordTrafo);
281 endPriorPathLength = endThisPathLength;
285 double endPriorPathLength = 0.0;
289 for (; it !=
end; ++ it) {
290 std::shared_ptr<Component> element = (*it).getElement();
291 if (element->isPositioned())
continue;
293 (*it).order_m = order ++;
295 double beginThisPathLength = element->getElementPosition();
296 double thisLength = element->getElementLength();
297 Vector_t beginThis3D({0, 0, beginThisPathLength - endPriorPathLength});
300 beginThis3D(2) -= thisLength;
314 sin(-0.5 * rotationAngleAboutZ) *
Vector_t({0, 0, 1}));
320 sin(0.5 * bendAngle) * effectiveRotationAxis);
322 sin(0.25 * bendAngle) * effectiveRotationAxis);
324 double arcLength = (thisLength * std::abs(bendAngle) /
325 (2 *
sin(bendAngle / 2)));
327 std::vector<Vector_t> truePath = bendElement->
getDesignPath();
329 Quaternion_t directionExitHardEdge(
cos(0.5 * (0.5 * bendAngle - entranceAngle)),
330 sin(0.5 * (0.5 * bendAngle - entranceAngle)) * effectiveRotationAxis);
332 double distanceEntryHETruePath =
euclidean_norm(truePath.front());
333 double distanceExitHETruePath =
euclidean_norm(rotationAboutZ.
rotate(truePath.back()) - exitHardEdge);
334 double pathLengthTruePath = (*it).getEnd() - (*it).getStart();
335 arcLength = pathLengthTruePath - distanceEntryHETruePath - distanceExitHETruePath;
338 endThis3D = (beginThis3D +
342 currentCoordTrafo = fromEndLastToEndThis * currentCoordTrafo;
344 endPriorPathLength = beginThisPathLength + arcLength;
346 double rotationAngleAboutZ = (*it).getElement()->getRotationAboutZ();
348 sin(-0.5 * rotationAngleAboutZ) *
Vector_t({0, 0, 1}));
352 element->setCSTrafoGlobal2Local(fromLastToThis * currentCoordTrafo);
355 element->fixPosition();
375 std::filesystem::exists(fileName)) {
376 pos.open(fileName, std::ios_base::app);
382 for (; it !=
end; ++ it) {
383 std::shared_ptr<Component> element = (*it).getElement();
389 mesh.
add(*(element.get()));
394 Bend2D * bendElement =
static_cast<Bend2D*
>(element.get());
395 std::vector<Vector_t> designPath = bendElement->
getDesignPath();
399 unsigned int size = designPath.size();
400 unsigned int minNumSteps = std::max(20.0,
402 unsigned int frequency = std::floor((
double)size / minNumSteps);
404 pos << std::setw(30) << std::left << std::string(
"\"ENTRY EDGE: ") + element->getName() + std::string(
"\"")
405 << std::setw(18) << std::setprecision(10) << entry3D(2)
406 << std::setw(18) << std::setprecision(10) << entry3D(0)
407 << std::setw(18) << std::setprecision(10) << entry3D(1)
410 Vector_t position = element->getCSTrafoGlobal2Local().transformFrom(designPath.front());
411 pos << std::setw(30) << std::left << std::string(
"\"BEGIN: ") + 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)
417 for (
unsigned int i = frequency; i + 1 < size; i += frequency) {
419 position = element->getCSTrafoGlobal2Local().transformFrom(designPath[i]);
420 pos << std::setw(30) << std::left << std::string(
"\"MID: ") + element->getName() + std::string(
"\"")
421 << std::setw(18) << std::setprecision(10) << position(2)
422 << std::setw(18) << std::setprecision(10) << position(0)
423 << std::setw(18) << std::setprecision(10) << position(1)
427 position = element->getCSTrafoGlobal2Local().transformFrom(designPath.back());
428 pos << std::setw(30) << std::left << std::string(
"\"END: ") + element->getName() + std::string(
"\"")
429 << std::setw(18) << std::setprecision(10) << position(2)
430 << std::setw(18) << std::setprecision(10) << position(0)
431 << std::setw(18) << std::setprecision(10) << position(1)
434 pos << std::setw(30) << std::left << std::string(
"\"EXIT EDGE: ") + element->getName() + std::string(
"\"")
435 << std::setw(18) << std::setprecision(10) << exit3D(2)
436 << std::setw(18) << std::setprecision(10) << exit3D(0)
437 << std::setw(18) << std::setprecision(10) << exit3D(1)
440 pos << std::setw(30) << std::left << std::string(
"\"BEGIN: ") + element->getName() + std::string(
"\"")
441 << std::setw(18) << std::setprecision(10) << entry3D(2)
442 << std::setw(18) << std::setprecision(10) << entry3D(0)
443 << std::setw(18) << std::setprecision(10) << entry3D(1)
446 pos << std::setw(30) << std::left << std::string(
"\"END: ") + element->getName() + std::string(
"\"")
447 << std::setw(18) << std::setprecision(10) << exit3D(2)
448 << std::setw(18) << std::setprecision(10) << exit3D(0)
449 << std::setw(18) << std::setprecision(10) << exit3D(1)
534 std::string input = parseInput();
539 std::ofstream pos(fname);
541 for (; it !=
end; ++ it) {
542 std::shared_ptr<Component> element = (*it).getElement();
543 std::string elementName = element->getName();
544 const std::regex replacePSI(
"(" + elementName +
"\\s*:[^\\n]*)PSI\\s*=[^,;]*,?", std::regex::icase);
545 input = std::regex_replace(input, replacePSI,
"\\1\\2");
547 const std::regex replaceELEMEDGE(
"(" + elementName +
"\\s*:[^\\n]*)ELEMEDGE\\s*=[^,;]*(.)", std::regex::icase);
552 for (
unsigned int d = 0; d < 3; ++ d)
555 std::string x = (std::abs(origin(0)) > 1e-10?
"X = " + round2string(origin(0), 10) +
", ":
"");
556 std::string y = (std::abs(origin(1)) > 1e-10?
"Y = " + round2string(origin(1), 10) +
", ":
"");
557 std::string z = (std::abs(origin(2)) > 1e-10?
"Z = " + round2string(origin(2), 10) +
", ":
"");
559 std::string theta = (orient(0) > 1e-10?
"THETA = " + round2string(orient(0), 6) +
" * PI / 180, ":
"");
560 std::string phi = (orient(1) > 1e-10?
"PHI = " + round2string(orient(1), 6) +
" * PI / 180, ":
"");
561 std::string psi = (orient(2) > 1e-10?
"PSI = " + round2string(orient(2), 6) +
" * PI / 180, ":
"");
562 std::string coordTrafo = x + y + z + theta + phi + psi;
563 if (coordTrafo.length() > 2) {
564 coordTrafo = coordTrafo.substr(0, coordTrafo.length() - 2);
567 std::string position = (
"\\1" + coordTrafo +
"\\2");
569 input = std::regex_replace(input, replaceELEMEDGE, position);
573 const Bend2D* dipole =
static_cast<const Bend2D*
>(element.get());
578 const std::regex angleR(
"(" + elementName +
"\\s*:[^\\n]*ANGLE\\s*=)[^,;]*(.)");
579 const std::string angleF(
"\\1 " + round2string(angle *
Units::rad2deg, 6) +
" / 180 * PI\\2");
580 const std::regex E1R(
"(" + elementName +
"\\s*:[^\\n]*E1\\s*=)[^,;]*(.)");
581 const std::string E1F(
"\\1 " + round2string(E1 *
Units::rad2deg, 6) +
" / 180 * PI\\2");
582 const std::regex E2R(
"(" + elementName +
"\\s*:[^\\n]*E2\\s*=)[^,;]*(.)");
583 const std::string E2F(
"\\1 " + round2string(E2 *
Units::rad2deg, 6) +
" / 180 * PI\\2");
584 const std::regex noRotation(
"(" + elementName +
"\\s*:[^\\n]*),\\s*ROTATION\\s*=[^,;]*(.)");
585 const std::string noRotationFormat(
"\\1\\2 ");
587 input = std::regex_replace(input, angleR, angleF);
588 input = std::regex_replace(input, E1R, E1F);
589 input = std::regex_replace(input, E2R, E2F);
590 input = std::regex_replace(input, noRotation, noRotationFormat);
594 const std::regex empty(
"##EMPTY_LINE##");
595 const std::string emptyFormat(
"\n");
596 input = std::regex_replace(input, empty, emptyFormat);
598 pos << input << std::endl;