BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldEInterpolated2Layer.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 "BDSException.hh"
21#include "BDSExtent.hh"
22#include "BDSFieldEInterpolated.hh"
23#include "BDSFieldEInterpolated2Layer.hh"
24
25#include "G4ThreeVector.hh"
26
27BDSFieldEInterpolated2Layer::BDSFieldEInterpolated2Layer(BDSFieldEInterpolated* mainFieldIn,
28 BDSFieldEInterpolated* subFieldIn):
29 mainField(mainFieldIn),
30 subField(subFieldIn),
31 subFieldExtent(subFieldIn->Extent())
32{
33 if (!mainField->ExtentNoOffset().Encompasses(subFieldIn->ExtentNoOffset()))
34 {throw BDSException(__METHOD_NAME__, "sub field in field map is bigger than main field.");}
35}
36
37BDSFieldEInterpolated2Layer::~BDSFieldEInterpolated2Layer()
38{
39 delete mainField;
40 delete subField;
41}
42
43G4ThreeVector BDSFieldEInterpolated2Layer::GetField(const G4ThreeVector& position,
44 const G4double t) const
45{
46 // transformations in these objects are only the transform of the field definition,
47 // not w.r.t. the beam line which is done already on the incoming position for this instance
48 if (subFieldExtent.Encompasses(position))
49 {return subField->GetFieldTransformed(position, t);}
50 else
51 {return mainField->GetFieldTransformed(position, t);}
52}
53
55{
56 return mainField->TimeVarying() || subField->TimeVarying();
57}
General exception with possible name of object and message.
Definition: BDSException.hh:35
G4bool Encompasses(const G4ThreeVector &point) const
Return whether the extent encompasses the point. True if point lies inside the extent.
Definition: BDSExtent.cc:190
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Return the interpolated field value at a given point.
Class to provide scaling and a base class pointer for interpolator fields.
virtual G4bool TimeVarying() const
BDSExtent ExtentNoOffset() const
Extent of field without any offset (ie in its own coordinate frame).
virtual G4ThreeVector GetFieldTransformed(const G4ThreeVector &position, const G4double t) const
Get the field value after applying transform for local offset.
Definition: BDSFieldE.cc:42