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),
61 CheckStep(
xStep,
"x");
62 smallestSpatialStep = std::min(smallestSpatialStep,
xStep);
69 CheckStep(
yStep,
"y");
70 smallestSpatialStep = std::min(smallestSpatialStep,
yStep);
77 CheckStep(
zStep,
"z");
78 smallestSpatialStep = std::min(smallestSpatialStep,
zStep);
85 CheckStep(
tStep,
"t");
86 G4double lengthScale = CLHEP::c_light *
tStep;
87 smallestSpatialStep = std::min(smallestSpatialStep, lengthScale);
94void BDSArray4DCoords::CheckStep(G4double step,
const G4String& name)
98 throw BDSException(__METHOD_NAME__,
"Invalid " + name +
"min and " + name +
99 "max in array leading to 0 step size between points.");
108 G4bool rx = x < xMin || x >
xMax;
109 G4bool ry = y < yMin || y >
yMax;
110 G4bool rz = z < zMin || z >
zMax;
111 G4bool rt = t < tMin || t >
tMax;
112 return rx || ry || rz || rt;
123 std::to_string(x) +
", " +
124 std::to_string(y) +
", " +
125 std::to_string(z) +
", " +
126 std::to_string(t) +
") is outside array");
138 G4double& tFrac)
const
140 G4double xArrayCoords, yArrayCoords, zArrayCoords, tArrayCoords;
142 auto x1 = (G4int)std::floor(xArrayCoords);
143 auto y1 = (G4int)std::floor(yArrayCoords);
144 auto z1 = (G4int)std::floor(zArrayCoords);
145 auto t1 = (G4int)std::floor(tArrayCoords);
147 xFrac = xArrayCoords - x1;
148 yFrac = yArrayCoords - y1;
149 zFrac = zArrayCoords - z1;
150 tFrac = tArrayCoords - t1;
152 for (G4int i = 0; i < 2; i++)
154 for (G4int j = 0; j < 2; j++)
156 for (G4int k = 0; k < 2; k++)
158 for (G4int l = 0; l < 2; l++)
159 {localData[i][j][k][l] =
GetConst(x1+i, y1+j, z1+k, t1+l);}
173 G4double& tFrac)
const
175 G4double xArrayCoords, yArrayCoords, zArrayCoords, tArrayCoords;
177 auto x1 = (G4int)std::floor(xArrayCoords);
178 auto y1 = (G4int)std::floor(yArrayCoords);
179 auto z1 = (G4int)std::floor(zArrayCoords);
180 auto t1 = (G4int)std::floor(tArrayCoords);
182 xFrac = xArrayCoords - x1;
183 yFrac = yArrayCoords - y1;
184 zFrac = zArrayCoords - z1;
185 tFrac = tArrayCoords - t1;
187 for (G4int i = 0; i < 4; i++)
189 for (G4int j = 0; j < 4; j++)
191 for (G4int k = 0; k < 4; k++)
193 for (G4int l = 0; l < 4; l++)
194 {localData[i][j][k][l] =
GetConst(x1-1+i, y1-1+j, z1-1+k, t1-1+l);}
215 out <<
"X: (" <<
xMin <<
", " <<
xMax <<
")" << G4endl;
216 out <<
"Y: (" <<
yMin <<
", " <<
yMax <<
")" << G4endl;
217 out <<
"Z: (" <<
zMin <<
", " <<
zMax <<
")" << G4endl;
218 out <<
"T: (" <<
tMin <<
", " <<
tMax <<
")" << G4endl;
244 for (G4int i = 0; i < 4; i++)
246 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())