BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldMagInterpolated3D.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 "BDSDimensionType.hh"
19#include "BDSFieldMagInterpolated3D.hh"
20#include "BDSInterpolator3D.hh"
21
22#include "G4ThreeVector.hh"
23
24BDSFieldMagInterpolated3D::BDSFieldMagInterpolated3D(BDSInterpolator3D* interpolatorIn,
25 const G4Transform3D& offset,
26 G4double scalingIn):
27 BDSFieldMagInterpolated(interpolatorIn, offset, scalingIn),
28 interpolator(interpolatorIn),
29 firstDimensionIndex((interpolatorIn->FirstDimension()).underlying()),
30 firstTime((interpolatorIn->FirstDimension()).underlying() > 2),
31 secondDimensionIndex((interpolatorIn->SecondDimension()).underlying()),
32 secondTime((interpolatorIn->SecondDimension()).underlying() > 2),
33 thirdDimensionIndex((interpolatorIn->ThirdDimension()).underlying()),
34 thirdTime((interpolatorIn->ThirdDimension()).underlying() > 2)
35{;}
36
37BDSFieldMagInterpolated3D::~BDSFieldMagInterpolated3D()
38{
39 delete interpolator;
40}
41
42G4ThreeVector BDSFieldMagInterpolated3D::GetField(const G4ThreeVector& position,
43 const G4double t) const
44{
45 G4double fCoordinate = 0;
46 if (firstTime)
47 {fCoordinate = t;}
48 else
49 {fCoordinate = position[firstDimensionIndex];}
50 G4double sCoordinate = 0;
51 if (secondTime)
52 {sCoordinate = t;}
53 else
54 {sCoordinate = position[secondDimensionIndex];}
55 G4double tCoordinate = 0; // 't' for third
56 if (thirdTime)
57 {tCoordinate = t;}
58 else
59 {tCoordinate = position[thirdDimensionIndex];}
60 return interpolator->GetInterpolatedValue(fCoordinate, sCoordinate, tCoordinate) * Scaling();
61}
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Return the interpolated field value at a given point.
const G4bool firstTime
Cache of whether to use time coordinate.
const G4int secondDimensionIndex
Integer index to dimension to use.
const G4int firstDimensionIndex
Integer index to dimension to use.
BDSInterpolator3D * interpolator
Interpolator the field is based on.
const G4bool thirdTime
Cache of whether to use time coordinate.
const G4int thirdDimensionIndex
Integer index to dimension to use.
const G4bool secondTime
Cache of whether to use time coordinate.
Class to provide scaling and a base class pointer for interpolator fields.
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.