19#include "BDSArray4DCoords.hh"
21#include "BDSException.hh"
22#include "BDSExtent.hh"
23#include "BDSFieldValue.hh"
24#include "BDSUtilities.hh"
26#include "CLHEP/Units/PhysicalConstants.h"
37 G4double xMinIn, G4double xMaxIn,
38 G4double yMinIn, G4double yMaxIn,
39 G4double zMinIn, G4double zMaxIn,
40 G4double tMinIn, G4double tMaxIn,
46 xMin(xMinIn), xMax(xMaxIn),
47 yMin(yMinIn), yMax(yMaxIn),
48 zMin(zMinIn), zMax(zMaxIn),
49 tMin(tMinIn), tMax(tMaxIn),
50 smallestSpatialStep(std::numeric_limits<double>::max()),
51 xDimension(xDimensionIn),
52 yDimension(yDimensionIn),
53 zDimension(zDimensionIn),
54 tDimension(tDimensionIn),
62 CheckStep(
xStep,
"x");
63 smallestSpatialStep = std::min(smallestSpatialStep,
xStep);
70 CheckStep(
yStep,
"y");
71 smallestSpatialStep = std::min(smallestSpatialStep,
yStep);
78 CheckStep(
zStep,
"z");
79 smallestSpatialStep = std::min(smallestSpatialStep,
zStep);
86 CheckStep(
tStep,
"t");
87 G4double lengthScale = CLHEP::c_light *
tStep;
88 smallestSpatialStep = std::min(smallestSpatialStep, lengthScale);
95void BDSArray4DCoords::CheckStep(G4double step,
const G4String& name)
99 throw BDSException(__METHOD_NAME__,
"Invalid " + name +
"min and " + name +
100 "max in array leading to 0 step size between points.");
109 G4bool rx = x < xMin || x >
xMax;
110 G4bool ry = y < yMin || y >
yMax;
111 G4bool rz = z < zMin || z >
zMax;
112 G4bool rt = t < tMin || t >
tMax;
113 return rx || ry || rz || rt;
124 std::to_string(x) +
", " +
125 std::to_string(y) +
", " +
126 std::to_string(z) +
", " +
127 std::to_string(t) +
") is outside array");
139 G4double& tFrac)
const
141 G4double xArrayCoords, yArrayCoords, zArrayCoords, tArrayCoords;
143 auto x1 = (G4int)std::floor(xArrayCoords);
144 auto y1 = (G4int)std::floor(yArrayCoords);
145 auto z1 = (G4int)std::floor(zArrayCoords);
146 auto t1 = (G4int)std::floor(tArrayCoords);
148 xFrac = xArrayCoords - x1;
149 yFrac = yArrayCoords - y1;
150 zFrac = zArrayCoords - z1;
151 tFrac = tArrayCoords - t1;
153 for (G4int i = 0; i < 2; i++)
155 for (G4int j = 0; j < 2; j++)
157 for (G4int k = 0; k < 2; k++)
159 for (G4int l = 0; l < 2; l++)
160 {localData[i][j][k][l] =
GetConst(x1+i, y1+j, z1+k, t1+l);}
174 G4double& tFrac)
const
176 G4double xArrayCoords, yArrayCoords, zArrayCoords, tArrayCoords;
178 auto x1 = (G4int)std::floor(xArrayCoords);
179 auto y1 = (G4int)std::floor(yArrayCoords);
180 auto z1 = (G4int)std::floor(zArrayCoords);
181 auto t1 = (G4int)std::floor(tArrayCoords);
183 xFrac = xArrayCoords - x1;
184 yFrac = yArrayCoords - y1;
185 zFrac = zArrayCoords - z1;
186 tFrac = tArrayCoords - t1;
188 for (G4int i = 0; i < 4; i++)
190 for (G4int j = 0; j < 4; j++)
192 for (G4int k = 0; k < 4; k++)
194 for (G4int l = 0; l < 4; l++)
195 {localData[i][j][k][l] =
GetConst(x1-1+i, y1-1+j, z1-1+k, t1-1+l);}
216 out <<
"X: (" <<
xMin <<
", " <<
xMax <<
")" << G4endl;
217 out <<
"Y: (" <<
yMin <<
", " <<
yMax <<
")" << G4endl;
218 out <<
"Z: (" <<
zMin <<
", " <<
zMax <<
")" << G4endl;
219 out <<
"T: (" <<
tMin <<
", " <<
tMax <<
")" << G4endl;
245 for (G4int i = 0; i < 4; i++)
247 if (dimensions[i] == match)
Overlay of 4D array that provides uniform only spatial coordinate mapping.
G4double xMin
Dimension parameter - protected for derived class access.
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 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 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.
virtual BDSExtent Extent() const
Return the SPATIAL (only) extent of this field without any offset. Ignores time.
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.
G4double tMin
Dimension parameter - protected for derived class access.
BDSDimensionType FourthDimension() const
Accessor for each dimension label. e.g. array 'x' = spatial z.
G4double zMin
Dimension parameter - protected for derived class access.
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.
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 tMax
Dimension parameter - protected for derived class access.
G4double zStep
Dimension parameter - protected for derived class access.
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
virtual BDSFieldValue ExtractNearest(G4double x, G4double y=0, G4double z=0, G4double t=0) const
Extract nearest field value from array.
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.
virtual const BDSFieldValue & GetConst(G4int x, G4int y=0, G4int z=0, G4int t=0) const
virtual std::ostream & Print(std::ostream &out) const
General exception with possible name of object and message.
Holder for +- extents in 3 dimensions.
type underlying() const
return underlying value (can be used in switch statement)
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())