Skip to content

Commit 2343d27

Browse files
committed
implement ParticleRay class
1 parent 1578698 commit 2343d27

3 files changed

Lines changed: 63 additions & 5 deletions

File tree

include/openmc/particle_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class GeometryState {
484484
* Algorithms.” Annals of Nuclear Energy 113 (March 2018): 506–18.
485485
* https://doi.org/10.1016/j.anucene.2017.11.032.
486486
*/
487-
class ParticleData : public GeometryState {
487+
class ParticleData : virtual public GeometryState {
488488
private:
489489
//==========================================================================
490490
// Data members -- see public: below for descriptions

include/openmc/ray.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#ifndef OPENMC_RAY_H
22
#define OPENMC_RAY_H
33

4-
#include "openmc/particle_data.h"
4+
#include "openmc/particle.h"
55
#include "openmc/position.h"
66

77
namespace openmc {
88

99
// Base class that implements ray tracing logic, not necessarily through
1010
// defined regions of the geometry but also outside of it.
11-
class Ray : public GeometryState {
11+
class Ray : virtual public GeometryState {
1212

1313
public:
1414
// Initialize from location and direction
@@ -32,6 +32,8 @@ class Ray : public GeometryState {
3232
// Sets the dist_ variable
3333
void compute_distance();
3434

35+
virtual void update_distance();
36+
3537
protected:
3638
// Records how far the ray has traveled
3739
double traversal_distance_ {0.0};
@@ -46,5 +48,18 @@ class Ray : public GeometryState {
4648
unsigned event_counter_ {0};
4749
};
4850

51+
class ParticleRay : public Ray, public Particle {
52+
53+
public:
54+
// Sets the dist_ variable
55+
void update_distance() override;
56+
57+
protected:
58+
// Records how much time passed during travel
59+
double time_distance_ {0.0};
60+
// Records how much mean free paths the ray traveled
61+
double mfp_distance_ {0.0};
62+
};
63+
4964
} // namespace openmc
5065
#endif // OPENMC_RAY_H

src/ray.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "openmc/error.h"
44
#include "openmc/geometry.h"
5+
#include "openmc/material.h"
6+
#include "openmc/mgxs_interface.h"
57
#include "openmc/settings.h"
68

79
namespace openmc {
@@ -136,8 +138,8 @@ void Ray::trace()
136138
cross_lattice(*this, boundary(), settings::verbosity >= 10);
137139
}
138140

139-
// Record how far the ray has traveled
140-
traversal_distance_ += boundary().distance();
141+
update_distance();
142+
141143
inside_cell = neighbor_list_find_cell(*this, settings::verbosity >= 10);
142144

143145
// Call the specialized logic for this type of ray. Note that we do not
@@ -165,4 +167,45 @@ void Ray::trace()
165167
}
166168
}
167169

170+
void Ray::update_distance()
171+
{
172+
// Record how far the ray has traveled
173+
traversal_distance_ += boundary().distance();
174+
}
175+
176+
void ParticleRay::update_distance()
177+
{
178+
Ray::update_distance();
179+
180+
time_distance_ += speed() * boundary().distance();
181+
182+
// Calculate microscopic and macroscopic cross sections
183+
if (material() != MATERIAL_VOID) {
184+
if (settings::run_CE) {
185+
if (material() != material_last() || sqrtkT() != sqrtkT_last() ||
186+
density_mult() != density_mult_last()) {
187+
// If the material is the same as the last material and the
188+
// temperature hasn't changed, we don't need to lookup cross
189+
// sections again.
190+
model::materials[material()]->calculate_xs(*this);
191+
}
192+
} else {
193+
// Get the MG data; unlike the CE case above, we have to re-calculate
194+
// cross sections for every collision since the cross sections may
195+
// be angle-dependent
196+
data::mg.macro_xs_[material()].calculate_xs(*this);
197+
198+
// Update the particle's group while we know we are multi-group
199+
g_last() = g();
200+
}
201+
} else {
202+
macro_xs().total = 0.0;
203+
macro_xs().absorption = 0.0;
204+
macro_xs().fission = 0.0;
205+
macro_xs().nu_fission = 0.0;
206+
}
207+
208+
mfp_distance_ += macro_xs().total * boundary().distance();
209+
}
210+
168211
} // namespace openmc

0 commit comments

Comments
 (0)