BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSFieldEMRFCavity.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSCavityInfo.hh"
20#include "BDSFieldEMRFCavity.hh"
21#include "BDSMagnetStrength.hh"
22#include "BDSUtilities.hh"
23
24#include "CLHEP/Units/PhysicalConstants.h"
25#include "globals.hh"
26#include "G4ThreeVector.hh"
27
28#include "TMath.h"
29
30#include <cmath>
31#include <utility>
32
33const G4double BDSFieldEMRFCavity::j0FirstZero = 2.404825557695772768622;
34
35const G4double BDSFieldEMRFCavity::Z0 = CLHEP::mu0 * CLHEP::c_light;
36
38 G4double brho):
39 BDSFieldEMRFCavity((*strength)["efield"],
40 (*strength)["frequency"],
41 (*strength)["phase"],
42 (*strength)["equatorradius"])
43{
44 eFieldMax *= BDS::Sign(brho);
45}
46
47BDSFieldEMRFCavity::BDSFieldEMRFCavity(G4double eFieldAmplitude,
48 G4double frequencyIn,
49 G4double phaseOffset,
50 G4double cavityRadiusIn):
51 eFieldMax(eFieldAmplitude),
52 frequency(frequencyIn),
53 phase(phaseOffset),
54 cavityRadius(cavityRadiusIn),
55 normalisedCavityRadius(j0FirstZero/cavityRadius),
56 angularFrequency(CLHEP::twopi * frequencyIn)
57{;}
58
59std::pair<G4ThreeVector, G4ThreeVector> BDSFieldEMRFCavity::GetField(const G4ThreeVector& position,
60 const G4double t) const
61{
62 // Converting from Local Cartesian to Local Cylindrical
63 G4double phi = std::atan2(position.y(),position.x());
64 G4double r = std::hypot(position.x(),position.y());
65
66 G4double rNormalised = normalisedCavityRadius * r;
67
68 // In case a point outside the cavity is queried, ensure the bessel will return 0
69 if (rNormalised > j0FirstZero)
70 {rNormalised = j0FirstZero - 1e-6;}
71
72 // Source for calculating the TM010 mode: Gerigk, Frank.
73 // "Cavity types." arXiv preprint arXiv:1111.4897 (2011).
74
75 G4double J0r = TMath::BesselJ0(rNormalised);
76 G4double J1r = TMath::BesselJ1(rNormalised);
77
78 // Calculating free-space impedance and scale factor for Bphi:
79 G4double hMax = -eFieldMax/Z0;
80 G4double Bmax = hMax * CLHEP::mu0;
81
82 // Calculating field components. Frequency in rad/s or /s?
83 G4double Ez = eFieldMax * J0r * std::cos(angularFrequency*t + phase);
84 G4double Bphi = Bmax * J1r * std::sin(angularFrequency*t + phase);
85
86 // Converting Bphi into cartesian coordinates:
87 G4double Bx = Bphi*std::sin(phi);
88 G4double By = Bphi*std::cos(phi);
89
90 // Local B and E fields:
91 G4ThreeVector LocalB = G4ThreeVector(Bx, By, 0);
92 G4ThreeVector LocalE = G4ThreeVector(0, 0, Ez);
93
94 auto result = std::make_pair(LocalB, LocalE);
95 return result;
96}
Pill box cavity electro-magnetic field.
virtual std::pair< G4ThreeVector, G4ThreeVector > GetField(const G4ThreeVector &position, const G4double t) const
Accessor to get B and E field.
const G4double angularFrequency
Angular frequency calculated from frequency - cached to avoid repeated calculation.
G4double phase
Phase offset of the oscillator.
BDSFieldEMRFCavity()
Private constructor to force use of provided one.
static const G4double j0FirstZero
X coordinate of first 0 point for bessel J0.
static const G4double Z0
Impedance of free space.
G4double eFieldMax
Maximum field in V/m.
const G4double normalisedCavityRadius
Pre-calculated normalised calculated radius w.r.t. bessel first 0.
Efficient storage of magnet strengths.