ElementBase.h 22.2 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#ifndef CLASSIC_ElementBase_HH
#define CLASSIC_ElementBase_HH 1

// ------------------------------------------------------------------------
// $RCSfile: ElementBase.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.2 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: ElementBase
//   The very base class for beam line representation objects.  A beam line
//   is modelled as a composite structure having a single root object
//   (the top level beam line), which contains both ``single'' leaf-type
//   elements (Components), as well as sub-lines (composites).
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/12/16 16:26:43 $
// $Author: mad $
//
// ------------------------------------------------------------------------

#include "AbsBeamline/AttributeSet.h"
#include "BeamlineGeometry/Geometry.h"
#include "MemoryManagement/RCObject.h"
30 31 32
#include "Algorithms/Vektor.h"
#include "Algorithms/Quaternion.h"
#include "Algorithms/CoordinateSystemTrafo.h"
33
#include "Utilities/GeneralClassicException.h"
34

gsell's avatar
gsell committed
35
#include <string>
36
#include <queue>
gsell's avatar
gsell committed
37 38

class BeamlineVisitor;
snuverink_j's avatar
snuverink_j committed
39
class BoundaryGeometry;
gsell's avatar
gsell committed
40 41 42
class Channel;
class ConstChannel;
class ElementImage;
43
class ParticleMatterInteractionHandler;
snuverink_j's avatar
snuverink_j committed
44
class WakeFunction;
gsell's avatar
gsell committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

// Class ElementBase
// ------------------------------------------------------------------------
/// Interface for basic beam line object.
//  This class defines the abstract interface for all objects which can be
//  contained in a beam line. ElementBase forms the base class for two distinct
//  but related hierarchies of objects:
//  [OL]
//  [LI]
//  A set of concrete accelerator element classes, which compose the standard
//  accelerator component library (SACL).
//  [LI]
//  A second hierarchy which parallels the SACL, acting as container or
//  wrapper-like objects.  These latter classes are used to construct
//  beam-lines composed of referenced ``design'' components, together with
//  beam-line position dependent extrinsic state (e. g. errors). These wrapper
//  objects are by default unique.
//  [/OL]
//  Also derived from ElementBase there is a class AlignWrapper, which can
//  be used to store misalignment errors or deliberate displacements.
//  Any element can have only one AlignWrapper and one FieldWrapper.  To be
//  processed in the correct order, the AlignWrapper must be the outermost.
//  [pre]
//    AlignWrapper --> FieldWrapper --> Element
//  [/pre]
//  To ensure this structure, wrapper elements cannot be constructed directly,
//  one should rather call one of:
//  [dl]
//  [dt]makeAlignWrapper()  [dd]make an align wrapper.
//  [dt]makeFieldWrapper()  [dd]make a field wrapper.
//  [dt]makeWrappers()      [dd]make both wrappers.
//  [/dl]
//  An existing wrapper can be removed by
//  [dl]
//  [dt]removeAlignWrapper()[dd]remove align wrapper.
//  [dt]removeFieldWrapper()[dd]remove field wrapper.
//  [/dl]
//  Instances of the concrete classes for single elements are by default
//  sharable.  Instances of beam lines, wrappers and integrators are by
//  default non-sharable, but they may be made sharable by a call to
//  [b]makeSharable()[/b].
//  [p]
//  An ElementBase object can return two lengths, which may be different:
//  [OL]
//  [LI]
//  The arc length along the geometry.
//  [LI]
//  The design length, often measured along a straight line.
//  [/OL]
//  Class ElementBase contains a map of name versus value for user-defined
//  attributes (see file AbsBeamline/AttributeSet.hh).  The map is primarily
//  intended for processes that require algorithm-specific data in the
//  accelerator model.
//  [P]
//  The class ElementBase has as base class the abstract class RCObject.
//  Virtual derivation is used to make multiple inheritance possible for
//  derived concrete classes. ElementBase implements three copy modes:
//  [OL]
//  [LI]
//  Copy by reference: Call RCObject::addReference() and use [b]this[/b].
//  [LI]
//  Copy structure: use ElementBase::copyStructure().
//  During copying of the structure, all sharable items are re-used, while
//  all non-sharable ones are cloned.
//  [LI]
//  Copy by cloning: use ElementBase::clone().
//  This returns a full deep copy.
//  [/OL]


115
class ElementBase: public RCObject, public std::enable_shared_from_this<ElementBase> {
gsell's avatar
gsell committed
116 117

public:
118 119 120 121
    typedef std::shared_ptr<ElementBase> SP;
    typedef std::shared_ptr<const ElementBase> ConstSP;
    typedef std::weak_ptr<ElementBase> WP;
    typedef std::weak_ptr<const ElementBase> ConstWP;
gsell's avatar
gsell committed
122 123

    /// Constructor with given name.
124
    explicit ElementBase(const std::string &name);
gsell's avatar
gsell committed
125 126 127 128 129 130

    ElementBase();
    ElementBase(const ElementBase &);
    virtual ~ElementBase();

    /// Get element name.
131
    virtual const std::string &getName() const;
gsell's avatar
gsell committed
132 133

    /// Set element name.
134
    virtual void setName(const std::string &name);
gsell's avatar
gsell committed
135

136 137 138 139 140
    enum ApertureType {RECTANGULAR
                     , ELLIPTICAL
                     , CONIC_RECTANGULAR
                     , CONIC_ELLIPTICAL
    };
141 142 143 144

    enum ElementType {ALIGNWRAPPER
                    , BEAMBEAM
                    , BEAMLINE
145
                    , BEAMSTRIPPING
146
                    , CCOLLIMATOR
147 148 149 150 151 152
                    , CORRECTOR
                    , CORRECTORWRAPPER
                    , CYCLOTRON
                    , CYCLOTRONWRAPPER
                    , DEGRADER
                    , DIAGNOSTIC
frey_m's avatar
frey_m committed
153
                    , DRIFT
154
                    , FLEXIBLECOLLIMATOR
155 156 157 158 159 160
                    , INTEGRATOR
                    , LAMBERTSON
                    , MARKER
                    , MONITOR
                    , MPSPLITINTEGRATOR
                    , MULTIPOLE
ext-rogers_c's avatar
ext-rogers_c committed
161
                    , MULTIPOLET
162 163 164 165 166 167
                    , MULTIPOLEWRAPPER
                    , OFFSET
                    , PARALLELPLATE
                    , PATCH
                    , PROBE
                    , RBEND
168
                    , RBEND3D
169 170 171 172 173 174 175 176 177 178
                    , RBENDWRAPPER
                    , RFCAVITY
                    , RFQUADRUPOLE
                    , RING
                    , SBEND3D
                    , SBEND
                    , SBENDWRAPPER
                    , SEPARATOR
                    , SEPTUM
                    , SOLENOID
179
                    , SOURCE
180 181 182 183 184
                    , STRIPPER
                    , TRAVELINGWAVE
                    , VARIABLERFCAVITY
                    , ANY};

185
    /// Get element type std::string.
186 187 188
    virtual ElementType getType() const = 0;

    std::string getTypeString() const;
189
    static std::string getTypeString(ElementType type);
gsell's avatar
gsell committed
190 191 192 193

    /// Get geometry.
    //  Return the element geometry.
    //  Version for non-constant object.
194
    virtual BGeometryBase  &getGeometry() = 0;
gsell's avatar
gsell committed
195 196 197 198

    /// Get geometry.
    //  Return the element geometry
    //  Version for constant object.
199
    virtual const BGeometryBase  &getGeometry() const = 0;
gsell's avatar
gsell committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214

    /// Get arc length.
    //  Return the entire arc length measured along the design orbit
    virtual double getArcLength() const;

    /// Get design length.
    //  Return the design length defined by the geometry.
    //  This may be the arc length or the straight length.
    virtual double getElementLength() const;

    /// Set design length.
    //  Set the design length defined by the geometry.
    //  This may be the arc length or the straight length.
    virtual void setElementLength(double length);

215 216 217 218 219 220
    virtual void getElementDimensions(double &begin,
                                      double &end) const {
        begin = 0.0;
        end = getElementLength();
    }

gsell's avatar
gsell committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
    /// Get origin position.
    //  Return the arc length from the entrance to the origin of the element
    //  (origin >= 0)
    virtual double getOrigin() const;

    /// Get entrance position.
    //  Return the arc length from the origin to the entrance of the element
    //  (entrance <= 0)
    virtual double getEntrance() const;

    /// Get exit position.
    //  Return the arc length from the origin to the exit of the element
    //  (exit >= 0)
    virtual double getExit() const;

    /// Get transform.
    //  Return the transform of the local coordinate system from the
    //  position [b]fromS[/b] to the position [b]toS[/b].
    virtual Euclid3D getTransform(double fromS, double toS) const;

    /// Get transform.
    //  Equivalent to getTransform(0.0, s).
    //  Return the transform of the local coordinate system from the
    //  origin and [b]s[/b].
    virtual Euclid3D getTransform(double s) const;

    /// Get transform.
    //  Equivalent to getTransform(getEntrance(), getExit()).
    //  Return the transform of the local coordinate system from the
    //  entrance to the exit of the element.
    virtual Euclid3D getTotalTransform() const;

    /// Get transform.
    //  Equivalent to getTransform(0.0, getEntrance()).
    //  Return the transform of the local coordinate system from the
    //  origin to the entrance of the element.
    virtual Euclid3D getEntranceFrame() const;

    /// Get transform.
    //  Equivalent to getTransform(0.0, getExit()).
    //  Return the transform of the local coordinate system from the
    //  origin to the exit of the element.
    virtual Euclid3D getExitFrame() const;

    /// Get patch.
    //  Returns the entrance patch (transformation) which is used to transform
    //  the global geometry to the local geometry for a misaligned element
    //  at its entrance. The default behaviour returns identity transformation.
    //  This function should be overridden by derived concrete classes which
    //  model complex geometries.
    virtual Euclid3D getEntrancePatch() const;

    /// Get patch.
    //  Returns the entrance patch (transformation) which is used to transform
    //  the local geometry to the global geometry for a misaligned element
    //  at its exit. The default behaviour returns identity transformation.
    //  This function should be overridden by derived concrete classes which
    //  model complex geometries.
    virtual Euclid3D getExitPatch() const;

    /// Get attribute value.
    //  If the attribute does not exist, return zero.
283
    virtual double getAttribute(const std::string &aKey) const;
gsell's avatar
gsell committed
284 285 286

    /// Test for existence of an attribute.
    //  If the attribute exists, return true, otherwise false.
287
    virtual bool hasAttribute(const std::string &aKey) const;
gsell's avatar
gsell committed
288 289

    /// Remove an existing attribute.
290
    virtual void removeAttribute(const std::string &aKey);
gsell's avatar
gsell committed
291 292

    /// Set value of an attribute.
293
    virtual void setAttribute(const std::string &aKey, double val);
gsell's avatar
gsell committed
294 295 296 297 298

    /// Construct a read/write channel.
    //  This method constructs a Channel permitting read/write access to
    //  the attribute [b]aKey[/b] and returns it.
    //  If the attribute does not exist, it returns NULL.
299
    virtual Channel *getChannel(const std::string &aKey, bool create = false);
gsell's avatar
gsell committed
300 301 302 303 304

    /// Construct a read-only channel.
    //  This method constructs a Channel permitting read-only access to
    //  the attribute [b]aKey[/b] and returns it.
    //  If the attribute does not exist, it returns NULL.
305
    virtual const ConstChannel *getConstChannel(const std::string &aKey) const;
gsell's avatar
gsell committed
306 307

    /// Construct an image.
308
    //  Return the image of the element, containing the name and type std::string
gsell's avatar
gsell committed
309 310 311 312 313 314 315 316 317 318 319 320
    //  of the element, and a copy of the user-defined attributes.
    virtual ElementImage *getImage() const;

    /// Apply visitor.
    //  This method must be overridden by derived classes. It should call the
    //  method of the visitor corresponding to the element class.
    //  If any error occurs, this method throws an exception.
    virtual void accept(BeamlineVisitor &visitor) const = 0;


    /// Return clone.
    //  Return an identical deep copy of the element.
321
    virtual ElementBase::SP clone() const = 0;
gsell's avatar
gsell committed
322 323 324 325

    /// Make a structural copy.
    //  Return a fresh copy of any beam line structure is made,
    //  but sharable elements remain shared.
326
    virtual ElementBase::SP copyStructure();
gsell's avatar
gsell committed
327 328 329 330 331 332 333 334 335 336 337 338 339 340

    /// Test if the element can be shared.
    bool isSharable() const;

    /// 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();

    /// Allow misalignment.
    //  Build an AlignWrapper pointing to the element and return a pointer to
    //  that wrapper.  If the element cannot be misaligned, or already has an
    //  AlignWrapper, return a pointer to the element.
    //  Wrappers are non-sharable, unless otherwise defined.
341
    virtual ElementBase::SP makeAlignWrapper();
gsell's avatar
gsell committed
342 343 344 345 346 347

    /// Allow field errors.
    //  Build a FieldWrapper pointing to the element and return a pointer to
    //  that wrapper.  If the element cannot have field errors, or already has
    //  a FieldWrapper, return a pointer to the element.
    //  Wrappers are non-sharable, unless otherwise defined.
348
    virtual ElementBase::SP makeFieldWrapper();
gsell's avatar
gsell committed
349 350 351 352 353 354 355

    /// Allow errors.
    //  Equivalent to the calls
    //  [pre]
    //    makeFieldWrapper()->makeAlignWrapper()
    //  [/pre].
    //  Wrappers are non-sharable, unless otherwise defined.
356
    virtual ElementBase::SP makeWrappers();
gsell's avatar
gsell committed
357 358 359

    /// Remove align wrapper.
    //  Remove the align wrapper.
360
    virtual ElementBase::SP removeAlignWrapper();
gsell's avatar
gsell committed
361 362 363

    /// Remove align wrapper.
    //  Remove the align wrapper.
364
    virtual ElementBase::ConstSP removeAlignWrapper() const;
gsell's avatar
gsell committed
365 366 367

    /// Remove field wrapper.
    //  Remove the field wrapper.
368
    virtual ElementBase::SP removeFieldWrapper();
gsell's avatar
gsell committed
369 370 371

    /// Remove field wrapper.
    //  Remove the field wrapper for constant object.
372
    virtual ElementBase::ConstSP removeFieldWrapper() const;
gsell's avatar
gsell committed
373 374 375

    /// Return the design element.
    //  Return [b]this[/b], if the element is not wrapped.
376
    virtual ElementBase::SP removeWrappers();
gsell's avatar
gsell committed
377 378 379

    /// Return the design element.
    //  Return [b]this[/b], if the element is not wrapped.
380
    virtual ElementBase::ConstSP removeWrappers() const;
gsell's avatar
gsell committed
381 382 383 384 385 386

    /// Update element.
    //  This method stores all attributes contained in the AttributeSet to
    //  "*this".  The return value [b]true[/b] indicates success.
    bool update(const AttributeSet &);

snuverink_j's avatar
snuverink_j committed
387
    ///@{ Access to ELEMEDGE attribute
388 389 390
    void setElementPosition(double elemedge);
    double getElementPosition() const;
    bool isElementPositionSet() const;
snuverink_j's avatar
snuverink_j committed
391
    ///@}
gsell's avatar
gsell committed
392 393 394 395 396 397 398 399 400 401
    /// attach a boundary geometry field to the element
    virtual void setBoundaryGeometry(BoundaryGeometry *geo);

    /// return the attached boundary geometrt object if there is any
    virtual BoundaryGeometry *getBoundaryGeometry() const;

    virtual bool hasBoundaryGeometry() const;


    /// attach a wake field to the element
402
    virtual void setWake(std::shared_ptr<WakeFunction> const& wf);
gsell's avatar
gsell committed
403 404

    /// return the attached wake object if there is any
405
    virtual std::shared_ptr<WakeFunction> getWake() const;
gsell's avatar
gsell committed
406 407 408

    virtual bool hasWake() const;

409
    virtual void setParticleMatterInteraction(std::shared_ptr<ParticleMatterInteractionHandler> const& spys);
gsell's avatar
gsell committed
410

411
    virtual std::shared_ptr<ParticleMatterInteractionHandler> getParticleMatterInteraction() const;
gsell's avatar
gsell committed
412

413
    virtual bool hasParticleMatterInteraction() const;
gsell's avatar
gsell committed
414

415 416
    void setCSTrafoGlobal2Local(const CoordinateSystemTrafo &ori);
    CoordinateSystemTrafo getCSTrafoGlobal2Local() const;
417
    void releasePosition();
418
    void fixPosition();
419
    bool isPositioned() const;
420

421 422
    virtual CoordinateSystemTrafo getEdgeToBegin() const;
    virtual CoordinateSystemTrafo getEdgeToEnd() const;
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441

    void setAperture(const ApertureType& type, const std::vector<double> &args);
    std::pair<ElementBase::ApertureType, std::vector<double> > getAperture() const;

    virtual bool isInside(const Vector_t &r) const;

    void setMisalignment(double x, double y, double s);
    void setMisalignment(const CoordinateSystemTrafo &cst);

    void getMisalignment(double &x, double &y, double &s) const;
    CoordinateSystemTrafo getMisalignment() const;

    void setActionRange(const std::queue<std::pair<double, double> > &range);
    void setCurrentSCoordinate(double s);

    /// Set rotation about z axis in bend frame.
    void setRotationAboutZ(double rotation);
    double getRotationAboutZ() const;

gsell's avatar
gsell committed
442
protected:
443
    bool isInsideTransverse(const Vector_t &r, double f = 1) const;
gsell's avatar
gsell committed
444 445 446 447 448

    // Sharable flag.
    // If this flag is true, the element is always shared.
    mutable bool shareFlag;

449 450 451 452 453 454 455 456 457
    CoordinateSystemTrafo csTrafoGlobal2Local_m;
    CoordinateSystemTrafo misalignment_m;

    std::pair<ApertureType, std::vector<double> > aperture_m;

    double elementEdge_m;

    double rotationZAxis_m;

gsell's avatar
gsell committed
458 459 460 461 462 463
private:

    // Not implemented.
    void operator=(const ElementBase &);

    // The element's name
464
    std::string elementID;
gsell's avatar
gsell committed
465 466 467 468

    // The user-defined set of attributes.
    AttributeSet userAttribs;

469
    std::shared_ptr<WakeFunction> wake_m;
gsell's avatar
gsell committed
470 471 472

    BoundaryGeometry *bgeometry_m;

473
    std::shared_ptr<ParticleMatterInteractionHandler> parmatint_m;
gsell's avatar
gsell committed
474

475
    bool positionIsFixed;
snuverink_j's avatar
snuverink_j committed
476
    ///@{ ELEMEDGE attribute
477 478
    double elementPosition_m;
    bool elemedgeSet_m;
snuverink_j's avatar
snuverink_j committed
479
    ///@}
480
    std::queue<std::pair<double, double> > actionRange_m;
gsell's avatar
gsell committed
481 482 483 484 485 486
};


// Inline functions.
// ------------------------------------------------------------------------

487 488
inline
double ElementBase::getArcLength() const
gsell's avatar
gsell committed
489 490
{ return getGeometry().getArcLength(); }

491 492
inline
double ElementBase::getElementLength() const
gsell's avatar
gsell committed
493 494
{ return getGeometry().getElementLength(); }

495 496
inline
void ElementBase::setElementLength(double length)
gsell's avatar
gsell committed
497 498
{ getGeometry().setElementLength(length); }

499 500
inline
double ElementBase::getOrigin() const
gsell's avatar
gsell committed
501 502
{ return getGeometry().getOrigin(); }

503 504
inline
double ElementBase::getEntrance() const
gsell's avatar
gsell committed
505 506
{ return getGeometry().getEntrance(); }

507 508
inline
double ElementBase::getExit() const
gsell's avatar
gsell committed
509 510
{ return getGeometry().getExit(); }

511 512
inline
Euclid3D ElementBase::getTransform(double fromS, double toS) const
gsell's avatar
gsell committed
513 514
{ return getGeometry().getTransform(fromS, toS); }

515 516
inline
Euclid3D ElementBase::getTotalTransform() const
gsell's avatar
gsell committed
517 518
{ return getGeometry().getTotalTransform(); }

519 520
inline
Euclid3D ElementBase::getTransform(double s) const
gsell's avatar
gsell committed
521 522
{ return getGeometry().getTransform(s); }

523 524
inline
Euclid3D ElementBase::getEntranceFrame() const
gsell's avatar
gsell committed
525 526
{ return getGeometry().getEntranceFrame(); }

527 528
inline
Euclid3D ElementBase::getExitFrame() const
gsell's avatar
gsell committed
529 530
{ return getGeometry().getExitFrame(); }

531 532
inline
Euclid3D ElementBase::getEntrancePatch() const
gsell's avatar
gsell committed
533 534
{ return getGeometry().getEntrancePatch(); }

535 536
inline
Euclid3D ElementBase::getExitPatch() const
gsell's avatar
gsell committed
537 538
{ return getGeometry().getExitPatch(); }

539 540
inline
bool ElementBase::isSharable() const
gsell's avatar
gsell committed
541 542
{ return shareFlag; }

543
inline
544
std::shared_ptr<WakeFunction> ElementBase::getWake() const
gsell's avatar
gsell committed
545 546
{ return wake_m; }

547 548
inline
bool ElementBase::hasWake() const
549
{ return wake_m != nullptr; }
gsell's avatar
gsell committed
550

551 552
inline
BoundaryGeometry *ElementBase::getBoundaryGeometry() const
gsell's avatar
gsell committed
553 554
{ return bgeometry_m; }

555 556
inline
bool ElementBase::hasBoundaryGeometry() const
gsell's avatar
gsell committed
557 558
{ return bgeometry_m != NULL; }

559
inline
560
std::shared_ptr<ParticleMatterInteractionHandler> ElementBase::getParticleMatterInteraction() const
561
{ return parmatint_m; }
gsell's avatar
gsell committed
562

563
inline
564
bool ElementBase::hasParticleMatterInteraction() const
565
{ return parmatint_m != nullptr; }
gsell's avatar
gsell committed
566

567 568 569 570 571 572 573 574 575 576 577 578 579
inline
void ElementBase::setCSTrafoGlobal2Local(const CoordinateSystemTrafo &trafo)
{
    if (positionIsFixed) return;

    csTrafoGlobal2Local_m = trafo;
}

inline
CoordinateSystemTrafo ElementBase::getCSTrafoGlobal2Local() const
{ return csTrafoGlobal2Local_m; }

inline
580 581 582 583 584 585 586 587 588 589
CoordinateSystemTrafo ElementBase::getEdgeToBegin() const
{
    CoordinateSystemTrafo ret(Vector_t(0, 0, 0),
                              Quaternion(1, 0, 0, 0));

    return ret;
}

inline
CoordinateSystemTrafo ElementBase::getEdgeToEnd() const
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
{
    CoordinateSystemTrafo ret(Vector_t(0, 0, getElementLength()),
                              Quaternion(1, 0, 0, 0));

    return ret;
}

inline
void ElementBase::setAperture(const ApertureType& type, const std::vector<double> &args)
{
    aperture_m.first = type;
    aperture_m.second = args;
}

inline
std::pair<ElementBase::ApertureType, std::vector<double> > ElementBase::getAperture() const
{
    return aperture_m;
}

inline
bool ElementBase::isInside(const Vector_t &r) const
{
    const double length = getElementLength();
    return isInsideTransverse(r, r(2) / length * aperture_m.second[2]) && r(2) >= 0.0 && r(2) < length;
}

inline
bool ElementBase::isInsideTransverse(const Vector_t &r, double f) const
{
    switch(aperture_m.first) {
    case RECTANGULAR:
        return (std::abs(r[0]) < aperture_m.second[0] && std::abs(r[1]) < aperture_m.second[1]);
    case ELLIPTICAL:
        return (std::pow(r[0] / aperture_m.second[0], 2) + std::pow(r[1] / aperture_m.second[1], 2) < 1.0);
    case CONIC_RECTANGULAR:
626
        return (std::abs(r[0]) < f * aperture_m.second[0] && std::abs(r[1]) < f * aperture_m.second[1]);
627
    case CONIC_ELLIPTICAL:
628
        return (std::pow(r[0] / (f * aperture_m.second[0]), 2) + std::pow(r[1] / (f * aperture_m.second[1]), 2) < 1.0);
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
    default:
        return false;
    }
}

inline
void ElementBase::setMisalignment(const CoordinateSystemTrafo &cst) {
    misalignment_m = cst;
}

inline
CoordinateSystemTrafo ElementBase::getMisalignment() const {
    return misalignment_m;
}

644 645 646 647 648
inline
void ElementBase::releasePosition() {
    positionIsFixed = false;
}

649 650 651 652 653 654
inline
void ElementBase::fixPosition() {
    positionIsFixed = true;
}

inline
655
bool ElementBase::isPositioned() const {
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
    return positionIsFixed;
}

inline
void ElementBase::setActionRange(const std::queue<std::pair<double, double> > &range) {
    actionRange_m = range;

    if (actionRange_m.size() > 0)
        elementEdge_m = actionRange_m.front().first;
}

inline
void ElementBase::setRotationAboutZ(double rotation) {
    rotationZAxis_m = rotation;
}

inline
double ElementBase::getRotationAboutZ() const {
    return rotationZAxis_m;
}

inline
std::string ElementBase::getTypeString() const
679 680
{ return getTypeString(getType());}

681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
inline
void ElementBase::setElementPosition(double elemedge) {
    elementPosition_m = elemedge;
    elemedgeSet_m = true;
}

inline
double ElementBase::getElementPosition() const {
    if (elemedgeSet_m)
        return elementPosition_m;

    throw GeneralClassicException("ElementBase::getElementPosition()",
                                  std::string("ELEMEDGE for \"") + getName() + "\" not set");
}

inline
bool ElementBase::isElementPositionSet() const
{ return elemedgeSet_m; }


frey_m's avatar
frey_m committed
701
#endif // CLASSIC_ElementBase_HH