From 9d1790765ecedd2a6f62b0c0ffbb5095871cac9a Mon Sep 17 00:00:00 2001 From: Christof Kraus <christof.kraus@psi.ch> Date: Fri, 24 Jul 2020 10:51:21 +0200 Subject: [PATCH] Also place the Source element relative to the beamline; Add a comment to the regexp that makes sure that the origin and orientation of the beamlines doesn't differ from the laboratory coordinate system --- src/Elements/OpalBeamline.cpp | 23 ++++++++++++++++++++++- src/Elements/OpalBeamline.h | 5 +++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Elements/OpalBeamline.cpp b/src/Elements/OpalBeamline.cpp index 076e433c1..c5ece25db 100644 --- a/src/Elements/OpalBeamline.cpp +++ b/src/Elements/OpalBeamline.cpp @@ -204,10 +204,24 @@ FieldList OpalBeamline::getElementByType(ElementBase::ElementType type) { return elements_of_requested_type; } +void OpalBeamline::positionElementRelative(std::shared_ptr<ElementBase> element) { + if (!element->isPositioned()) { + return; + } + + element->releasePosition(); + CoordinateSystemTrafo toElement = element->getCSTrafoGlobal2Local(); + toElement *= coordTransformationTo_m; + + element->setCSTrafoGlobal2Local(toElement); + element->fixPosition(); +} + void OpalBeamline::compute3DLattice() { static unsigned int order = 0; const FieldList::iterator end = elements_m.end(); + unsigned int minOrder = order; { double endPriorPathLength = 0.0; @@ -500,6 +514,13 @@ namespace { source = boost::regex_replace(source, cCommentExpr, commentFormat); source = boost::regex_replace(source, lineEnd, lineEndFormat, boost::match_default | boost::format_all); + // Since the positions of the elements are absolute in the laboratory coordinate system we have to make + // sure that the line command doesn't provide an origin and orientation. Everything after the sequence of + // elements can be deleted and only "LINE = (...);", the first sub-expression (denoted by '\1'), should be kept. + const boost::regex lineCommand("(LINE[ \t]*=[ \t]*\\([^\\)]*\\))[ \t]*,[^;]*;", boost::regex::icase); + const std::string firstSubExpression("\\1;"); + source = boost::regex_replace(source, lineCommand, firstSubExpression); + return source; } @@ -615,4 +636,4 @@ void OpalBeamline::activateElements() { (*it).setOn(designEnergy); // element->goOnline(designEnergy); } -} +} \ No newline at end of file diff --git a/src/Elements/OpalBeamline.h b/src/Elements/OpalBeamline.h index 49d8e75fa..7f07f5394 100644 --- a/src/Elements/OpalBeamline.h +++ b/src/Elements/OpalBeamline.h @@ -83,6 +83,7 @@ public: void visit(const T &, BeamlineVisitor &, PartBunchBase<double, 3> *); void prepareSections(); + void positionElementRelative(std::shared_ptr<ElementBase>); void compute3DLattice(); void save3DLattice(); void save3DInput(); @@ -109,6 +110,8 @@ void OpalBeamline::visit(const T &element, BeamlineVisitor &, PartBunchBase<doub double endField = 0.0; std::shared_ptr<T> elptr(dynamic_cast<T *>(element.clone())); + positionElementRelative(elptr); + if (elptr->isElementPositionSet()) startField = elptr->getElementPosition(); @@ -123,6 +126,8 @@ void OpalBeamline::visit<Source>(const Source &element, BeamlineVisitor &, PartB double endField = 0.0; std::shared_ptr<Source> elptr(dynamic_cast<Source *>(element.clone())); + positionElementRelative(elptr); + if (elptr->isElementPositionSet()) startField = elptr->getElementPosition(); -- GitLab