BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSArray4D.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
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#ifndef BDSARRAY4D_H
20#define BDSARRAY4D_H
21
22#include "BDSFieldValue.hh"
23#include "BDSFourVector.hh"
24
25#include <ostream>
26#include <vector>
27
51{
52public:
55 BDSArray4D() = delete;
58 BDSArray4D(G4int nXIn, G4int nYIn, G4int nZIn, G4int nTIn);
59 virtual ~BDSArray4D(){;}
60
62 inline G4int NX() const {return nX;}
63 inline G4int NY() const {return nY;}
64 inline G4int NZ() const {return nZ;}
65 inline G4int NT() const {return nT;}
66 inline BDSFourVector<G4int> NXYZT() const {return BDSFourVector<G4int>(NX(), NY(), NZ(), NT());}
68
70 virtual BDSFieldValue& operator()(G4int x,
71 G4int y = 0,
72 G4int z = 0,
73 G4int t = 0);
74
77 {return operator()(pos.x(), pos.y(), pos.z(), pos.t());}
78
82 virtual const BDSFieldValue& GetConst(G4int x,
83 G4int y = 0,
84 G4int z = 0,
85 G4int t = 0) const;
86
88 virtual const BDSFieldValue& operator()(G4int x,
89 G4int y = 0,
90 G4int z = 0,
91 G4int t = 0) const;
92
95 {return operator()(pos.x(), pos.y(), pos.z(), pos.t());}
96
98 virtual G4bool Outside(G4int x,
99 G4int y,
100 G4int z,
101 G4int t) const;
102
104 virtual void OutsideWarn(G4int x,
105 G4int y,
106 G4int z,
107 G4int t) const;
108
112 virtual std::ostream& Print(std::ostream& out) const;
113
115 friend std::ostream& operator<< (std::ostream& out, BDSArray4D const &a);
116
117protected:
118
120 const G4int nX;
121 const G4int nY;
122 const G4int nZ;
123 const G4int nT;
125
128
129private:
131 std::vector<BDSFieldValue> data;
132};
133
134#endif
4D array and base class for 3,2 & 1D arrays.
Definition BDSArray4D.hh:51
virtual void OutsideWarn(G4int x, G4int y, G4int z, G4int t) const
Use Outside() but warn and exit if the coordinates requested are outside the array.
Definition BDSArray4D.cc:76
G4int NZ() const
Access the number of elements in a given dimension.
Definition BDSArray4D.hh:64
friend std::ostream & operator<<(std::ostream &out, BDSArray4D const &a)
Output stream.
std::vector< BDSFieldValue > data
A 1D array representing all the data.
virtual G4bool Outside(G4int x, G4int y, G4int z, G4int t) const
Return whether the indices are valid and lie within the array boundaries or not.
Definition BDSArray4D.cc:64
virtual BDSFieldValue & operator()(G4int x, G4int y=0, G4int z=0, G4int t=0)
Setter & (technically, a non-const) accessor.
Definition BDSArray4D.cc:37
const G4int nZ
Dimension.
G4int NX() const
Access the number of elements in a given dimension.
Definition BDSArray4D.hh:62
G4int NT() const
Access the number of elements in a given dimension.
Definition BDSArray4D.hh:65
const BDSFieldValue & operator()(BDSFourVector< G4int > &pos)
Convenience accessor to operator().
Definition BDSArray4D.hh:76
BDSFieldValue defaultValue
Need to store a default value so it can be return by reference.
const G4int nY
Dimension.
const BDSFieldValue & operator()(const BDSFourVector< G4int > &pos) const
Convenience accessor to operator().
Definition BDSArray4D.hh:94
BDSFourVector< G4int > NXYZT() const
Access the number of elements in a given dimension.
Definition BDSArray4D.hh:66
virtual const BDSFieldValue & GetConst(G4int x, G4int y=0, G4int z=0, G4int t=0) const
Definition BDSArray4D.cc:46
const G4int nX
Dimension.
virtual std::ostream & Print(std::ostream &out) const
Definition BDSArray4D.cc:91
BDSArray4D()=delete
const G4int nT
Dimension.
G4int NY() const
Access the number of elements in a given dimension.
Definition BDSArray4D.hh:63
A simple templated four vector class.
const Type & y() const
Accessor by name.
const Type & z() const
Accessor by name.
const Type & x() const
Accessor by name.
const Type & t() const
Accessor by name.