BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldEMInterpolated3D.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 "BDSFieldEMInterpolated3D.hh"
19#include "BDSInterpolator3D.hh"
20
21#include "G4ThreeVector.hh"
22#include "G4Types.hh"
23
24#include <utility>
25
26BDSFieldEMInterpolated3D::BDSFieldEMInterpolated3D(BDSInterpolator3D* eInterpolatorIn,
27 BDSInterpolator3D* bInterpolatorIn,
28 const G4Transform3D& offset,
29 G4double eScalingIn,
30 G4double bScalingIn):
31 BDSFieldEMInterpolated(eInterpolatorIn, bInterpolatorIn, offset, eScalingIn, bScalingIn),
32 eInterpolator(eInterpolatorIn),
33 bInterpolator(bInterpolatorIn),
34 eFirstDimensionIndex((eInterpolatorIn->FirstDimension()).underlying()),
35 eFirstTime((eInterpolatorIn->FirstDimension()).underlying() > 2),
36 eSecondDimensionIndex((eInterpolatorIn->SecondDimension()).underlying()),
37 eSecondTime((eInterpolatorIn->SecondDimension()).underlying() > 2),
38 eThirdDimensionIndex((eInterpolatorIn->ThirdDimension()).underlying()),
39 eThirdTime((eInterpolatorIn->ThirdDimension()).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 bThirdDimensionIndex((bInterpolatorIn->ThirdDimension()).underlying()),
45 bThirdTime((bInterpolatorIn->ThirdDimension()).underlying() > 2)
46{;}
47
48BDSFieldEMInterpolated3D::~BDSFieldEMInterpolated3D()
49{
50 delete eInterpolator;
51 delete bInterpolator;
52}
53
54std::pair<G4ThreeVector,G4ThreeVector> BDSFieldEMInterpolated3D::GetField(const G4ThreeVector& position,
55 const G4double t) const
56{
57 G4double eFCoordinate = 0;
58 if (eFirstTime)
59 {eFCoordinate = t;}
60 else
61 {eFCoordinate = position[eFirstDimensionIndex];}
62 G4double eSCoordinate = 0;
63 if (eSecondTime)
64 {eSCoordinate = t;}
65 else
66 {eSCoordinate = position[eSecondDimensionIndex];}
67 G4double eTCoordinate = 0;
68 if (eThirdTime)
69 {eTCoordinate = t;}
70 else
71 {eTCoordinate = position[eThirdDimensionIndex];}
72 G4double bFCoordinate = 0;
73 if (bFirstTime)
74 {bFCoordinate = t;}
75 else
76 {bFCoordinate = position[bFirstDimensionIndex];}
77 G4double bSCoordinate = 0;
78 if (bSecondTime)
79 {bSCoordinate = t;}
80 else
81 {bSCoordinate = position[bSecondDimensionIndex];}
82 G4double bTCoordinate = 0;
83 if (bThirdTime)
84 {bTCoordinate = t;}
85 else
86 {bTCoordinate = position[bThirdDimensionIndex];}
87
88 G4ThreeVector e = eInterpolator->GetInterpolatedValue(eFCoordinate,
89 eSCoordinate,
90 eTCoordinate) * EScaling();
91 G4ThreeVector b = bInterpolator->GetInterpolatedValue(bFCoordinate,
92 bSCoordinate,
93 bTCoordinate) * BScaling();
94 return std::make_pair(b,e);
95}
const G4int bFirstDimensionIndex
Integer index to dimension to use.
const G4bool eFirstTime
Cache of whether to use time coordinate.
const G4bool eSecondTime
Cache of whether to use time coordinate.
const G4int eFirstDimensionIndex
Integer index to dimension to use.
const G4bool eThirdTime
Cache of whether to use time coordinate.
const G4bool bThirdTime
Cache of whether to use time coordinate.
BDSInterpolator3D * eInterpolator
E Interplator 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 eThirdDimensionIndex
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 G4int eSecondDimensionIndex
Integer index to dimension to use.
BDSInterpolator3D * bInterpolator
B Interpolator the field is based on.
const G4int bThirdDimensionIndex
Integer index to dimension to use.
const G4int bSecondDimensionIndex
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 3D interpolators.
G4ThreeVector GetInterpolatedValue(G4double x, G4double y, G4double z) const
Public interface to a 3D interpolator. Returns Geant4 type as that's what will be needed.