206 static unsigned int order = 0;
209 unsigned int minOrder = order;
211 double endPriorPathLength = 0.0;
215 for (; it !=
end; ++ it) {
216 std::shared_ptr<Component> element = (*it).getElement();
217 if (element->isPositioned()) {
220 (*it).order_m = minOrder;
228 double beginThisPathLength = element->getElementPosition();
229 Vector_t beginThis3D(0, 0, beginThisPathLength - endPriorPathLength);
234 double arcLength = (thisLength * std::abs(bendAngle) / (2 *
sin(std::abs(bendAngle) / 2)));
238 sin(-0.5 * rotationAngleAboutZ) *
Vector_t(0, 0, 1));
244 sin(0.5 * bendAngle) * effectiveRotationAxis);
246 sin(0.25 * bendAngle) * effectiveRotationAxis);
248 sin(0.5 * entranceAngle) * effectiveRotationAxis);
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);
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;
262 Vector_t endThis3D = beginThis3D + chord;
263 double endThisPathLength = beginThisPathLength + arcLength;
266 (entryFaceRotation * rotationAboutZ).conjugate());
270 element->setCSTrafoGlobal2Local(fromEndLastToBeginThis * currentCoordTrafo);
272 currentCoordTrafo = (fromEndLastToEndThis * currentCoordTrafo);
274 endPriorPathLength = endThisPathLength;
278 double endPriorPathLength = 0.0;
282 for (; it !=
end; ++ it) {
283 std::shared_ptr<Component> element = (*it).getElement();
284 if (element->isPositioned())
continue;
286 (*it).order_m = order ++;
288 double beginThisPathLength = element->getElementPosition();
289 double thisLength = element->getElementLength();
290 Vector_t beginThis3D(0, 0, beginThisPathLength - endPriorPathLength);
293 beginThis3D(2) -= thisLength;
307 sin(-0.5 * rotationAngleAboutZ) *
Vector_t(0, 0, 1));
313 sin(0.5 * bendAngle) * effectiveRotationAxis);
315 sin(0.25 * bendAngle) * effectiveRotationAxis);
317 double arcLength = (thisLength * std::abs(bendAngle) /
318 (2 *
sin(bendAngle / 2)));
320 std::vector<Vector_t> truePath = bendElement->
getDesignPath();
322 Quaternion_t directionExitHardEdge(
cos(0.5 * (0.5 * bendAngle - entranceAngle)),
323 sin(0.5 * (0.5 * bendAngle - entranceAngle)) * effectiveRotationAxis);
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;
331 endThis3D = (beginThis3D +
335 currentCoordTrafo = fromEndLastToEndThis * currentCoordTrafo;
337 endPriorPathLength = beginThisPathLength + arcLength;
339 double rotationAngleAboutZ = (*it).getElement()->getRotationAboutZ();
341 sin(-0.5 * rotationAngleAboutZ) *
Vector_t(0, 0, 1));
345 element->setCSTrafoGlobal2Local(fromLastToThis * currentCoordTrafo);
348 element->fixPosition();
368 std::filesystem::exists(fileName)) {
369 pos.open(fileName, std::ios_base::app);
375 for (; it !=
end; ++ it) {
376 std::shared_ptr<Component> element = (*it).getElement();
382 mesh.
add(*(element.get()));
387 Bend2D * bendElement =
static_cast<Bend2D*
>(element.get());
388 std::vector<Vector_t> designPath = bendElement->
getDesignPath();
392 unsigned int size = designPath.size();
393 unsigned int minNumSteps = std::max(20.0,
395 unsigned int frequency = std::floor((
double)size / minNumSteps);
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)
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)
410 for (
unsigned int i = frequency; i + 1 < size; i += frequency) {
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)
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)
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)
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)
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)
527 std::string input = parseInput();
532 std::ofstream pos(fname);
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");
540 const boost::regex replaceELEMEDGE(
"(" + elementName +
"\\s*:[^\\n]*)ELEMEDGE\\s*=[^,;]*(.)", boost::regex::icase);
545 for (
unsigned int d = 0; d < 3; ++ d)
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) +
", ":
"");
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);
560 std::string position = (
"\\1" + coordTrafo +
"\\2");
562 input = boost::regex_replace(input, replaceELEMEDGE, position);
566 const Bend2D* dipole =
static_cast<const Bend2D*
>(element.get());
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 ");
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);
587 const boost::regex empty(
"##EMPTY_LINE##");
588 const std::string emptyFormat(
"\n");
589 input = boost::regex_replace(input, empty, emptyFormat);
591 pos << input << std::endl;