Component.h 6.98 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
#ifndef CLASSIC_Component_HH
#define CLASSIC_Component_HH

// ------------------------------------------------------------------------
// $RCSfile: Component.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: Component
//   An abstract base class which defines the common interface for all
//   CLASSIC components, i.e. beam line members which are not themselves
//   beam lines.
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:31 $
// $Author: fci $
//
// ------------------------------------------------------------------------

#include "AbsBeamline/ElementBase.h"
#include "Fields/EMField.h"
28
#include "Algorithms/PBunchDefs.h"
gsell's avatar
gsell committed
29 30 31 32

#define EPS_MISALIGNMENT 1e-8

class PartData;
33
class PartBunch;
gsell's avatar
gsell committed
34 35
template <class T, int N> class FVps;

36 37 38 39 40
struct Point
{
  double x;
  double y;
};
gsell's avatar
gsell committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54

// Class Component
// ------------------------------------------------------------------------
/// Interface for a single beam element.
//  Class Component defines the abstract interface for an arbitrary single
//  component in a beam line.  A component is the basic element in the
//  accelerator model, like a dipole, a quadrupole, etc.  It is normally
//  associated with an electro-magnetic field, which may be null.

class Component: public ElementBase {

public:

    /// Constructor with given name.
Steve Russell's avatar
Steve Russell committed
55
    explicit Component(const std::string &name);
gsell's avatar
gsell committed
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

    Component();
    Component(const Component &right);
    virtual ~Component();

    /// Return field.
    //  The representation of the electro-magnetic field of the component
    //  (version for non-constant object).
    virtual EMField &getField() = 0;

    /// Return field.
    //  The representation of the electro-magnetic field of the component
    //  (version for constant object).
    virtual const EMField &getField() const = 0;

    /// Return the field in a point.
    //  Return the value of the time-independent part of the electric
    //  field at point [b]P[/b].
    EVector Efield(const Point3D &P) const;

    /// Return the field in a point.
    //  Return the value of the time-independent part of the magnetic
    //  field at point [b]P[/b].
    BVector Bfield(const Point3D &P) const;

    /// Return the field in a point.
    //  Return the value of the time-dependent part of the electric
    //  field at point [b]P[/b] for time [b]t[/b].
    EVector Efield(const Point3D &P, double t) const;

    /// Return the field in a point.
    //  Return the value of the time-dependent part of the magnetic
    //  field at point [b]P[/b] for time [b]t[/b].
    BVector Bfield(const Point3D &P, double t) const;

    /// Return the field in a point.
    //  Return the value of the time-independent part of both electric
    //  and magnetic fields at point [b]P[/b].
    EBVectors EBfield(const Point3D &P) const;

    /// Return the field in a point.
    //  Return the value of the time-dependent part of both electric
    //  and magnetic fields at point [b]P[/b] for time [b]t[/b].
    EBVectors EBfield(const Point3D &P, double t) const;

    virtual void addKR(int i, double t, Vector_t &K) {};

    virtual void addKT(int i, double t, Vector_t &K) {};

    virtual bool apply(const int &i, const double &t, double E[], double B[]) = 0;

    virtual bool apply(const int &i, const double &t, Vector_t &E, Vector_t &B) = 0;

    virtual bool apply(const Vector_t &R, const Vector_t &centroid, const double &t, Vector_t &E, Vector_t &B) = 0;

    virtual void initialise(PartBunch *bunch, double &startField, double &endField, const double &scaleFactor) = 0;

    virtual void finalise() = 0;

    virtual bool bends() const = 0;

    virtual void goOnline();

    virtual void goOffline();

    virtual bool Online();

    void getOrientation(Vector_t &, double &) const;  // first component is alpha, second is beta. the third component is always neglected.
    // alpha is defined as the angle between projection of the normal of the face of the element onto
    // the s-u plane and the s vector. for beta the following is valid:
    // beta = arccos(|n_{parallel}|) where n_{parallel} is the projection of the normal onto the s-u
    // plane

    void setOrientation(const Vector_t &direction);

    virtual void getDimensions(double &zBegin, double &zEnd) const = 0;

Steve Russell's avatar
Steve Russell committed
133
    virtual const std::string &getType() const;
gsell's avatar
gsell committed
134

Steve Russell's avatar
Steve Russell committed
135 136
    virtual void setComponentType(std::string name) { };
    virtual std::string getComponentType() const { return ""; };
gsell's avatar
gsell committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208

    /// Return design element.
    //  If a component is a wrapper, this method returns a pointer to
    //  its underlying design element, otherwise a pointer to this component.
    //  The default version returns ``this''.
    virtual const ElementBase &getDesign() const;

    /// Track particle bunch.
    //  This catch-all method implements a hook for tracking a particle
    //  bunch through a non-standard component.
    //  The default version throws a LogicalError.
    virtual void trackBunch(PartBunch &bunch, const PartData &,
                            bool revBeam, bool revTrack) const;

    /// Track a map.
    //  This catch-all method implements a hook for tracking a transfer
    //  map through a non-standard component.
    //  The default version throws a LogicalError.
    virtual void trackMap(FVps<double, 6> &map, const PartData &,
                          bool revBeam, bool revTrack) const;

    void setMisalignment(double x, double y, double s);

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

    void setExitFaceSlope(const double &);

protected:

    double dx_m;
    double dy_m;
    double ds_m;
    Vector_t Orientation_m;
    double exit_face_slope_m;

    PartBunch *RefPartBunch_m;
    bool online_m;
};


// Inline access functions to fields.
// ------------------------------------------------------------------------

inline EVector Component::Efield(const Point3D &P) const
{ return getField().Efield(P); }

inline BVector Component::Bfield(const Point3D &P) const
{ return getField().Bfield(P); }

inline EVector Component::Efield(const Point3D &P, double t) const
{ return getField().Efield(P, t); }

inline BVector Component::Bfield(const Point3D &P, double t) const
{ return getField().Bfield(P, t); }

inline EBVectors Component::EBfield(const Point3D &P) const
{ return getField().EBfield(P); }

inline EBVectors Component::EBfield(const Point3D &P, double t) const
{ return getField().EBfield(P, t); }

inline void Component::getOrientation(Vector_t &ori, double &m) const {
    ori = Orientation_m;
    m = exit_face_slope_m;
}

inline void Component::setOrientation(const Vector_t &direction)
{ Orientation_m = direction; }

inline void Component::setExitFaceSlope(const double &m)
{ exit_face_slope_m = m; }
#endif // CLASSIC_Component_HH