Commit 26aa0ff8 authored by frey_m's avatar frey_m
Browse files

Merge branch '240-visitor-pattern-alignwrapper' into 'master'

Resolve "Remove wrappers"

Closes #240

See merge request !386
parents 10c4aa19 b138e969
// ------------------------------------------------------------------------
// $RCSfile: Element.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: Element
// The base class for all OPAL beamline elements.
// Class Element
// The base class for all OPAL elements.
// It implements the common behaviour of elements, it can also be used via
// dynamic casting to determine whether an object represents an element.
//
// ------------------------------------------------------------------------
// Each Element object contains a pointer to a CLASSIC beam line element,
// known as the ``ideal'' element.
//
// $Date: 2000/03/27 09:33:34 $
// $Author: Andreas Adelmann $
// If sharable flag is set, all occurrences of the element are supposed to
// have the same imperfections. Thus the assembly is shared when it is used
// more than once in beam lines or sequences.
//
// If the sharable flag is not set, each occurrence of the element is supposed
// to have its own imperfections, but the same ideal representation.
//
// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
// ------------------------------------------------------------------------
#include "AbstractObjects/Element.h"
#include "AbstractObjects/OpalData.h"
#include "Utilities/OpalException.h"
#include "Utilities/Options.h"
// Class Element
// ------------------------------------------------------------------------
Element::~Element()
{}
......
#ifndef OPAL_Element_HH
#define OPAL_Element_HH
// ------------------------------------------------------------------------
// $RCSfile: Element.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: Element
// Class Element
// The base class for all OPAL elements.
// It implements the common behaviour of elements, it can also be used via
// dynamic casting to determine whether an object represents an element.
//
// ------------------------------------------------------------------------
// Each Element object contains a pointer to a CLASSIC beam line element,
// known as the ``ideal'' element.
//
// $Date: 2000/03/27 09:33:34 $
// $Author: Andreas Adelmann $
// If sharable flag is set, all occurrences of the element are supposed to
// have the same imperfections. Thus the assembly is shared when it is used
// more than once in beam lines or sequences.
//
// ------------------------------------------------------------------------
// If the sharable flag is not set, each occurrence of the element is supposed
// to have its own imperfections, but the same ideal representation.
//
// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#ifndef OPAL_Element_HH
#define OPAL_Element_HH
#include "AbstractObjects/Object.h"
#include "AbsBeamline/ElementBase.h"
#include "MemoryManagement/Pointer.h"
// Class Element
// ------------------------------------------------------------------------
/// The base class for all OPAL elements.
// It implements the common behaviour of elements, it can also be used via
// dynamic casting to determine whether an object represents an element.
//
// Each Element object contains a pointer to a CLASSIC beam line element,
// known as the ``ideal'' element. To represent imperfections, this element
// is ``wrapped'' as required in a field wrapper and an AlignWrapper.
// This assembly represents the actual element as it occurs in a beam line.
//
// If sharable flag is set, all occurrences of the element are supposed to
// have the same imperfections. Thus the assembly is shared when it is used
// more than once in beam lines or sequences.
//
// If the sharable flag is not set, each occurrence of the element is supposed
// to have its own imperfections, but the same ideal representation. Thus
// the wrappers are cloned for each new use in a beam line or sequence,
// but they point to the same ideal element.
class Element: public Object {
public:
......
//
// Copyright & License: See Copyright.readme in src directory
// Class NilTracker
// :FIXME: Add class description
//
// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#include "Algorithms/NilTracker.h"
NilTracker::NilTracker(const Beamline &beamline,
......
#ifndef OPAL_NILTRACKER_H
#define OPAL_NILTRACKER_H
//
// Copyright & License: See Copyright.readme in src directory
// Class NilTracker
// :FIXME: Add class description
//
// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#ifndef OPAL_NILTRACKER_H
#define OPAL_NILTRACKER_H
/*!
Class documentation
*/
#define NIL_VISITELEMENT(elem) virtual void visit##elem(const elem &) { }
......@@ -16,7 +26,6 @@
class BMultipoleField;
template <class T, unsigned Dim>
class PartBunchBase;
class AlignWrapper;
class BeamBeam;
class BeamStripping;
class CCollimator;
......@@ -52,7 +61,6 @@ public:
virtual ~NilTracker();
NIL_VISITELEMENT(AlignWrapper)
NIL_VISITELEMENT(Beamline)
NIL_VISITELEMENT(BeamBeam)
NIL_VISITELEMENT(BeamStripping)
......
// ------------------------------------------------------------------------
// $RCSfile: ParallelTTracker.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.2.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: ParallelTTracker
// Class ParallelTTracker
// OPAL-T tracker.
// The visitor class for tracking particles with time as independent
// variable.
//
// ------------------------------------------------------------------------
// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// $Date: 2004/11/12 20:10:11 $
// $Author: adelmann $
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
// ------------------------------------------------------------------------
#include "Algorithms/ParallelTTracker.h"
#include <cfloat>
......
#ifndef OPAL_ParallelTTracker_HH
#define OPAL_ParallelTTracker_HH
// ------------------------------------------------------------------------
// $RCSfile: ParallelTTracker.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.2.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: ParallelTTracker
// Class ParallelTTracker
// OPAL-T tracker.
// The visitor class for tracking particles with time as independent
// variable.
//
// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// ------------------------------------------------------------------------
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// $Date: 2004/11/12 20:10:11 $
// $Author: adelmann $
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
// ------------------------------------------------------------------------
#ifndef OPAL_ParallelTTracker_HH
#define OPAL_ParallelTTracker_HH
#include "Algorithms/Tracker.h"
#include "Steppers/BorisPusher.h"
......@@ -30,7 +32,6 @@
#include "Algorithms/OrbitThreader.h"
#include "Algorithms/IndexMap.h"
#include "AbsBeamline/AlignWrapper.h"
#include "AbsBeamline/BeamBeam.h"
#include "AbsBeamline/BeamStripping.h"
#include "AbsBeamline/CCollimator.h"
......@@ -100,8 +101,6 @@ public:
virtual ~ParallelTTracker();
virtual void visitAlignWrapper(const AlignWrapper &);
/// Apply the algorithm to a BeamBeam.
virtual void visitBeamBeam(const BeamBeam &);
......@@ -293,10 +292,6 @@ private:
void evenlyDistributeParticles();
};
inline void ParallelTTracker::visitAlignWrapper(const AlignWrapper &wrap) {
itsOpalBeamline_m.visit(wrap, *this, itsBunch_m);
}
inline void ParallelTTracker::visitBeamBeam(const BeamBeam &bb) {
itsOpalBeamline_m.visit(bb, *this, itsBunch_m);
}
......
......@@ -148,9 +148,6 @@ public:
virtual ~ThickTracker();
virtual void visitAlignWrapper(const AlignWrapper &);
/// Apply the algorithm to a BeamBeam.
virtual void visitBeamBeam(const BeamBeam &);
......@@ -384,11 +381,6 @@ private:
IpplTimings::TimerRef mapTracking_m; ///< track particles trough maps of elements_m
};
inline void ThickTracker::visitAlignWrapper(const AlignWrapper &/*wrap*/) {
// itsOpalBeamline_m.visit(wrap, *this, itsBunch_m);
this->throwElementError_m("AlignWrapper");
}
inline void ThickTracker::visitBeamBeam(const BeamBeam &/*bb*/) {
// itsOpalBeamline_m.visit(bb, *this, itsBunch_m);
this->throwElementError_m("BeamBeam");
......
// ------------------------------------------------------------------------
// $RCSfile: AlignWrapper.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: AlignWrapper
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:31 $
// $Author: fci $
//
// ------------------------------------------------------------------------
#include "AbsBeamline/AlignWrapper.h"
#include "AbsBeamline/BeamlineVisitor.h"
// Class AlignWrapper
// ------------------------------------------------------------------------
void AlignWrapper::accept(BeamlineVisitor &visitor) const {
visitor.visitAlignWrapper(*this);
}
AlignWrapper *AlignWrapper::clone() const {
return new AlignWrapper(*this);
}
ElementBase *AlignWrapper::copyStructure() {
if(isSharable()) {
return this;
} else {
AlignWrapper *wrap = new AlignWrapper(*this);
wrap->itsElement = itsElement->copyStructure();
return wrap;
}
}
void AlignWrapper::makeSharable() {
shareFlag = true;
itsElement->makeSharable();
}
Euclid3D AlignWrapper::getEntranceTransform() const {
if(itsOffset.isIdentity()) {
return itsOffset;
} else {
Euclid3D frame = itsElement->getEntranceFrame();
return frame.inverse() * itsOffset * frame;
}
}
Euclid3D AlignWrapper::getExitTransform() const {
if(itsOffset.isIdentity()) {
return itsOffset;
} else {
Euclid3D frame = itsElement->getExitFrame();
return frame * Inverse(itsOffset) * Inverse(frame);
}
}
ElementBase *AlignWrapper::getElement() const {
return &*itsElement;
}
void AlignWrapper::setElement(ElementBase *elem) {
itsElement = elem;
}
BGeometryBase &AlignWrapper::getGeometry() {
return itsElement->getGeometry();
}
const BGeometryBase &AlignWrapper::getGeometry() const {
return itsElement->getGeometry();
}
ElementBase::ElementBase::ElementType AlignWrapper::getType() const {
return itsElement->getType();
}
Euclid3D &AlignWrapper::offset() const {
return itsOffset;
}
ElementBase *AlignWrapper::makeAlignWrapper() {
return this;
}
ElementBase *AlignWrapper::makeFieldWrapper() {
itsElement = itsElement->makeFieldWrapper();
itsElement->setName(itsElement->getName());
return this;
}
ElementBase *AlignWrapper::removeAlignWrapper() {
return &*itsElement;
}
const ElementBase *AlignWrapper::removeAlignWrapper() const {
return &*itsElement;
}
ElementBase *AlignWrapper::removeFieldWrapper() {
return new AlignWrapper(itsElement->removeFieldWrapper());
}
const ElementBase *AlignWrapper::removeFieldWrapper() const {
return new AlignWrapper(itsElement->removeFieldWrapper());
}
ElementBase *AlignWrapper::removeWrappers() {
return itsElement->removeWrappers();
}
const ElementBase *AlignWrapper::removeWrappers() const {
return itsElement->removeWrappers();
}
AlignWrapper::AlignWrapper(const AlignWrapper &rhs):
ElementBase(rhs), itsElement(rhs.itsElement), itsOffset(rhs.itsOffset) {
shareFlag = false;
}
AlignWrapper::~AlignWrapper()
{}
AlignWrapper::AlignWrapper(ElementBase *elem):
ElementBase(elem->getName()), itsElement(elem), itsOffset() {
shareFlag = false;
}
\ No newline at end of file
#ifndef CLASSIC_AlignWrapper_HH
#define CLASSIC_AlignWrapper_HH
// ------------------------------------------------------------------------
// $RCSfile: AlignWrapper.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: AlignWrapper
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:31 $
// $Author: fci $
//
// ------------------------------------------------------------------------
#include "AbsBeamline/ElementBase.h"
#include "BeamlineGeometry/Euclid3D.h"
#include "MemoryManagement/Pointer.h"
class BeamlineVisitor;
// Class AlignWrapper
// ------------------------------------------------------------------------
/// Define the position of a misaligned element.
// An AlignWrapper is used to store misalignment errors or deliberate
// misalignments. It acts as a wrapper around a component or a complete
// beam line. Rotations and translations are defined about the design
// local frame, which in turn is specified by the position of the element
// on the design geometry. An AlignWrapper is non-sharable by default.
class AlignWrapper: public ElementBase {
friend class ElementBase;
public:
/// Apply BeamlineVisitor.
virtual void accept(BeamlineVisitor &) const override;
/// Return clone.
// Return an identical deep copy of the wrapper and its contents.
virtual AlignWrapper *clone() const override;
/// Make structural copy.
virtual ElementBase *copyStructure() override;
/// Set sharable flag.
// The whole structure depending on [b]this[/b] is marked as sharable.
// After this call a [b]copyStructure()[/b] call reuses the element.
virtual void makeSharable() override;
/// Get entrance patch.
// Returns the entrance patch (transformation) which is used to
// transform the global geometry to the local geometry at entrance
// of the misaligned element.
virtual Euclid3D getEntranceTransform() const;
/// Get exit patch.
// Returns the exit patch (transformation) which is used to
// transform the local geometry to the global geometry at exit of
// the misaligned element.
virtual Euclid3D getExitTransform() const;
/// Return the contained element.
virtual ElementBase *getElement() const;
/// Replace the contained element.
void setElement(ElementBase *);
/// Get geometry.
// Return the element geometry.
// Version for non-constant object.
virtual BGeometryBase &getGeometry() override;
/// Get geometry.
// Return the element geometry.
// Version for constant object.
virtual const BGeometryBase &getGeometry() const override;
/// Return the offset.
// This method can be used to get or set the offset. The offset is
// declared as mutable, so as to allow changing it in a constant
// structure.
Euclid3D &offset() const;
/// Get element type std::string.
// Returns the type std::string for the enclosed item.
virtual ElementBase::ElementBase::ElementType getType() const override;
/// Disallow misalignment of an already misaligned object.
// This method returns [b]this[/b], since "this" is already an
// AlignWrapper.
virtual ElementBase *makeAlignWrapper() override;
/// Allow field errors.
// Wrap the contained element in a field wrapper, unless such a
// wrapper already exists.
virtual ElementBase *makeFieldWrapper() override;
/// Remove AlignWrapper.
// Return the element or field wrapper contained in "this".
// Version for non-const object.
virtual ElementBase *removeAlignWrapper() override;
/// Remove AlignWrapper.
// Return the element or field wrapper contained in "this".
// Version for const object.
virtual const ElementBase *removeAlignWrapper() const override;
/// Remove field wrapper.
// Remove any field wrapper on the contained object.
virtual ElementBase *removeFieldWrapper() override;
/// Remove field wrapper.
// Remove the field wrapper for constant object.
virtual const ElementBase *removeFieldWrapper() const override;
/// Return the design element.
// This method removes all wrappers on the contained object.
// Version for non-const object.
virtual ElementBase *removeWrappers() override;
/// Return the design element.
// Version for const object.
virtual const ElementBase *removeWrappers() const override;