BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldMagOctupole.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSDebug.hh"
19#include "BDSFieldMagOctupole.hh"
20#include "BDSMagnetStrength.hh"
21#include "BDSUtilities.hh"
22
23#include "G4ThreeVector.hh"
24
25#include "CLHEP/Units/SystemOfUnits.h"
26
27#include <cmath>
28
30 G4double const brho)
31{
32 // B''' = d^3By/dx^3 = Brho * (1/Brho d^3By/dx^3) = Brho * k3
33 bTriplePrime = brho * (*strength)["k3"] / (CLHEP::m3*CLHEP::m);
36#ifdef BDSDEBUG
37 G4cout << __METHOD_NAME__ << "B''' = " << bTriplePrime << G4endl;
38#endif
39}
40
41G4ThreeVector BDSFieldMagOctupole::GetField(const G4ThreeVector &position,
42 const G4double /*t*/) const
43{
44 // B_x = (3x^2y - y^3) * (B'''/3!)
45 // B_y = (x^3-3xy^2) * (B'''/3!)
46 // B_z = 0
47
48 //shortcuts
49 G4double x = position.x();
50 G4double y = position.y();
51
52 G4ThreeVector localField;
53 localField[0] = (3 * std::pow(x,2) * y - std::pow(y,3)) * bTPNormed;
54 localField[1] = (std::pow(x,3) - 3* x * std::pow(y,2)) * bTPNormed;
55 localField[2] = 0;
56
57 return localField;
58}
BDSFieldMagOctupole()
Private default constructor to force use of supplied constructor.
G4double bTPNormed
bTriplePrime / 3! cached for simplicity
G4double bTriplePrime
3rd derivative of the magnetic field
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Access the field value.
G4bool finiteStrength
Flag to cache whether finite nor not.
Efficient storage of magnet strengths.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())