13 #include "G4TransportationManager.hh"
14 #include "G4UImanager.hh"
15 #include "G4FieldManager.hh"
17 #include "G4PropagatorInField.hh"
18 #include "G4Mag_UsualEqRhs.hh"
19 #include "G4ClassicalRK4.hh"
24 : fFieldMessenger(
this,
"/eAST/field/",
"Field properties")
27 .SetStates(G4State_PreInit)
28 .SetToBeBroadcasted(
false);
30 .SetStates(G4State_PreInit, G4State_Init, G4State_Idle)
31 .SetToBeBroadcasted(
false);
37 auto transportationmanager = G4TransportationManager::GetTransportationManager();
49 fChordFinder->GetIntegrationDriver()->SetVerboseLevel(0);
59 fMaps.emplace_back(name);
63 : fName(name),fFieldMapMessenger(
this,
"/eAST/field/" + fName +
"/",
"Field map properties")
66 .SetStates(G4State_PreInit)
67 .SetToBeBroadcasted(
false);
69 .SetStates(G4State_PreInit)
70 .SetToBeBroadcasted(
false);
72 .SetStates(G4State_PreInit)
73 .SetToBeBroadcasted(
false);
75 .SetStates(G4State_PreInit)
76 .SetToBeBroadcasted(
false);
78 .SetStates(G4State_PreInit)
79 .SetToBeBroadcasted(
false);
81 .SetStates(G4State_PreInit, G4State_Init, G4State_Idle)
82 .SetToBeBroadcasted(
false);
88 if (!
fMap.empty())
return false;
92 G4cout <<
"Locate Magnet map: Searching for " << filename << G4endl;
93 auto UImanager = G4UImanager::GetUIpointer();
94 auto fullfile = UImanager->FindMacroPath(filename);
95 G4cout <<
"Locate Magnet map: Using" << fullfile << G4endl;
99 if (!inputfile.good()) {
100 G4cout <<
"WARNING: Couldn't open " << fullfile << G4endl;
105 for (
unsigned int i = 0; i < 2; i++) {
110 G4cerr <<
"ERROR: unable to read grid." << G4endl;
117 G4cout <<
"Assuming axially symmetric 2D grid." << G4endl;
121 G4cout <<
"Assuming R,Z,Phi grid." << G4endl;
138 unsigned int counter = 0;
139 while (inputfile.good()) {
140 double polar[3] = {0.0, 0.0, 0.0};
141 double field[3] = {0.0, 0.0, 0.0};
145 polar[0] >> polar[1] >> polar[2] >>
146 field[0] >> field[1] >> field[2])) {
147 if (inputfile.eof())
continue;
148 G4cerr <<
"ERROR: unable to read grid, no 6 columns." << G4endl;
154 polar[0] >> polar[1] >>
155 field[0] >> field[1])) {
156 if (inputfile.eof())
continue;
157 G4cerr <<
"ERROR: unable to read grid, no 4 columns." << G4endl;
162 G4cout <<
"ERROR: set field map extent first" << G4endl;
168 unsigned int index[3] = {0, 0, 0};
172 for (
unsigned int i = 0; i < 3; i++) {
180 G4cout <<
"ERROR: expected " << fGridSize[0] * fGridSize[1] * fGridSize[2] <<
" entries "
181 <<
"but read " << counter << G4endl;
196 sqrt(point[0]*point[0] + point[1]*point[1]),
198 atan2(point[1], point[0])
202 if (polar[0] < std::get<0>(
fGridExtent[0])*fGridUnit[0]
203 || polar[0] > std::get<1>(
fGridExtent[0])*fGridUnit[0])
return;
206 unsigned int index[3] = {0, 0, 0};
207 double local[3] = {0.0, 0.0, 0.0};
209 index[i] = (int) floor ((polar[i]/fGridUnit[i] - std::get<0>(
fGridExtent[i])) / std::get<2>(
fGridExtent[i]));
215 if (interpolation ==
kCubic) {
229 switch (interpolation) {
239 thread_local G4double
values[3][64];
240 for (
unsigned int i = 0; i <
n; i++) {
241 for (
unsigned int j = 0; j < 3; j++) {
244 fMap[j][index[0] + map[i][0]][index[1] + map[i][1]][index[2] + map[i][2]] :
245 fMap[j][index[0] + map[i][0]][index[1] + map[i][1]][0]
251 double cylindrical[3] = {0.0, 0.0, 0.0};
252 for (
unsigned int j = 0; j < 3; j++) {
260 cartesian[0] = (cylindrical[0] * point[0] - cylindrical[2] * point[1]) / polar[0];
261 cartesian[1] = (cylindrical[2] * point[0] + cylindrical[0] * point[1]) / polar[0];
263 cartesian[0] = cylindrical[0] *
cos(polar[2]) - cylindrical[2] * sin(polar[2]);
264 cartesian[1] = cylindrical[2] *
cos(polar[2]) + cylindrical[0] * sin(polar[2]);
266 cartesian[2] = cylindrical[1];
271 G4double B[3] = {0,0,0};
272 G4double
p[4] = {point.x(), point.y(), point.z(), 0.0};
274 G4cout <<
"B" << point/
CLHEP::m <<
" [m] = ";
275 for (
unsigned int i = 0; i < 3; i++)
276 G4cout << B[i]/CLHEP::tesla <<
" ";
277 G4cout <<
"[T]" << G4endl;