BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSArray1DCoords.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 "BDSArray1DCoords.hh"
20#include "BDSExtent.hh"
21
22#include "globals.hh"
23
24#include <array>
25#include <cmath>
26#include <ostream>
27#include <limits>
28#include <set>
29#include <vector>
30
32 G4double xMinIn,
33 G4double xMaxIn,
34 BDSDimensionType dimensionIn):
35 BDSArray2DCoords(nXIn,1,
36 xMinIn,xMaxIn,
37 0, 1,
38 dimensionIn)
39{
40 std::set<BDSDimensionType> allDims = {BDSDimensionType::x,
41 BDSDimensionType::y,
42 BDSDimensionType::z,
43 BDSDimensionType::t};
44 allDims.erase(dimensionIn);
45 std::array<BDSDimensionType*, 3> vars = {&yDimension,
46 &zDimension,
47 &tDimension};
48 std::vector<BDSDimensionType> unusedDims(allDims.begin(), allDims.end());
49 for (G4int i = 0; i < 3; i++)
50 {*(vars[i]) = unusedDims[i];}
51 BuildDimensionIndex();
52 timeVarying = dimensionIn == BDSDimensionType::t;
53}
54
56 BDSFieldValue (&localData)[2],
57 G4double& xFrac) const
58{
59 G4double xArrayCoords = ArrayCoordsFromX(x);
60 auto x1 = (G4int)std::floor(xArrayCoords);
61 xFrac = xArrayCoords - x1;
62 for (G4int i = 0; i < 2; i++)
63 {localData[i] = GetConst(x1+i);}
64}
65
67 BDSFieldValue (&localData)[4],
68 G4double& xFrac) const
69{
70 G4double xArrayCoords = ArrayCoordsFromX(x);
71 auto x1 = (G4int)std::floor(xArrayCoords);
72 xFrac = xArrayCoords - x1;
73 for (G4int i = 0; i < 4; i++)
74 {localData[i] = GetConst(x1-1+i);}
75}
76
78 G4double /*y*/,
79 G4double /*z*/,
80 G4double /*t*/) const
81{
82 return GetConst(NearestX(x));
83}
84
85std::ostream& operator<< (std::ostream& out, BDSArray1DCoords const &a)
86{
87 return a.Print(out);
88}
89
91{
92 G4double limitMax = std::numeric_limits<double>::max();
93 G4double limitMin = std::numeric_limits<double>::lowest();
94 return BDSExtent(xMin, xMax, limitMin, limitMax, limitMin, limitMax);
95}
1D array with spatial mapping derived from BDSArray4DCoords.
BDSArray1DCoords()=delete
virtual void ExtractSection4(G4double x, BDSFieldValue(&localData)[4], G4double &xFrac) const
Extract 4 points lying around coordinate x, where x will be between points 2 and 3.
virtual void ExtractSection2(G4double x, BDSFieldValue(&localData)[2], G4double &xFrac) const
Extract 2 points lying around coordinate x.
virtual BDSFieldValue ExtractNearest(G4double x, G4double y=0, G4double z=0, G4double t=0) const
Extract nearest field value from array. y,z,t ignored but required for overload.
virtual BDSExtent Extent() const
2D array with spatial mapping derived from BDSArray4DCoords.
G4double xMin
Dimension parameter - protected for derived class access.
virtual G4double ArrayCoordsFromX(G4double x) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
virtual std::ostream & Print(std::ostream &out) const
virtual G4int NearestX(G4double x) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
G4double xMax
Dimension parameter - protected for derived class access.
virtual const BDSFieldValue & GetConst(G4int x, G4int y=0, G4int z=0, G4int t=0) const
Definition: BDSArray4D.cc:46
Holder for +- extents in 3 dimensions.
Definition: BDSExtent.hh:39