/home/cern/BDSIM_new/include/myMultipoleField.hh

00001 // gab (after NJW)
00002 #ifndef myMultipoleField_h
00003 #define myMultipoleField_h 1
00004 
00005 
00006 //#include "merlin_config.h"
00007 
00008 #include <vector>
00009 #include <utility>
00010 #include <iostream>
00011 //#include "NumericalUtils/Complex.h"
00012 // gab: 
00013 #include<complex>
00014 
00015 // Space3D
00016 //#include "EuclideanGeometry/Space3D.h"
00017 #include"G4ThreeVector.hh"
00018 #include "globals.hh"
00019 
00020 // EMFieldRegion
00021 //#include "AcceleratorModel/EMFieldRegion.h"
00022 
00023 //      A representation of a multipole expansion of a magnetic
00024 //      field having only a non-zero component of the magnetic
00025 //      vector potential in the z-direction. The general
00026 //      expression for the series is give as
00027 //
00028 //                                                               
00029 //                                              n
00030 //           By+i Bx =  Sum  B0 (bn-i an) (z/r0)
00031 //                      n=0
00032 //
00033 //      where z=(x+iy). B0 is the overall scale (in Tesla), and
00034 //      r0 is an aribitrary defining radius. For Multipole
00035 //      expansions representing ideal single multipoles (e.g.
00036 //      dipole, quadrupole etc), then B0 is set to the field
00037 //      strength at r0, and consequently |bn+ i an|=1.
00038 
00039       typedef complex<G4double> Complex;
00040       typedef G4ThreeVector Vector3D;
00041       typedef G4ThreeVector Point3D;
00042 
00043 class myMultipoleField 
00044 {
00045   public:
00046 
00047       typedef std::vector<Complex > TermExpansion;
00048 
00049 
00050    typedef TermExpansion::iterator iterator;
00051 
00052    typedef TermExpansion::const_iterator const_iterator;
00053 
00054   public:
00055       myMultipoleField (G4double scale, size_t nt = 0);
00056       myMultipoleField (int np, G4double bn, G4double an, G4double r0);
00057 
00058       myMultipoleField (int np, G4double bn, G4double r0, bool skew = false);
00059       myMultipoleField (int np, G4double bn, bool skew = false);
00060 
00061 
00062 
00063       //        Returns the current normalising scale for the field (in
00064       //        Tesla)
00065       G4double GetFieldScale () const;
00066 
00067       //        Set the (normalising) scale of the field (units are in
00068       //        Tesla).
00069       void SetFieldScale (G4double scale);
00070 
00071       //        Returns true if this field is a null field.
00072       bool IsNullField () const;
00073 
00074       //        Returns the normalised field component Kn for the
00075       //        specified magnetic rigidity brho. Kn is defined as
00076       //        Dn[By+iBx]/brho, where Dn is the n-th complex derivative
00077       //        wrt x+i y, evaluated at (x+iy)=0. If brho is in
00078       //        Tesla.meter, Kn has the units 1/meter^(n+1).
00079       Complex GetKn (int np, G4double rigidity) const;
00080 
00081       //        Returns the 2-D magnetic field in Tesla as the complex
00082       //        number By+i Bx at the point (x,y) (in meters). The
00083       //        optional parameter exclude can be used to exclude terms
00084       //        lower than or equal to exclude Thus a value of exclude=1
00085       //        gives only that field due to the non-linear terms
00086       //        (sextupole and above). A Value of -1 (default) includes
00087       //        all multipole terms.
00088       Complex GetField2D (G4double x, G4double y, int exclude = -1) const;
00089 
00090       //        Returns the magnetic field at the point x. The time
00091       //        variable t is ignored.
00092       G4double* GetBFieldAt (const G4double* x, 
00093                                            G4double t = 0) const;
00094 
00095       //        Returns a null vector (pure magnetric field).
00096       Vector3D GetEFieldAt (const Point3D& x, G4double t = 0) const;
00097 
00098       //        Return the force due to the magnetic field on a particle
00099       //        of charge q, with position x and velocity v. The time
00100       //        variable t is ignored (static magnetic field).
00101 
00102         virtual Vector3D GetForceAt (const Point3D& x, 
00103                     const Vector3D& v, G4double q, G4double t = 0) const;
00104 
00105   //            Rotates this field 180 degrees about the local vertical
00106   //            axis.
00107         void RotateY180 ();
00108 
00109       //        Prints an ascii representation (table) of the field to
00110       //        os.
00111       void PrintField (std::ostream& os) const;
00112 
00113       //        Add the specified component to the field. The field
00114       //        components bn and an are in Tesla , and are normalised
00115       //        to the radius r (default = 1 meter).
00116       void SetComponent (int np, G4double bn, G4double an = 0, G4double r0 = 1);
00117 
00118       //        Returns the field (in Tesla) at the radius r0 due to the
00119       //        np-th multipole component
00120       Complex GetComponent (int np, G4double r0 = 1.0) const;
00121 
00122       //        Returns the unitless complex coefficient for the np-th
00123       //        term (bn+i*an).The coefficient is relative to the
00124       //        specified pole radius r0 (default = 1meter).
00125       Complex GetCoefficient (int np, G4double r0 = 1.0) const;
00126 
00127       //        Sets the unitless complex coefficient for the np-th term
00128       //        (bn+i*an).The coefficient is relative to the specified
00129       //        pole radius r0 (default = 1meter).
00130       void SetCoefficient (int np, const Complex& b, G4double r0 = 1.0);
00131 
00132       int HighestMultipole () const;
00133 
00134   protected:
00135   private:
00136     // Data Members for Class Attributes
00137 
00138       //        The scale of the field in Tesla. The coefficients of the
00139       //        expansion terms are normalised so that they have no
00140       //        field unit.
00141       G4double B0;
00142       TermExpansion expansion;
00143 
00144   private:  
00145 };
00146 
00147 // Class myMultipoleField 
00148 
00149 inline myMultipoleField::myMultipoleField (G4double scale, size_t nt)
00150   : B0(scale),expansion(nt,Complex(0,0)){}
00151 
00152 inline bool myMultipoleField::IsNullField () const
00153 {
00154         return B0==0;
00155 }
00156 
00157 inline int myMultipoleField::HighestMultipole () const
00158 {
00159         return expansion.size()-1;
00160 }
00161 
00162 
00163 #endif
00164 

Generated on Wed Mar 5 17:25:22 2008 for BDSIM by  doxygen 1.5.3