BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldEMInterpolated2D.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 "BDSDimensionType.hh"
20#include "BDSFieldEMInterpolated2D.hh"
21#include "BDSInterpolator2D.hh"
22
23#include "G4ThreeVector.hh"
24#include "G4Types.hh"
25
26#include <utility>
27
28BDSFieldEMInterpolated2D::BDSFieldEMInterpolated2D(BDSInterpolator2D* eInterpolatorIn,
29 BDSInterpolator2D* bInterpolatorIn,
30 const G4Transform3D& offset,
31 G4double eScalingIn,
32 G4double bScalingIn):
33 BDSFieldEMInterpolated(eInterpolatorIn, bInterpolatorIn, offset, eScalingIn, bScalingIn),
34 eInterpolator(eInterpolatorIn),
35 bInterpolator(bInterpolatorIn),
36 eFirstDimensionIndex((eInterpolatorIn->FirstDimension()).underlying()),
37 eFirstTime((eInterpolatorIn->FirstDimension()).underlying() > 2),
38 eSecondDimensionIndex((eInterpolatorIn->SecondDimension()).underlying()),
39 eSecondTime((eInterpolatorIn->SecondDimension()).underlying() > 2),
40 bFirstDimensionIndex((bInterpolatorIn->FirstDimension()).underlying()),
41 bFirstTime((bInterpolatorIn->FirstDimension()).underlying() > 2),
42 bSecondDimensionIndex((bInterpolatorIn->SecondDimension()).underlying()),
43 bSecondTime((bInterpolatorIn->SecondDimension()).underlying() > 2)
44{;}
45
46BDSFieldEMInterpolated2D::~BDSFieldEMInterpolated2D()
47{
48 delete eInterpolator;
49 delete bInterpolator;
50}
51
52std::pair<G4ThreeVector,G4ThreeVector> BDSFieldEMInterpolated2D::GetField(const G4ThreeVector& position,
53 const G4double t) const
54{
55 G4double eFCoordinate = 0;
56 if (eFirstTime)
57 {eFCoordinate = t;}
58 else
59 {eFCoordinate = position[eFirstDimensionIndex];}
60 G4double eSCoordinate = 0;
61 if (eSecondTime)
62 {eSCoordinate = t;}
63 else
64 {eSCoordinate = position[eSecondDimensionIndex];}
65 G4double bFCoordinate = 0;
66 if (bFirstTime)
67 {bFCoordinate = t;}
68 else
69 {bFCoordinate = position[bFirstDimensionIndex];}
70 G4double bSCoordinate = 0;
71 if (bSecondTime)
72 {bSCoordinate = t;}
73 else
74 {bSCoordinate = position[bSecondDimensionIndex];}
75 G4ThreeVector e = eInterpolator->GetInterpolatedValue(eFCoordinate,
76 eSCoordinate) * EScaling();
77 G4ThreeVector b = bInterpolator->GetInterpolatedValue(bFCoordinate,
78 bSCoordinate) * BScaling();
79 return std::make_pair(b,e);
80}
const G4int eFirstDimensionIndex
Integer index to dimension to use.
BDSInterpolator2D * eInterpolator
E Interpolator the field is based on.
const G4bool bFirstTime
Cache of whether to use time coordinate.
const G4bool bSecondTime
Cache of whether to use time coordinate.
const G4int eSecondDimensionIndex
Integer index to dimension to use.
BDSInterpolator2D * bInterpolator
B Interpolator the field is based on.
const G4bool eSecondTime
Cache of whether to use time coordinate.
const G4int bSecondDimensionIndex
Integer index to dimension to use.
virtual std::pair< G4ThreeVector, G4ThreeVector > GetField(const G4ThreeVector &position, const G4double t=0) const
Return the interpolated field value at a given point.
const G4bool eFirstTime
Cache of whether to use time coordinate.
const G4int bFirstDimensionIndex
Integer index to dimension to use.
Class to provide scaling and a base class pointer for interpolator fields.
G4double EScaling() const
Accessor.
G4double BScaling() const
Accessor.
Interface for all 2D interpolators.
G4ThreeVector GetInterpolatedValue(G4double x, G4double y) const
Public interface to a 2D interpolator. Returns Geant4 type as that's what will be needed.