Skip to content

Commit 42d06c0

Browse files
author
Itay
committed
Implement relativistic point detector tally
1 parent a64cc96 commit 42d06c0

38 files changed

+2211
-88
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "vendor/Catch2"]
1414
path = vendor/Catch2
1515
url = https://github.com/catchorg/Catch2.git
16+
[submodule "vendor/gsl-lite"]
17+
path = vendor/gsl-lite
18+
url = https://github.com/gsl-lite/gsl-lite.git

include/openmc/constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ enum class TallyResult { VALUE, SUM, SUM_SQ, SIZE };
290290

291291
enum class TallyType { VOLUME, MESH_SURFACE, SURFACE, PULSE_HEIGHT };
292292

293-
enum class TallyEstimator { ANALOG, TRACKLENGTH, COLLISION };
293+
enum class TallyEstimator { ANALOG, TRACKLENGTH, COLLISION, POINT };
294294

295295
enum class TallyEvent { SURFACE, LATTICE, KILL, SCATTER, ABSORB };
296296

include/openmc/distribution.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Distribution {
2323
public:
2424
virtual ~Distribution() = default;
2525
virtual double sample(uint64_t* seed) const = 0;
26-
26+
virtual double get_pdf(double x) const = 0;
2727
//! Return integral of distribution
2828
//! \return Integral of distribution
2929
virtual double integral() const { return 1.0; };
@@ -84,6 +84,10 @@ class Discrete : public Distribution {
8484
//! \param seed Pseudorandom number seed pointer
8585
//! \return Sampled value
8686
double sample(uint64_t* seed) const override;
87+
//! Calculate the probability density function (PDF) at a given value
88+
//! \param x The value at which to evaluate the PDF
89+
//! \return The value of the PDF at the given point
90+
double get_pdf(double x) const;
8791

8892
double integral() const override { return di_.integral(); };
8993

@@ -111,6 +115,7 @@ class Uniform : public Distribution {
111115
//! \param seed Pseudorandom number seed pointer
112116
//! \return Sampled value
113117
double sample(uint64_t* seed) const override;
118+
double get_pdf(double x) const;
114119

115120
double a() const { return a_; }
116121
double b() const { return b_; }
@@ -135,6 +140,7 @@ class PowerLaw : public Distribution {
135140
//! \param seed Pseudorandom number seed pointer
136141
//! \return Sampled value
137142
double sample(uint64_t* seed) const override;
143+
double get_pdf(double x) const;
138144

139145
double a() const { return std::pow(offset_, ninv_); }
140146
double b() const { return std::pow(offset_ + span_, ninv_); }
@@ -160,6 +166,7 @@ class Maxwell : public Distribution {
160166
//! \param seed Pseudorandom number seed pointer
161167
//! \return Sampled value
162168
double sample(uint64_t* seed) const override;
169+
double get_pdf(double x) const;
163170

164171
double theta() const { return theta_; }
165172

@@ -180,6 +187,7 @@ class Watt : public Distribution {
180187
//! \param seed Pseudorandom number seed pointer
181188
//! \return Sampled value
182189
double sample(uint64_t* seed) const override;
190+
double get_pdf(double x) const;
183191

184192
double a() const { return a_; }
185193
double b() const { return b_; }
@@ -204,6 +212,7 @@ class Normal : public Distribution {
204212
//! \param seed Pseudorandom number seed pointer
205213
//! \return Sampled value
206214
double sample(uint64_t* seed) const override;
215+
double get_pdf(double x) const;
207216

208217
double mean_value() const { return mean_value_; }
209218
double std_dev() const { return std_dev_; }
@@ -227,8 +236,10 @@ class Tabular : public Distribution {
227236
//! \param seed Pseudorandom number seed pointer
228237
//! \return Sampled value
229238
double sample(uint64_t* seed) const override;
239+
double get_pdf(double x) const;
230240

231-
// properties
241+
// double get_pdf_value(double x,uint64_t* seed) const;
242+
// properties
232243
vector<double>& x() { return x_; }
233244
const vector<double>& x() const { return x_; }
234245
const vector<double>& p() const { return p_; }
@@ -263,6 +274,7 @@ class Equiprobable : public Distribution {
263274
//! \param seed Pseudorandom number seed pointer
264275
//! \return Sampled value
265276
double sample(uint64_t* seed) const override;
277+
double get_pdf(double x) const;
266278

267279
const vector<double>& x() const { return x_; }
268280

@@ -282,6 +294,7 @@ class Mixture : public Distribution {
282294
//! \param seed Pseudorandom number seed pointer
283295
//! \return Sampled value
284296
double sample(uint64_t* seed) const override;
297+
double get_pdf(double x) const;
285298

286299
double integral() const override { return integral_; }
287300

include/openmc/distribution_angle.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ class AngleDistribution {
2525
//! \param[inout] seed pseudorandom number seed pointer
2626
//! \return Cosine of the angle in the range [-1,1]
2727
double sample(double E, uint64_t* seed) const;
28-
28+
double get_pdf(double E, double mu, uint64_t* seed) const;
2929
//! Determine whether angle distribution is empty
3030
//! \return Whether distribution is empty
3131
bool empty() const { return energy_.empty(); }
32+
double get_energy(int num) { return energy_[num]; }
3233

3334
private:
3435
vector<double> energy_;

include/openmc/hdf5_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void write_int(hid_t group_id, int ndim, const hsize_t* dims, const char* name,
114114
void write_llong(hid_t group_id, int ndim, const hsize_t* dims,
115115
const char* name, const long long* buffer, bool indep);
116116
void write_string(hid_t group_id, int ndim, const hsize_t* dims, size_t slen,
117-
const char* name, char const* buffer, bool indep);
117+
const char* name, const char* buffer, bool indep);
118118
void write_tally_results(
119119
hid_t group_id, hsize_t n_filter, hsize_t n_score, const double* results);
120120
} // extern "C"

include/openmc/particle.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ class Particle : public ParticleData {
3434

3535
Particle() = default;
3636

37-
//==========================================================================
38-
// Methods
39-
4037
double speed() const;
4138

4239
//! create a secondary particle
4340
//
41+
//
42+
double getMass() const;
43+
//
44+
//
4445
//! stores the current phase space attributes of the particle in the
4546
//! secondary bank and increments the number of sites in the secondary bank.
4647
//! \param wgt Weight of the secondary particle
@@ -63,7 +64,9 @@ class Particle : public ParticleData {
6364
//! simply as a secondary particle.
6465
//! \param src Source site data
6566
void from_source(const SourceSite* src);
66-
67+
void initialize_ghost_particle(Particle& p, Direction u, double E);
68+
void initialize_ghost_particle_from_source(
69+
const SourceSite* src, Direction u_new);
6770
// Coarse-grained particle events
6871
void event_calculate_xs();
6972
void event_advance();

include/openmc/particle_data.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct SourceSite {
5454
int parent_nuclide {-1};
5555
int64_t parent_id;
5656
int64_t progeny_id;
57+
int source_index;
58+
bool ext {true}; //!< Is this source site external?
5759
};
5860

5961
//! State of a particle used for particle track files
@@ -488,7 +490,9 @@ class ParticleData : public GeometryState {
488490
int event_nuclide_;
489491
int event_mt_;
490492
int delayed_group_ {0};
493+
int event_index_mt_;
491494
int parent_nuclide_ {-1};
495+
Direction v_t_;
492496

493497
int n_bank_ {0};
494498
double bank_second_E_ {0.0};
@@ -622,7 +626,10 @@ class ParticleData : public GeometryState {
622626
const int& event_nuclide() const { return event_nuclide_; }
623627
int& event_mt() { return event_mt_; } // MT number of collision
624628
const int& event_mt() const { return event_mt_; }
629+
int& event_index_mt() { return event_index_mt_; }
625630
int& delayed_group() { return delayed_group_; } // delayed group
631+
Position& v_t() { return v_t_; }
632+
const Position& v_t() const { return v_t_; }
626633
const int& parent_nuclide() const { return parent_nuclide_; }
627634
int& parent_nuclide() { return parent_nuclide_; } // Parent nuclide
628635

include/openmc/physics.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ Direction sample_cxs_target_velocity(
9090
void sample_fission_neutron(
9191
int i_nuclide, const Reaction& rx, SourceSite* site, Particle& p);
9292

93+
void score_fission_neutron(int i_tally, int i_nuclide, const Reaction& rx,
94+
SourceSite* site, Particle& p, std::vector<double>& mu_cm,
95+
std::vector<double>& Js, std::vector<Particle>& ghost_particles,
96+
std::vector<double>& pdfs_lab);
97+
9398
//! handles all reactions with a single secondary neutron (other than fission),
9499
//! i.e. level scattering, (n,np), (n,na), etc.
95100
void inelastic_scatter(const Nuclide& nuc, const Reaction& rx, Particle& p);

include/openmc/reaction_product.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
#include "openmc/endf.h"
1212
#include "openmc/memory.h" // for unique_ptr
1313
#include "openmc/particle.h"
14+
#include "openmc/tallies/filter.h"
15+
#include "openmc/tallies/tally.h"
1416
#include "openmc/vector.h" // for vector
15-
1617
namespace openmc {
1718

1819
//==============================================================================
@@ -48,7 +49,10 @@ class ReactionProduct {
4849
//! \param[out] mu Outgoing cosine with respect to current direction
4950
//! \param[inout] seed Pseudorandom seed pointer
5051
void sample(double E_in, double& E_out, double& mu, uint64_t* seed) const;
51-
52+
void get_pdf(int i_tally, double E_in, double& E_out, uint64_t* seed,
53+
Particle& p, std::vector<double>& mu_cm, std::vector<double>& Js,
54+
std::vector<Particle>& ghost_particles,
55+
std::vector<double>& pdfs_lab) const;
5256
ParticleType particle_; //!< Particle type
5357
EmissionMode emission_mode_; //!< Emission mode
5458
double decay_rate_; //!< Decay rate (for delayed neutron precursors) in [1/s]

include/openmc/secondary_correlated.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "openmc/angle_energy.h"
1111
#include "openmc/distribution.h"
1212
#include "openmc/endf.h"
13+
#include "openmc/particle.h"
1314
#include "openmc/vector.h"
1415

1516
namespace openmc {
@@ -40,6 +41,10 @@ class CorrelatedAngleEnergy : public AngleEnergy {
4041
//! \param[inout] seed Pseudorandom seed pointer
4142
void sample(
4243
double E_in, double& E_out, double& mu, uint64_t* seed) const override;
44+
void get_pdf(double det_pos[4], double E_in, double& E_out, uint64_t* seed,
45+
Particle& p, std::vector<double>& mu_cm, std::vector<double>& Js,
46+
std::vector<Particle>& ghost_particles,
47+
std::vector<double>& pdfs_lab) const;
4348

4449
// energy property
4550
vector<double>& energy() { return energy_; }

0 commit comments

Comments
 (0)