00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "gismo/Field.h"
00011
00012 #include "geometry/Ray.h"
00013 #include "geometry/Helix.h"
00014 #include "gismo/Units.h"
00015
00016 #include "facilities/error.h"
00017 #include <float.h>
00018 #include <string.h>
00019
00020 Field::Field_list Field::theFields;
00021
00022
00023 Field::Field(double bx, double by, double bz)
00024 : constB(bx,by,bz)
00025 {
00026 checkAppend();
00027 }
00028
00029 Field::Field():constB(0,0,0),id(0){}
00030
00031 void Field::checkAppend()
00032 {
00033
00034
00035 for(id = 0; id<theFields.size(); id++)
00036 if(theFields[id]->constB == constB)
00037 break;
00038
00039 if( id == theFields.size() )
00040 theFields.push_back(this);
00041
00042 }
00043
00044 Ray*
00045 Field::CreateRay(const Point& r, const Vector& p, float q, float)const
00046 {
00047 Vector bField = valueAt(r);
00048 float bMag = bField.magnitude();
00049 float pmag = p.magnitude();
00050 if (pmag == 0.) return 0;
00051 Vector t= p.unit() ;
00052
00053
00054
00055
00056 if (q == 0 || bMag < 0.001 )
00057 return new Ray(r, t);
00058
00059
00060
00061 Vector bHat = bField.unit();
00062
00063 float pPerp = pmag * (bHat.cross(t)).mag();
00064 float rho = pPerp/ ( Units::ec() * q * bMag );
00065 if(fabs(rho) < 1000.* FLT_EPSILON ) return new Ray(r, t);
00066 else return new Helix(r, t, bHat, rho);
00067
00068 }
00069
00070 void Field::printOn( std::ostream& os ) const
00071 {
00072
00073 os << "Magnetic Field Base Class: constant field = " << constB << "\n";
00074 }
00075