openPMD_raytrace_API  0.1.0
ray.hh
1 #ifndef RAY_CLASS_HH
2 #define RAY_CLASS_HH
3 
4 #include <cmath>
5 #include <ostream>
6 
7 namespace raytracing {
8 constexpr double V2W = 3.956034e-07; // m^2/
9 // enum particleStatus_t : int { kDead = 0, kAlive = 1 };
10 
20 typedef int particleStatus_t;
21 constexpr int kDead = 0;
22 constexpr int kAlive = 1;
23 
39 class Ray {
40 public:
41 #define DIM_INIT \
42  { 0, 0, 0 }
43 #define PHASEDIM_INIT \
44  { 0, 0, 0, 0 }
45 
46  static const size_t DIM = 3;
47  static const size_t X = 0;
48  static const size_t Y = 1;
49  static const size_t Z = 2;
50  static const size_t PHASEDIM = DIM + 1;
51  static const size_t PHASE = 3;
52 
53 private:
54  float _position[DIM] = DIM_INIT;
55  float _direction[DIM] = DIM_INIT;
56  float _polarization[DIM] = DIM_INIT; // for non-photons
57  float _sPolarization[PHASEDIM] = PHASEDIM_INIT;
58  float _pPolarization[PHASEDIM] = PHASEDIM_INIT;
59  float _wavelength = 0;
60  float _time = 0;
61  float _weight = 1;
62  unsigned long long int _id = 0;
63  // particleStatus_t _status;
64  particleStatus_t _status = kAlive;
65 
66 public:
67  // Ray(){};
68 
71 
74  float x() const { return _position[X]; };
75  float y() const { return _position[Y]; };
76  float z() const { return _position[Z]; };
77  void get_position(float* xx, float* yy, float* zz) const {
78  (*xx) = x();
79  (*yy) = y();
80  (*zz) = z();
81  }
82  void get_position(double* xx, double* yy, double* zz) const {
83  (*xx) = x();
84  (*yy) = y();
85  (*zz) = z();
86  }
88  void get_position(float& xx, float& yy, float& zz) const {
89  xx = x();
90  yy = y();
91  zz = z();
92  }
94 
97  float dx() const { return _direction[X]; };
98  float dy() const { return _direction[Y]; };
99  float dz() const { return _direction[Z]; };
100  void get_direction(float* x, float* y, float* z, double scale) const {
101  *x = dx() * scale;
102  *y = dy() * scale;
103  *z = dz() * scale;
104  }
105  void get_direction(double* x, double* y, double* z, double scale) const {
106  *x = dx() * scale;
107  *y = dy() * scale;
108  *z = dz() * scale;
109  }
111 
114  float sx() const { return _polarization[X]; };
115  float sy() const { return _polarization[Y]; };
116  float sz() const { return _polarization[Z]; };
117  void get_polarization(float* x, float* y, float* z) const {
118  *x = sx();
119  *y = sy();
120  *z = sz();
121  }
122  void get_polarization(double* x, double* y, double* z) const {
123  *x = sx();
124  *y = sy();
125  *z = sz();
126  }
128 
131  float sPolAx() const { return _sPolarization[X]; };
132  float sPolAy() const { return _sPolarization[Y]; };
133  float sPolAz() const { return _sPolarization[Z]; };
134  float sPolPh() const { return _sPolarization[PHASE]; };
135  void get_sPolarizationAmplitude(float* x, float* y, float* z) const {
136  *x = sPolAx();
137  *y = sPolAy();
138  *z = sPolAz();
139  }
140  void get_sPolarization(float* x, float* y, float* z, float* phase) const {
141  get_sPolarizationAmplitude(x,y,z);
142  *phase = sPolPh();
143  }
144 
147  float pPolAx() const { return _pPolarization[X]; };
148  float pPolAy() const { return _pPolarization[Y]; };
149  float pPolAz() const { return _pPolarization[Z]; };
150  float pPolPh() const { return _pPolarization[PHASE]; };
151  void get_pPolarizationAmplitude(float* x, float* y, float* z) const {
152  *x = pPolAx();
153  *y = pPolAy();
154  *z = pPolAz();
155  }
156 
157  void get_pPolarization(float* x, float* y, float* z, float* phase) const {
158  get_pPolarizationAmplitude(x,y,z);
159  *phase = pPolPh();
160  }
161 
163 
167  float get_wavelength() const { return _wavelength; };
169  float get_time() const { return _time; };
170  float get_weight() const { return _weight; };
171  unsigned long long int get_id(void) const { return _id; };
175  inline particleStatus_t get_status(void) const { return _status; };
176 
179 
182 
184  void set_position(double x, double y, double z, double scale = 1) {
185  _position[X] = x * scale;
186  _position[Y] = y * scale;
187  _position[Z] = z * scale;
188  }
189 
191  void set_direction(double x, double y, double z, double scale = 1) {
192  _direction[X] = x * scale;
193  _direction[Y] = y * scale;
194  _direction[Z] = z * scale;
195  }
196 
198  void set_velocity(double x, double y, double z) {
199  double abs_v = sqrt(x * x + y * y + z * z);
200  set_direction(x, y, z, 1. / abs_v);
201  }
202 
204  void set_polarization(double x, double y, double z, double scale = 1) {
205  _polarization[X] = x * scale;
206  _polarization[Y] = y * scale;
207  _polarization[Z] = z * scale;
208  }
210  void set_sPolarization(double x, double y, double z, double phase, double scale = 1){
211  _sPolarization[X] = x * scale;
212  _sPolarization[Y] = y * scale;
213  _sPolarization[Z] = z * scale;
214  _sPolarization[PHASE] = phase;
215  };
217  void set_pPolarization(double x, double y, double z, double phase, double scale = 1){
218  _pPolarization[X] = x * scale;
219  _pPolarization[Y] = y * scale;
220  _pPolarization[Z] = z * scale;
221  _pPolarization[PHASE] = phase;
222  };
224  void set_wavelength(double w) { _wavelength = w; };
226  void set_time(double t) { _time = t; };
228  void set_weight(double w) { _weight = w; };
229  void set_id(unsigned long long int idv) { _id = idv; };
230  void set_status(particleStatus_t s) { _status = s; };
231 
233 public:
234  friend std::ostream& operator<<(std::ostream& os, const Ray& ray);
235 };
236 
237 #ifdef DD
238 
242 class photon : public Ray {};
243 
247 class neutron : public Ray {};
248 
249 #endif
250 
251 
252 class mcstas_neutron : public Ray {
253 public:
254  void set_position(double x, double y, double z){
255  Ray::set_position(x, y, z);
256  };
257  void set_velocity(double x, double y, double z){
258  double abs_v = sqrt(x * x + y * y + z * z);
259  set_direction(x, y, z, 1. / abs_v);
260  set_wavelength(V2W/abs_v);
261  }
262  void get_velocity(float *x, float *y, float* z){
263  double abs_v = V2W/get_wavelength();
264  get_direction(x, y, z, abs_v);
265  }
266 };
267 
268 } // namespace raytracing
269 
270 #endif
271 
272 
273 
274 
275 
void set_wavelength(double w)
set wavelength
Definition: ray.hh:224
void set_polarization(double x, double y, double z, double scale=1)
scale and set polarization for non-photons
Definition: ray.hh:204
void set_weight(double w)
set weight
Definition: ray.hh:228
int particleStatus_t
Definition: ray.hh:20
Generic ray, containing all the ray information being stored by the API into the openPMD file...
Definition: ray.hh:39
void set_direction(double x, double y, double z, double scale=1)
scale and set the direction
Definition: ray.hh:191
constexpr int kAlive
alive ray
Definition: ray.hh:22
defines the maximum number of rays that can be stored in memory before dumping to file ...
Definition: openPMD_io.hh:10
constexpr int kDead
particleStatus_t: dead ray
Definition: ray.hh:21
void get_position(float &xx, float &yy, float &zz) const
Definition: ray.hh:88
void set_sPolarization(double x, double y, double z, double phase, double scale=1)
scale and set s-polarization for photons
Definition: ray.hh:210
void set_pPolarization(double x, double y, double z, double phase, double scale=1)
scale and set p-polarization for photons
Definition: ray.hh:217
void set_velocity(double x, double y, double z)
scale and set the direction from the velocity
Definition: ray.hh:198
void set_time(double t)
set time
Definition: ray.hh:226
void set_position(double x, double y, double z, double scale=1)
scale and set the position
Definition: ray.hh:184
particleStatus_t get_status(void) const
return the particle status
Definition: ray.hh:175