BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldMagDipole.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
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 "BDSDebug.hh"
20#include "BDSFieldMagDipole.hh"
21#include "BDSMagnetStrength.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh"
25#include "G4ThreeVector.hh"
26
27BDSFieldMagDipole::BDSFieldMagDipole(const G4ThreeVector& field):
28 localField(field)
29{
31#ifdef BDSDEBUG
32 G4cout << __METHOD_NAME__ << "B (local) = " << localField << G4endl;
33#endif
34}
35
37{
38 G4double field = (*strength)["field"];
39 G4double bx = (*strength)["bx"];
40 G4double by = (*strength)["by"];
41 G4double bz = (*strength)["bz"];
42
43 if (!BDS::IsFinite(bx) && !BDS::IsFinite(by) && !BDS::IsFinite(bz) && BDS::IsFinite(field))
44 {localField = G4ThreeVector(0,1,0) * field;}
45 else
46 {localField = G4ThreeVector(bx,by,bz).unit() * field;}
47
49#ifdef BDSDEBUG
50 G4cout << __METHOD_NAME__ << "B (local) (T) = " << localField / CLHEP::tesla << G4endl;
51#endif
52}
53
54G4ThreeVector BDSFieldMagDipole::GetField(const G4ThreeVector& /*position*/,
55 const G4double /*t*/) const
56{
57 return localField;
58}
G4ThreeVector localField
BDSFieldMagDipole()
Private default constructor to ensure use of supplied constructor.
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Access the field value.
G4bool finiteStrength
Flag to cache whether finite nor not.
Definition: BDSFieldMag.hh:83
Efficient storage of magnet strengths.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())