52 double lenUnit=
meter;
53 double fieldUnit=
tesla;
54 G4cout <<
"\n-----------------------------------------------------------"
55 <<
"\n Magnetic field"
56 <<
"\n-----------------------------------------------------------";
58 G4cout <<
"\n ---> " "Reading the field grid from " << filename <<
" ... " <<
G4endl;
63 G4AutoLock lock(&myPurgMagTabulatedField3DLock);
65 ifstream
file( filename );
70 ed <<
"Could not open input file " << filename << std::endl;
71 G4Exception(
"PurgMagTabulatedField3D::PurgMagTabulatedField3D",
77 file.getline(buffer,256);
82 G4cout <<
" [ Number of values x,y,z: "
83 <<
nx <<
" " <<
ny <<
" " << nz <<
" ] "
91 for (ix=0; ix<
nx; ix++) {
95 for (iy=0; iy<
ny; iy++) {
106 file.getline(buffer,256);
107 }
while ( buffer[1]!=
'0');
110 double xval,yval,zval,bx,by,bz;
112 for (ix=0; ix<
nx; ix++) {
113 for (iy=0; iy<
ny; iy++) {
114 for (iz=0; iz<
nz; iz++) {
115 file >> xval >> yval >> zval >> bx >> by >> bz >> permeability;
116 if ( ix==0 && iy==0 && iz==0 ) {
117 minx = xval * lenUnit;
118 miny = yval * lenUnit;
119 minz = zval * lenUnit;
121 xField[ix][iy][iz] = bx * fieldUnit;
122 yField[ix][iy][iz] = by * fieldUnit;
123 zField[ix][iy][iz] = bz * fieldUnit;
131 maxx = xval * lenUnit;
132 maxy = yval * lenUnit;
133 maxz = zval * lenUnit;
138 G4cout <<
" ---> assumed the order: x, y, z, Bx, By, Bz "
139 <<
"\n ---> Min values x,y,z: "
141 <<
"\n ---> Max values x,y,z: "
143 <<
"\n ---> The field will be offset by " << zOffset/
cm <<
" cm " <<
G4endl;
149 G4cout <<
"\nAfter reordering if neccesary"
150 <<
"\n ---> Min values x,y,z: "
152 <<
" \n ---> Max values x,y,z: "
158 G4cout <<
"\n ---> Dif values x,y,z (range): "
160 <<
"\n-----------------------------------------------------------" <<
G4endl;
164 double *Bfield )
const
178 double xfraction = (x -
minx) /
dx;
179 double yfraction = (y -
miny) /
dy;
180 double zfraction = (z -
minz) /
dz;
182 if (
invertX) { xfraction = 1 - xfraction;}
183 if (
invertY) { yfraction = 1 - yfraction;}
184 if (
invertZ) { zfraction = 1 - zfraction;}
188 double xdindex, ydindex, zdindex;
192 double xlocal = ( std::modf(xfraction*(
nx-1), &xdindex));
193 double ylocal = ( std::modf(yfraction*(
ny-1), &ydindex));
194 double zlocal = ( std::modf(zfraction*(
nz-1), &zdindex));
198 int xindex =
static_cast<int>(xdindex);
199 int yindex =
static_cast<int>(ydindex);
200 int zindex =
static_cast<int>(zdindex);
203 #ifdef DEBUG_INTERPOLATING_FIELD
204 G4cout <<
"Local x,y,z: " << xlocal <<
" " << ylocal <<
" " << zlocal <<
G4endl;
205 G4cout <<
"Index x,y,z: " << xindex <<
" " << yindex <<
" " << zindex <<
G4endl;
206 double valx0z0, mulx0z0, valx1z0, mulx1z0;
207 double valx0z1, mulx0z1, valx1z1, mulx1z1;
208 valx0z0= table[xindex ][0][zindex]; mulx0z0= (1-xlocal) * (1-zlocal);
209 valx1z0= table[xindex+1][0][zindex]; mulx1z0= xlocal * (1-zlocal);
210 valx0z1= table[xindex ][0][zindex+1]; mulx0z1= (1-xlocal) * zlocal;
211 valx1z1= table[xindex+1][0][zindex+1]; mulx1z1= xlocal * zlocal;
216 xField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
217 xField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
218 xField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
219 xField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
220 xField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
221 xField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
222 xField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
223 xField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal ;
225 yField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
226 yField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
227 yField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
228 yField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
229 yField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
230 yField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
231 yField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
232 yField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal ;
234 zField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
235 zField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
236 zField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
237 zField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
238 zField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
239 zField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
240 zField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
241 zField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal ;