Commit 9d179076 authored by kraus's avatar kraus

Also place the Source element relative to the beamline; Add a comment to the...

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
parent 2e4b24f8
......@@ -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
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment