Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Field.cxx

Go to the documentation of this file.
00001 // $Id: Field.cxx,v 1.1.1.1 1999/12/20 22:28:41 burnett Exp $
00002 //
00003 // This file is part of Gismo 2
00004 //
00005 //
00006 //    Implementation of class Field member functions
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;     // a list of unique fields
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     // check to see if it already exists
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     // --- Neutral Particle or no field: straight line Ray
00055 
00056   if (q == 0 || bMag < 0.001 )
00057     return new Ray(r, t);
00058 
00059   // --- otherwise the Helix
00060 
00061   Vector    bHat = bField.unit();  // unit vector in direction of field
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  //  printing function, uses C++ ostream class object
00073         os << "Magnetic Field Base Class: constant field = " << constB << "\n";
00074 }
00075 

Generated at Mon Nov 26 18:18:32 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000