musrTabulatedField3D Class Reference

#include <musrTabulatedField3D.hh>

List of all members.

Public Member Functions

 musrTabulatedField3D (const char *filename, double fieldValue)
void GetFieldValue (const double Point[4], double *Bfield) const
G4double GetFieldSetValue ()


Detailed Description

Definition at line 11 of file musrTabulatedField3D.hh.


Constructor & Destructor Documentation

musrTabulatedField3D::musrTabulatedField3D const char *  filename,
double  fieldValue
 

Definition at line 3 of file musrTabulatedField3D.cc.

00004   :ffieldValue(fieldValue),invertX(false),invertY(false),invertZ(false)
00005 {    
00006  
00007   double lenUnit= meter;
00008   //  double fieldUnit= tesla; 
00009   G4cout << "\n-----------------------------------------------------------"
00010          << "\n      Magnetic field"
00011          << "\n-----------------------------------------------------------"
00012          << endl;
00013   G4cout << " Field set to "<< fieldValue*1000 << " T"<< endl;  
00014   G4cout << "\n ---> " "Reading the field grid from " << filename << " ... " << endl; 
00015   ifstream file( filename ); // Open the file for reading.
00016   
00017   // Ignore first blank line
00018   char buffer[256];
00019   file.getline(buffer,256);
00020   
00021   // Read table dimensions 
00022   file >> nx >> ny >> nz; // Note dodgy order
00023 
00024   G4cout << "  [ Number of values x,y,z: " 
00025          << nx << " " << ny << " " << nz << " ] "
00026          << endl;
00027 
00028   // Set up storage space for table
00029   xField.resize( nx );
00030   yField.resize( nx );
00031   zField.resize( nx );
00032   int ix, iy, iz;
00033   for (ix=0; ix<nx; ix++) {
00034     xField[ix].resize(ny);
00035     yField[ix].resize(ny);
00036     zField[ix].resize(ny);
00037     for (iy=0; iy<ny; iy++) {
00038       xField[ix][iy].resize(nz);
00039       yField[ix][iy].resize(nz);
00040       zField[ix][iy].resize(nz);
00041     }
00042   }
00043   
00044   // Ignore other header information    
00045   // The first line whose second character is '0' is considered to
00046   // be the last line of the header.
00047   do {
00048     file.getline(buffer,256);
00049   } while ( buffer[1]!='0');
00050   
00051   // Read in the data
00052   double xval,yval,zval,bx,by,bz;
00053   double permeability; // Not used in this example.
00054   for (ix=0; ix<nx; ix++) {
00055     for (iy=0; iy<ny; iy++) {
00056       for (iz=0; iz<nz; iz++) {
00057         file >> xval >> yval >> zval >> bx >> by >> bz >> permeability;
00058         if ( ix==0 && iy==0 && iz==0 ) {
00059           minx = xval * lenUnit;
00060           miny = yval * lenUnit;
00061           minz = zval * lenUnit;
00062         }
00063         //xField[ix][iy][iz] = bx * fieldUnit * fieldValue;
00064         //yField[ix][iy][iz] = by * fieldUnit * fieldValue;
00065         //zField[ix][iy][iz] = bz * fieldUnit * fieldValue;
00066         xField[ix][iy][iz] = bx * fieldValue;
00067         yField[ix][iy][iz] = by * fieldValue;
00068         zField[ix][iy][iz] = bz * fieldValue;
00069       }
00070     }
00071   }
00072   file.close();
00073 
00074   maxx = xval * lenUnit;
00075   maxy = yval * lenUnit;
00076   maxz = zval * lenUnit;
00077 
00078   G4cout << "\n ---> ... done reading " << endl;
00079 
00080   // G4cout << " Read values of field from file " << filename << endl; 
00081   G4cout << " ---> assumed the order:  x, y, z, Bx, By, Bz "
00082          << "\n ---> Min values x,y,z: " 
00083          << minx/cm << " " << miny/cm << " " << minz/cm << " cm "
00084          << "\n ---> Max values x,y,z: " 
00085          << maxx/cm << " " << maxy/cm << " " << maxz/cm << " cm " << endl;
00086 
00087 
00088   // Should really check that the limits are not the wrong way around.
00089   if (maxx < minx) {swap(maxx,minx); invertX = true;} 
00090   if (maxy < miny) {swap(maxy,miny); invertY = true;} 
00091   if (maxz < minz) {swap(maxz,minz); invertZ = true;} 
00092   G4cout << "\nAfter reordering if neccesary"  
00093          << "\n ---> Min values x,y,z: " 
00094          << minx/cm << " " << miny/cm << " " << minz/cm << " cm "
00095          << " \n ---> Max values x,y,z: " 
00096          << maxx/cm << " " << maxy/cm << " " << maxz/cm << " cm ";
00097 
00098   dx = maxx - minx;
00099   dy = maxy - miny;
00100   dz = maxz - minz;
00101   G4cout << "\n ---> Dif values x,y,z (range): " 
00102          << dx/cm << " " << dy/cm << " " << dz/cm << " cm in z "
00103          << "\n-----------------------------------------------------------" << endl;
00104 }


Member Function Documentation

G4double musrTabulatedField3D::GetFieldSetValue  ) 
 

Definition at line 194 of file musrTabulatedField3D.cc.

00195 {
00196   return ffieldValue;
00197 }

void musrTabulatedField3D::GetFieldValue const double  Point[4],
double *  Bfield
const
 

Definition at line 106 of file musrTabulatedField3D.cc.

00108 {
00109 
00110   double x = point[0];
00111   double y = point[1];
00112   double z = point[2];
00113 
00114 
00115   // Check that the point is within the defined region 
00116   if ( x>=minx && x<=maxx &&
00117        y>=miny && y<=maxy && 
00118        z>=minz && z<=maxz ) {
00119     
00120     // Position of given point within region, normalized to the range
00121     // [0,1]
00122     double xfraction = (x - minx) / dx;
00123     double yfraction = (y - miny) / dy; 
00124     double zfraction = (z - minz) / dz;
00125 
00126     if (invertX) { xfraction = 1 - xfraction;}
00127     if (invertY) { yfraction = 1 - yfraction;}
00128     if (invertZ) { zfraction = 1 - zfraction;}
00129 
00130     // Need addresses of these to pass to modf below.
00131     // modf uses its second argument as an OUTPUT argument.
00132     double xdindex, ydindex, zdindex;
00133     
00134     // Position of the point within the cuboid defined by the
00135     // nearest surrounding tabulated points
00136     double xlocal = ( modf(xfraction*(nx-1), &xdindex));
00137     double ylocal = ( modf(yfraction*(ny-1), &ydindex));
00138     double zlocal = ( modf(zfraction*(nz-1), &zdindex));
00139     
00140     // The indices of the nearest tabulated point whose coordinates
00141     // are all less than those of the given point
00142     int xindex = static_cast<int>(xdindex);
00143     int yindex = static_cast<int>(ydindex);
00144     int zindex = static_cast<int>(zdindex);
00145     
00146 
00147 #ifdef DEBUG_INTERPOLATING_FIELD
00148     G4cout << "Local x,y,z: " << xlocal << " " << ylocal << " " << zlocal << endl;
00149     G4cout << "Index x,y,z: " << xindex << " " << yindex << " " << zindex << endl;
00150     double valx0z0, mulx0z0, valx1z0, mulx1z0;
00151     double valx0z1, mulx0z1, valx1z1, mulx1z1;
00152     valx0z0= table[xindex  ][0][zindex];  mulx0z0=  (1-xlocal) * (1-zlocal);
00153     valx1z0= table[xindex+1][0][zindex];  mulx1z0=   xlocal    * (1-zlocal);
00154     valx0z1= table[xindex  ][0][zindex+1]; mulx0z1= (1-xlocal) * zlocal;
00155     valx1z1= table[xindex+1][0][zindex+1]; mulx1z1=  xlocal    * zlocal;
00156 #endif
00157 
00158         // Full 3-dimensional version
00159     Bfield[0] =
00160       xField[xindex  ][yindex  ][zindex  ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
00161       xField[xindex  ][yindex  ][zindex+1] * (1-xlocal) * (1-ylocal) *    zlocal  +
00162       xField[xindex  ][yindex+1][zindex  ] * (1-xlocal) *    ylocal  * (1-zlocal) +
00163       xField[xindex  ][yindex+1][zindex+1] * (1-xlocal) *    ylocal  *    zlocal  +
00164       xField[xindex+1][yindex  ][zindex  ] *    xlocal  * (1-ylocal) * (1-zlocal) +
00165       xField[xindex+1][yindex  ][zindex+1] *    xlocal  * (1-ylocal) *    zlocal  +
00166       xField[xindex+1][yindex+1][zindex  ] *    xlocal  *    ylocal  * (1-zlocal) +
00167       xField[xindex+1][yindex+1][zindex+1] *    xlocal  *    ylocal  *    zlocal ;
00168     Bfield[1] =
00169       yField[xindex  ][yindex  ][zindex  ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
00170       yField[xindex  ][yindex  ][zindex+1] * (1-xlocal) * (1-ylocal) *    zlocal  +
00171       yField[xindex  ][yindex+1][zindex  ] * (1-xlocal) *    ylocal  * (1-zlocal) +
00172       yField[xindex  ][yindex+1][zindex+1] * (1-xlocal) *    ylocal  *    zlocal  +
00173       yField[xindex+1][yindex  ][zindex  ] *    xlocal  * (1-ylocal) * (1-zlocal) +
00174       yField[xindex+1][yindex  ][zindex+1] *    xlocal  * (1-ylocal) *    zlocal  +
00175       yField[xindex+1][yindex+1][zindex  ] *    xlocal  *    ylocal  * (1-zlocal) +
00176       yField[xindex+1][yindex+1][zindex+1] *    xlocal  *    ylocal  *    zlocal ;
00177     Bfield[2] =
00178       zField[xindex  ][yindex  ][zindex  ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
00179       zField[xindex  ][yindex  ][zindex+1] * (1-xlocal) * (1-ylocal) *    zlocal  +
00180       zField[xindex  ][yindex+1][zindex  ] * (1-xlocal) *    ylocal  * (1-zlocal) +
00181       zField[xindex  ][yindex+1][zindex+1] * (1-xlocal) *    ylocal  *    zlocal  +
00182       zField[xindex+1][yindex  ][zindex  ] *    xlocal  * (1-ylocal) * (1-zlocal) +
00183       zField[xindex+1][yindex  ][zindex+1] *    xlocal  * (1-ylocal) *    zlocal  +
00184       zField[xindex+1][yindex+1][zindex  ] *    xlocal  *    ylocal  * (1-zlocal) +
00185       zField[xindex+1][yindex+1][zindex+1] *    xlocal  *    ylocal  *    zlocal ;
00186 
00187   } else {
00188     Bfield[0] = 0.0;
00189     Bfield[1] = 0.0;
00190     Bfield[2] = 0.0;
00191   }
00192 }


The documentation for this class was generated from the following files:
Generated on Mon Mar 27 12:19:54 2006 for MUSR by  doxygen 1.4.6