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) 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 "BDSArray1DCoords.hh"
19#include "BDSExtent.hh"
20
21#include "globals.hh"
22
23#include <array>
24#include <cmath>
25#include <ostream>
26#include <limits>
27#include <set>
28#include <vector>
29
31 G4double xMinIn,
32 G4double xMaxIn,
33 BDSDimensionType dimensionIn):
34 BDSArray2DCoords(nXIn,1,
35 xMinIn,xMaxIn,
36 0, 1,
37 dimensionIn)
38{
39 std::set<BDSDimensionType> allDims = {BDSDimensionType::x,
40 BDSDimensionType::y,
41 BDSDimensionType::z,
42 BDSDimensionType::t};
43 allDims.erase(dimensionIn);
44 std::array<BDSDimensionType*, 3> vars = {&yDimension,
45 &zDimension,
46 &tDimension};
47 std::vector<BDSDimensionType> unusedDims(allDims.begin(), allDims.end());
48 for (G4int i = 0; i < 3; i++)
49 {*(vars[i]) = unusedDims[i];}
50 BuildDimensionIndex();
51 timeVarying = dimensionIn == BDSDimensionType::t;
52}
53
55 BDSFieldValue (&localData)[2],
56 G4double& xFrac) const
57{
58 G4double xArrayCoords = ArrayCoordsFromX(x);
59 auto x1 = (G4int)std::floor(xArrayCoords);
60 xFrac = xArrayCoords - x1;
61 for (G4int i = 0; i < 2; i++)
62 {localData[i] = GetConst(x1+i);}
63}
64
66 BDSFieldValue (&localData)[4],
67 G4double& xFrac) const
68{
69 G4double xArrayCoords = ArrayCoordsFromX(x);
70 auto x1 = (G4int)std::floor(xArrayCoords);
71 xFrac = xArrayCoords - x1;
72 for (G4int i = 0; i < 4; i++)
73 {localData[i] = GetConst(x1-1+i);}
74}
75
77 G4double /*y*/,
78 G4double /*z*/,
79 G4double /*t*/) const
80{
81 return GetConst(NearestX(x));
82}
83
84std::ostream& operator<< (std::ostream& out, BDSArray1DCoords const &a)
85{
86 return a.Print(out);
87}
88
90{
91 G4double limitMax = std::numeric_limits<double>::max();
92 G4double limitMin = std::numeric_limits<double>::lowest();
93 return BDSExtent(xMin, xMax, limitMin, limitMax, limitMin, limitMax);
94}
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:45
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38