36 :feXoffset(exOffset),feYoffset(eyOffset),feZoffset(ezOffset),einvertX(false),einvertY(false),einvertZ(false)
42 G4cout <<
"\n-----------------------------------------------------------"
43 <<
"\n Electric field"
44 <<
"\n-----------------------------------------------------------";
46 G4cout <<
"\n ---> " "Reading the field grid from " << filename <<
" ... " << endl;
49 ifstream file( filename );
53 file.getline(ebuffer,256);
56 file >> Enx >> Eny >> Enz;
58 G4cout <<
" [ Number of values x,y,z: "
59 << Enx <<
" " << Eny <<
" " << Enz <<
" ] "
63 xEField.resize( Enx );
64 yEField.resize( Enx );
65 zEField.resize( Enx );
67 for (ix=0; ix<Enx; ix++) {
68 xEField[ix].resize(Eny);
69 yEField[ix].resize(Eny);
70 zEField[ix].resize(Eny);
71 for (iy=0; iy<Eny; iy++) {
72 xEField[ix][iy].resize(Enz);
73 yEField[ix][iy].resize(Enz);
74 zEField[ix][iy].resize(Enz);
85 for (iz=0; iz<Enz; iz++) {
86 for (iy=0; iy<Eny; iy++) {
87 for (ix=0; ix<Enx; ix++) {
88 file >> Exval >> Eyval >> Ezval >> Ex >> Ey >> Ez;
90 if ( ix==0 && iy==0 && iz==0 ) {
91 Eminx = Exval * ElenUnit;
92 Eminy = Eyval * ElenUnit;
93 Eminz = Ezval * ElenUnit;
95 xEField[ix][iy][iz] = Ex * EfieldUnit;
96 yEField[ix][iy][iz] = Ey * EfieldUnit;
97 zEField[ix][iy][iz] = Ez * EfieldUnit;
104 Emaxx = Exval * ElenUnit;
105 Emaxy = Eyval * ElenUnit;
106 Emaxz = Ezval * ElenUnit;
108 G4cout <<
"\n ---> ... done reading " << endl;
111 G4cout <<
" ---> assumed the order: x, y, z, Ex, Ey, Ez "
112 <<
"\n ---> Min values x,y,z: "
113 << Eminx/
cm <<
" " << Eminy/
cm <<
" " << Eminz/
cm <<
" cm "
114 <<
"\n ---> Max values x,y,z: "
115 << Emaxx/
cm <<
" " << Emaxy/
cm <<
" " << Emaxz/
cm <<
" cm "
116 <<
"\n ---> The field will be offset in x by " << exOffset/
cm <<
" cm "
117 <<
"\n ---> The field will be offset in y by " << eyOffset/
cm <<
" cm "
118 <<
"\n ---> The field will be offset in z by " << ezOffset/
cm <<
" cm " << endl;
121 if (Emaxx < Eminx) {swap(Emaxx,Eminx); einvertX =
true;}
122 if (Emaxy < Eminy) {swap(Emaxy,Eminy); einvertY =
true;}
123 if (Emaxz < Eminz) {swap(Emaxz,Eminz); einvertZ =
true;}
124 G4cout <<
"\nAfter reordering if neccesary"
125 <<
"\n ---> Min values x,y,z: "
126 << Eminx/
cm <<
" " << Eminy/
cm <<
" " << Eminz/
cm <<
" cm "
127 <<
" \n ---> Max values x,y,z: "
128 << Emaxx/
cm <<
" " << Emaxy/
cm <<
" " << Emaxz/
cm <<
" cm ";
133 G4cout <<
"\n ---> Dif values x,y,z (range): "
134 << dx1/
cm <<
" " << dy1/
cm <<
" " << dz1/
cm <<
" cm "
135 <<
"\n-----------------------------------------------------------" << endl;
141 G4double x1 = Epoint[0] + feXoffset;
142 G4double y1 = Epoint[1] + feYoffset;
143 G4double z1 = Epoint[2] + feZoffset;
147 G4double Exfraction = (x1 - Eminx) / dx1;
148 G4double Eyfraction = (y1 - Eminy) / dy1;
149 G4double Ezfraction = (z1 - Eminz) / dz1;
151 if (einvertX) { Exfraction = 1 - Exfraction;}
152 if (einvertY) { Eyfraction = 1 - Eyfraction;}
153 if (einvertZ) { Ezfraction = 1 - Ezfraction;}
157 G4double exdindex, eydindex, ezdindex;
161 G4double exlocal = ( std::modf(Exfraction*(Enx-1), &exdindex));
162 G4double eylocal = ( std::modf(Eyfraction*(Eny-1), &eydindex));
163 G4double ezlocal = ( std::modf(Ezfraction*(Enz-1), &ezdindex));
167 G4int exindex =
static_cast<G4int>(std::floor(exdindex));
168 G4int eyindex =
static_cast<G4int>(std::floor(eydindex));
169 G4int ezindex =
static_cast<G4int>(std::floor(ezdindex));
171 if ((exindex < 0) || (exindex >= Enx - 1) ||
172 (eyindex < 0) || (eyindex >= Eny - 1) ||
173 (ezindex < 0) || (ezindex >= Enz - 1))
204 xEField[exindex ][eyindex ][ezindex ] * (1-exlocal) * (1-eylocal) * (1-ezlocal) +
205 xEField[exindex ][eyindex ][ezindex+1] * (1-exlocal) * (1-eylocal) * ezlocal +
206 xEField[exindex ][eyindex+1][ezindex ] * (1-exlocal) * eylocal * (1-ezlocal) +
207 xEField[exindex ][eyindex+1][ezindex+1] * (1-exlocal) * eylocal * ezlocal +
208 xEField[exindex+1][eyindex ][ezindex ] * exlocal * (1-eylocal) * (1-ezlocal) +
209 xEField[exindex+1][eyindex ][ezindex+1] * exlocal * (1-eylocal) * ezlocal +
210 xEField[exindex+1][eyindex+1][ezindex ] * exlocal * eylocal * (1-ezlocal) +
211 xEField[exindex+1][eyindex+1][ezindex+1] * exlocal * eylocal * ezlocal ;
213 yEField[exindex ][eyindex ][ezindex ] * (1-exlocal) * (1-eylocal) * (1-ezlocal) +
214 yEField[exindex ][eyindex ][ezindex+1] * (1-exlocal) * (1-eylocal) * ezlocal +
215 yEField[exindex ][eyindex+1][ezindex ] * (1-exlocal) * eylocal * (1-ezlocal) +
216 yEField[exindex ][eyindex+1][ezindex+1] * (1-exlocal) * eylocal * ezlocal +
217 yEField[exindex+1][eyindex ][ezindex ] * exlocal * (1-eylocal) * (1-ezlocal) +
218 yEField[exindex+1][eyindex ][ezindex+1] * exlocal * (1-eylocal) * ezlocal +
219 yEField[exindex+1][eyindex+1][ezindex ] * exlocal * eylocal * (1-ezlocal) +
220 yEField[exindex+1][eyindex+1][ezindex+1] * exlocal * eylocal * ezlocal ;
222 zEField[exindex ][eyindex ][ezindex ] * (1-exlocal) * (1-eylocal) * (1-ezlocal) +
223 zEField[exindex ][eyindex ][ezindex+1] * (1-exlocal) * (1-eylocal) * ezlocal +
224 zEField[exindex ][eyindex+1][ezindex ] * (1-exlocal) * eylocal * (1-ezlocal) +
225 zEField[exindex ][eyindex+1][ezindex+1] * (1-exlocal) * eylocal * ezlocal +
226 zEField[exindex+1][eyindex ][ezindex ] * exlocal * (1-eylocal) * (1-ezlocal) +
227 zEField[exindex+1][eyindex ][ezindex+1] * exlocal * (1-eylocal) * ezlocal +
228 zEField[exindex+1][eyindex+1][ezindex ] * exlocal * eylocal * (1-ezlocal) +
229 zEField[exindex+1][eyindex+1][ezindex+1] * exlocal * eylocal * ezlocal ;
#define G4MUTEX_INITIALIZER
G4GLOB_DLL std::ostream G4cout
static constexpr double m
void GetFieldValue(const G4double Epoint[4], G4double *Efield) const
static constexpr double cm
HadrontherapyElectricTabulatedField3D(const char *filename, G4double exOffset, G4double eyOffset, G4double ezOffset)
static constexpr double volt