BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSArray4DCoords.hh
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#ifndef BDSARRAY4DCOORDS_H
19#define BDSARRAY4DCOORDS_H
20
21#include "BDSArray4D.hh"
22#include "BDSDimensionType.hh"
23#include "BDSFourVector.hh"
24
25#include "globals.hh"
26
27#include <array>
28#include <ostream>
29
30class BDSExtent;
31
48{
49public:
52 BDSArray4DCoords() = delete;
53
57 BDSArray4DCoords(G4int nXIn, G4int nYIn, G4int nZIn, G4int nTIn,
58 G4double xMinIn, G4double xMaxIn,
59 G4double yMinIn, G4double yMaxIn,
60 G4double zMinIn, G4double zMaxIn,
61 G4double tMinIn, G4double tMaxIn,
62 BDSDimensionType xDimensionIn = BDSDimensionType::x,
63 BDSDimensionType yDimensionIn = BDSDimensionType::y,
64 BDSDimensionType zDimensionIn = BDSDimensionType::z,
65 BDSDimensionType tDimensionIn = BDSDimensionType::t);
66
67 virtual ~BDSArray4DCoords(){;}
68
70 inline G4double XStep() const {return xStep;}
71 inline G4double YStep() const {return yStep;}
72 inline G4double ZStep() const {return zStep;}
73 inline G4double TStep() const {return tStep;}
75
78 inline G4double SmallestSpatialStep() const {return smallestSpatialStep;}
79
81 virtual G4bool OutsideCoords(G4double x,
82 G4double y,
83 G4double z,
84 G4double t) const;
85
89 virtual void OutsideCoordsWarn(G4double x,
90 G4double y,
91 G4double z,
92 G4double t) const;
93
95 virtual G4double ArrayCoordsFromX(G4double x) const {return (x - xMin) / xStep;}
96 virtual G4double ArrayCoordsFromY(G4double y) const {return (y - yMin) / yStep;}
97 virtual G4double ArrayCoordsFromZ(G4double z) const {return (z - zMin) / zStep;}
98 virtual G4double ArrayCoordsFromT(G4double t) const {return (t - tMin) / tStep;}
100
102 void ArrayCoordsFromXY(G4double& x, G4double& xArr,
103 G4double& y, G4double& yArr) const
104 {xArr = ArrayCoordsFromX(x); yArr = ArrayCoordsFromY(y);}
105 void ArrayCoordsFromXYZ(G4double& x, G4double& xArr,
106 G4double& y, G4double& yArr,
107 G4double& z, G4double& zArr) const
108 {xArr = ArrayCoordsFromX(x); yArr = ArrayCoordsFromY(y); zArr = ArrayCoordsFromZ(z);}
109 void ArrayCoordsFromXYZT(G4double& x, G4double& xArr,
110 G4double& y, G4double& yArr,
111 G4double& z, G4double& zArr,
112 G4double& t, G4double& tArr) const
113 {xArr = ArrayCoordsFromX(x); yArr = ArrayCoordsFromY(y); zArr = ArrayCoordsFromZ(z); tArr = ArrayCoordsFromT(t);}
115
118 G4double y,
119 G4double z,
120 G4double t) const
121 {
126 }
127
129 inline G4double XFromArrayCoords(G4double xCoord) const {return xMin + xCoord*xStep;}
130 inline G4double YFromArrayCoords(G4double yCoord) const {return yMin + yCoord*yStep;}
131 inline G4double ZFromArrayCoords(G4double zCoord) const {return zMin + zCoord*zStep;}
132 inline G4double TFromArrayCoords(G4double tCoord) const {return tMin + tCoord*tStep;}
134
138 G4double y,
139 G4double z,
140 G4double t) const
141 {
146 }
147
149 virtual G4int NearestX(G4double x) const {return (G4int)round((x - xMin) / xStep);}
150 virtual G4int NearestY(G4double y) const {return (G4int)round((y - yMin) / yStep);}
151 virtual G4int NearestZ(G4double z) const {return (G4int)round((z - zMin) / zStep);}
152 virtual G4int NearestT(G4double t) const {return (G4int)round((t - tMin) / tStep);}
154
157 G4double y,
158 G4double z,
159 G4double t) const
160 {
162 NearestY(y),
163 NearestZ(z),
164 NearestT(t));
165 }
166
169 {
170 return BDSFourVector<G4int>(NearestX(pos[0]),
171 NearestY(pos[1]),
172 NearestZ(pos[2]),
173 NearestT(pos[3]));
174 }
175
177 virtual void ExtractSection2x2x2x2(G4double x,
178 G4double y,
179 G4double z,
180 G4double t,
181 BDSFieldValue (&localData)[2][2][2][2],
182 G4double& xFrac,
183 G4double& yFrac,
184 G4double& zFrac,
185 G4double& tFrac) const;
186
188 virtual void ExtractSection4x4x4x4(G4double x,
189 G4double y,
190 G4double z,
191 G4double t,
192 BDSFieldValue (&localData)[4][4][4][4],
193 G4double& xFrac,
194 G4double& yFrac,
195 G4double& zFrac,
196 G4double& tFrac) const;
197
199 virtual BDSFieldValue ExtractNearest(G4double x,
200 G4double y = 0,
201 G4double z = 0,
202 G4double t = 0) const;
203
206 virtual std::ostream& Print(std::ostream& out) const;
207
209 friend std::ostream& operator<< (std::ostream& out, BDSArray4DCoords const &a);
210
212 virtual BDSExtent Extent() const;
213
214 inline G4double XMin() const {return xMin;}
215 inline G4double YMin() const {return yMin;}
216 inline G4double ZMin() const {return zMin;}
217 inline G4double TMin() const {return tMin;}
218 inline G4double XMax() const {return xMax;}
219 inline G4double YMax() const {return yMax;}
220 inline G4double ZMax() const {return zMax;}
221 inline G4double TMax() const {return tMax;}
222
225 inline BDSDimensionType SecondDimension() const {return yDimension;}
226 inline BDSDimensionType ThirdDimension() const {return zDimension;}
227 inline BDSDimensionType FourthDimension() const {return tDimension;}
229
232 virtual G4bool TimeVarying() const {return timeVarying;}
233
236 G4int DimensionIndex(BDSDimensionType spatialDimension) const;
237
239 inline std::array<G4int, 4> ArrayToSpatialDimensionIndices() const {return dimensions;}
240
241protected:
243 void BuildDimensionIndex();
244
246 G4double xMin;
247 G4double xMax;
248 G4double yMin;
249 G4double yMax;
250 G4double zMin;
251 G4double zMax;
252 G4double tMin;
253 G4double tMax;
254
255 G4double xStep;
256 G4double yStep;
257 G4double zStep;
258 G4double tStep;
260
261 G4double smallestSpatialStep;
262
266 BDSDimensionType yDimension;
267 BDSDimensionType zDimension;
268 BDSDimensionType tDimension;
269 std::array<G4int, 4> dimensions;
270 G4bool timeVarying;
271
272private:
273 static void CheckStep(G4double step, const G4String& name);
274};
275
276#endif
Overlay of 4D array that provides uniform only spatial coordinate mapping.
G4double xMin
Dimension parameter - protected for derived class access.
void ArrayCoordsFromXY(G4double &x, G4double &xArr, G4double &y, G4double &yArr) const
Utility version to forward to individual function.
virtual G4bool OutsideCoords(G4double x, G4double y, G4double z, G4double t) const
Whether the spatial coordinates lie outside the range of the array or not.
G4double yMin
Dimension parameter - protected for derived class access.
G4double XStep() const
The distance in spatial coordinates between any two points in the array.
G4double YFromArrayCoords(G4double yCoord) const
Return spatial value from a continuous array coordinate in one dimension.
virtual G4double ArrayCoordsFromX(G4double x) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
BDSFourVector< G4int > NearestXYZT(const BDSFourVector< G4double > &pos) const
Return the index of the nearest field value in space via four-vector.
G4double SmallestSpatialStep() const
G4double yStep
Dimension parameter - protected for derived class access.
BDSDimensionType ThirdDimension() const
Accessor for each dimension label. e.g. array 'x' = spatial z.
virtual std::ostream & Print(std::ostream &out) const
virtual G4int NearestY(G4double y) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
virtual G4double ArrayCoordsFromZ(G4double z) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
virtual G4int NearestX(G4double x) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
BDSDimensionType SecondDimension() const
Accessor for each dimension label. e.g. array 'x' = spatial z.
BDSFourVector< G4double > XYZTFromArrayCoords(G4double x, G4double y, G4double z, G4double t) const
virtual BDSExtent Extent() const
Return the SPATIAL (only) extent of this field without any offset. Ignores time.
virtual G4double ArrayCoordsFromY(G4double y) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
std::array< G4int, 4 > ArrayToSpatialDimensionIndices() const
Access all indices at once.
virtual G4double ArrayCoordsFromT(G4double t) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
G4double zMax
Dimension parameter - protected for derived class access.
virtual G4int NearestT(G4double t) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
virtual G4bool TimeVarying() const
G4double tMin
Dimension parameter - protected for derived class access.
friend std::ostream & operator<<(std::ostream &out, BDSArray4DCoords const &a)
Output stream.
BDSDimensionType FourthDimension() const
Accessor for each dimension label. e.g. array 'x' = spatial z.
G4double zMin
Dimension parameter - protected for derived class access.
BDSDimensionType xDimension
virtual G4int NearestZ(G4double z) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
G4double xStep
Dimension parameter - protected for derived class access.
virtual void OutsideCoordsWarn(G4double x, G4double y, G4double z, G4double t) const
virtual void ExtractSection2x2x2x2(G4double x, G4double y, G4double z, G4double t, BDSFieldValue(&localData)[2][2][2][2], G4double &xFrac, G4double &yFrac, G4double &zFrac, G4double &tFrac) const
Extract 2x2x2x2 points lying around coordinate x.
G4double YStep() const
The distance in spatial coordinates between any two points in the array.
G4int DimensionIndex(BDSDimensionType spatialDimension) const
G4double yMax
Dimension parameter - protected for derived class access.
G4double xMax
Dimension parameter - protected for derived class access.
virtual void ExtractSection4x4x4x4(G4double x, G4double y, G4double z, G4double t, BDSFieldValue(&localData)[4][4][4][4], G4double &xFrac, G4double &yFrac, G4double &zFrac, G4double &tFrac) const
Extract 4x4x4x4 points lying around coordinate x.
G4double TFromArrayCoords(G4double tCoord) const
Return spatial value from a continuous array coordinate in one dimension.
G4double tMax
Dimension parameter - protected for derived class access.
G4double zStep
Dimension parameter - protected for derived class access.
G4double TStep() const
The distance in spatial coordinates between any two points in the array.
void ArrayCoordsFromXYZ(G4double &x, G4double &xArr, G4double &y, G4double &yArr, G4double &z, G4double &zArr) const
Utility version to forward to individual function.
void ArrayCoordsFromXYZT(G4double &x, G4double &xArr, G4double &y, G4double &yArr, G4double &z, G4double &zArr, G4double &t, G4double &tArr) const
Utility version to forward to individual function.
BDSArray4DCoords()=delete
G4double ZFromArrayCoords(G4double zCoord) const
Return spatial value from a continuous array coordinate in one dimension.
G4double XFromArrayCoords(G4double xCoord) const
Return spatial value from a continuous array coordinate in one dimension.
G4double ZStep() const
The distance in spatial coordinates between any two points in the array.
BDSFourVector< G4int > NearestXYZT(G4double x, G4double y, G4double z, G4double t) const
Return the index of the nearest field value in space.
virtual BDSFieldValue ExtractNearest(G4double x, G4double y=0, G4double z=0, G4double t=0) const
Extract nearest field value from array.
BDSFourVector< G4double > ArrayCoordsFromXYZT(G4double x, G4double y, G4double z, G4double t) const
Convenience function to easily get array coords in all dimensions at once.
G4double tStep
Dimension parameter - protected for derived class access.
BDSDimensionType FirstDimension() const
Accessor for each dimension label. e.g. array 'x' = spatial z.
void BuildDimensionIndex()
Build up an array of ints based on the order of dimensions stored in the array.
4D array and base class for 3,2 & 1D arrays.
Definition BDSArray4D.hh:50
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38
A simple templated four vector class.