BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSIntegratorOctupole.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 "BDSIntegratorOctupole.hh"
20#include "BDSMagnetStrength.hh"
21#include "BDSStep.hh"
22#include "BDSUtilities.hh"
23
24#include "G4Mag_EqRhs.hh"
25#include "G4MagIntegratorStepper.hh"
26#include "G4ThreeVector.hh"
27
28#include "CLHEP/Units/SystemOfUnits.h"
29
30#include <cmath>
31
32BDSIntegratorOctupole::BDSIntegratorOctupole(BDSMagnetStrength const* strength,
33 G4double brho,
34 G4Mag_EqRhs* eqOfMIn):
36{
37 // B''' = d^3By/dx^3 = Brho * (1/Brho d^3By/dx^3) = Brho * k3
38 bTriplePrime = brho * (*strength)["k3"] / (CLHEP::m3*CLHEP::m);
39
40 zeroStrength = !BDS::IsFinite(bTriplePrime);
41#ifdef BDSDEBUG
42 G4cout << __METHOD_NAME__ << "B''' = " << bTriplePrime << G4endl;
43#endif
44}
45
46void BDSIntegratorOctupole::AdvanceHelix(const G4double yIn[],
47 G4double h,
48 G4double yOut[],
49 G4double yErr[])
50{
51 G4ThreeVector mom = G4ThreeVector(yIn[3], yIn[4], yIn[5]);
52 G4double momMag = mom.mag();
53 G4double kappa = -eqOfM->FCof()*bTriplePrime / momMag;
54
55 if(std::abs(kappa) < 1e-20)
56 {
57 AdvanceDriftMag(yIn, h, yOut, yErr);
58 SetDistChord(0);
59 return;
60 }
61
62 G4ThreeVector pos = G4ThreeVector(yIn[0], yIn[1], yIn[2]);
63 BDSStep localPosMom = ConvertToLocal(pos, mom, h, false);
64 G4ThreeVector localPos = localPosMom.PreStepPoint();
65 G4ThreeVector localMom = localPosMom.PostStepPoint();
66 G4ThreeVector localMomUnit = localMom.unit();
67
68 G4double x0 = localPos.x();
69 G4double y0 = localPos.y();
70
71 // Evaluate field at the approximate midpoint of the step.
72 const G4double halfH = 0.5*h;
73 x0 = x0 + localMomUnit.x()*halfH;
74 y0 = y0 + localMomUnit.y()*halfH;
75
76 G4double xp = localMomUnit.x();
77 G4double yp = localMomUnit.y();
78 G4double zp = localMomUnit.z();
79
80 G4double y3fac = y0*(y0*y0 - 3*x0*x0);
81 G4double x3fac = x0*(x0*x0 - 3*y0*y0);
82
83 // local r'' (for curvature)
84 G4ThreeVector localA;
85 localA.setX(-zp*x3fac);
86 localA.setY(-zp*y3fac);
87 localA.setZ( xp*x3fac + yp*y3fac);
88
89 localA *= kappa / 6; // 6 is actually a 3! factor.;
90
91 AdvanceChord(h,localPos,localMomUnit,localA);
92 ConvertToGlobal(localPos, localMomUnit, yOut, yErr, momMag);
93}
BDSStep ConvertToLocal(G4Step const *const step, G4bool useCurvilinear=true) const
void AdvanceDriftMag(const G4double yIn[], const G4double h, G4double yOut[], G4double yErr[]) const
Error array [6] all 0.
Common functionality for Euler integrators.
void AdvanceChord(const G4double h, G4ThreeVector &localPos, G4ThreeVector &localMom, const G4ThreeVector &localA)
G4Mag_EqRhs * eqOfM
void SetDistChord(G4double distChordIn)
Setter for distChord to private member.
void ConvertToGlobal(const G4ThreeVector &localPos, const G4ThreeVector &localMom, G4double yOut[], G4double yErr[], const G4double momScaling=1.0)
scaling of momentum in case localMom is a unit vector
virtual void AdvanceHelix(const G4double yIn[], G4double h, G4double yOut[], G4double yErr[])
Calculate the new particle coordinates.
G4double bTriplePrime
3rd differential of field.
Efficient storage of magnet strengths.
A simple class to represent the positions of a step.
Definition BDSStep.hh:32
G4ThreeVector PostStepPoint() const
Accessor.
Definition BDSStep.hh:42
G4ThreeVector PreStepPoint() const
Accessor.
Definition BDSStep.hh:41
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())