Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulse height tally for photons #2452

Merged
merged 82 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
974a720
pulse-height tally implementation v2.0
Apr 3, 2023
dd18f12
bugfixes
Apr 3, 2023
199e23b
description of the score pulse-height
Apr 3, 2023
38b7f70
type in score dic
Apr 3, 2023
89820f2
remove blank line
Apr 3, 2023
c676ad7
Clang Format
Apr 14, 2023
eeb8a49
Clang format
Apr 14, 2023
82f7b90
clang
Apr 14, 2023
11a7ed2
clang format - final
Apr 14, 2023
7c2142e
clang
Apr 14, 2023
3ce4b9c
adding global variable pulse_height_cells
Apr 27, 2023
7cdbada
changing the value in the pht_storage at index
Apr 27, 2023
7c9c991
calling the right index of the pht_storage
Apr 27, 2023
01e3506
small changes
Apr 27, 2023
a746d37
Merge branch 'develop' into pulse-height-2
Apr 30, 2023
158c3af
update
Apr 30, 2023
d32174e
addressing issue #2508
May 1, 2023
09de63d
missing break statement in tally.cpp
May 1, 2023
e401990
revert last changes
May 2, 2023
78bd621
Merge branch 'develop' into pulse-height-2
May 2, 2023
deb4196
small change comment
May 2, 2023
1712d5c
p.alive in process_advance_particle_events
May 3, 2023
7090c5c
redo last change
May 3, 2023
7c7c0a4
undo last change
May 3, 2023
2626347
Merge branch 'pulse-height-2' of https://github.com/cfichtlscherer/op…
May 3, 2023
fcebe5c
run again with sort surf bank
May 4, 2023
74a1640
added regression test
May 4, 2023
795145a
reset pht storage for event based simulations
May 4, 2023
7516002
remove sorting surface source
May 5, 2023
efc476f
Update docs/source/usersguide/tallies.rst
cfichtlscherer May 25, 2023
6873cc4
Update include/openmc/particle_data.h
cfichtlscherer May 25, 2023
91f561a
Update include/openmc/particle_data.h
cfichtlscherer May 25, 2023
c34aa0c
Update src/particle.cpp
cfichtlscherer May 25, 2023
32714aa
Update src/particle_data.cpp
cfichtlscherer May 25, 2023
31e47b1
Update src/tallies/tally.cpp
cfichtlscherer May 25, 2023
1e0365f
description tallies.cpp
May 25, 2023
1d69270
clang
May 25, 2023
9274af0
description particle.cpp
May 25, 2023
f42d316
easyier check if cell index in pulse_height_cells
May 25, 2023
1dcb51e
clang
May 25, 2023
6d4cfee
Update src/tallies/tally.cpp
cfichtlscherer May 25, 2023
27692b5
missing semicolon
May 25, 2023
538a06e
include container_util
May 25, 2023
d7423fb
missing if
May 25, 2023
d1a61fa
clang
May 25, 2023
62f8c58
description tallies
May 25, 2023
8ff651e
update pulse-height test
May 25, 2023
a727c4c
checking only cell / energy filter
May 25, 2023
36172d3
clang
May 25, 2023
464e504
adding pytest pht test
May 25, 2023
8e260d9
include cellborn filter
May 25, 2023
ac2e6e2
update pulse-height score function
May 25, 2023
4b9f2e1
clang
May 25, 2023
11ec770
update scoring function
May 25, 2023
dbf6aa4
clang
May 25, 2023
7967e8f
type
May 25, 2023
57f1425
box -> sphere pht test
May 25, 2023
6b7bcf0
update
Jun 2, 2023
d689d91
clang
Jun 2, 2023
8fab57a
remove estimator
cfichtlscherer Jun 8, 2023
fb547a9
remove estimator py / small changes
cfichtlscherer Jun 8, 2023
16cbc2a
when score check if cell in pht_cells
cfichtlscherer Jun 8, 2023
7c0804a
clang
cfichtlscherer Jun 8, 2023
48d2277
iterate over all cells in all cell filters
cfichtlscherer Jun 11, 2023
cfd219a
update test
cfichtlscherer Jun 11, 2023
7aa7c4f
comment photon transport / clang
cfichtlscherer Jun 20, 2023
969ef10
clang update
cfichtlscherer Jun 20, 2023
63db229
update test
cfichtlscherer Jun 20, 2023
a630e89
cell filter check
cfichtlscherer Jun 20, 2023
0bf609d
asking birth cell earlier
cfichtlscherer Jun 20, 2023
e8a412d
clang
cfichtlscherer Jun 20, 2023
71b0e17
clang
cfichtlscherer Jun 20, 2023
3eb998f
clang
cfichtlscherer Jun 21, 2023
ff0f6db
clang
cfichtlscherer Jun 21, 2023
e4b574d
clang old version
cfichtlscherer Jun 21, 2023
6f7d8ad
clange
cfichtlscherer Jun 23, 2023
01a03a6
test clang
cfichtlscherer Jun 24, 2023
c796fa1
changes filt->type() in tally
cfichtlscherer Jul 7, 2023
b10a32e
clang
cfichtlscherer Jul 7, 2023
b43ebae
dynamic_cast to FilterType
cfichtlscherer Jul 8, 2023
24d8cb5
type
cfichtlscherer Jul 8, 2023
ebee016
type 2
cfichtlscherer Jul 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/usersguide/tallies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ The following tables show all valid scores:
| |particle. This corresponds to MT=444 produced by |
| |NJOY's HEATR module. |
+----------------------+---------------------------------------------------+
|pulse-height |The energy deposited by an entire photon's history |
| |(including its progeny). Units are eV per source |
| |particle. Note that this score can only be combined|
| |with a cell filter and an energy filter. |
+----------------------+---------------------------------------------------+

.. _usersguide_tally_normalization:

Expand Down
5 changes: 3 additions & 2 deletions include/openmc/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ enum class MgxsType {

enum class TallyResult { VALUE, SUM, SUM_SQ };

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

enum class TallyEstimator { ANALOG, TRACKLENGTH, COLLISION };

Expand Down Expand Up @@ -306,7 +306,8 @@ enum TallyScore {
SCORE_INVERSE_VELOCITY = -13, // flux-weighted inverse velocity
SCORE_FISS_Q_PROMPT = -14, // prompt fission Q-value
SCORE_FISS_Q_RECOV = -15, // recoverable fission Q-value
SCORE_DECAY_RATE = -16 // delayed neutron precursor decay rate
SCORE_DECAY_RATE = -16, // delayed neutron precursor decay rate
SCORE_PULSE_HEIGHT = -17 // pulse-height
};

// Global tally parameters
Expand Down
4 changes: 4 additions & 0 deletions include/openmc/particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class Particle : public ParticleData {
void event_revive_from_secondary();
void event_death();

//! pulse-height recording
void pht_collision_energy();
void pht_secondary_particles();

//! Cross a surface and handle boundary conditions
void cross_surface();

Expand Down
3 changes: 3 additions & 0 deletions include/openmc/particle_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ class ParticleData {

vector<NuBank> nu_bank_; // bank of most recently fissioned particles

vector<double> pht_storage_; // interim pulse-height results

// Global tally accumulators
double keff_tally_absorption_ {0.0};
double keff_tally_collision_ {0.0};
Expand Down Expand Up @@ -443,6 +445,7 @@ class ParticleData {
decltype(tracks_)& tracks() { return tracks_; }
decltype(nu_bank_)& nu_bank() { return nu_bank_; }
NuBank& nu_bank(int i) { return nu_bank_[i]; }
vector<double>& pht_storage() { return pht_storage_; }

double& keff_tally_absorption() { return keff_tally_absorption_; }
double& keff_tally_collision() { return keff_tally_collision_; }
Expand Down
4 changes: 4 additions & 0 deletions include/openmc/tallies/tally.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ class Tally {
// We need to have quick access to some filters. The following gives indices
// for various filters that could be in the tally or C_NONE if they are not
// present.
int energy_filter_ {C_NONE};
int energyout_filter_ {C_NONE};
int delayedgroup_filter_ {C_NONE};
int cell_filter_ {C_NONE};

vector<Trigger> triggers_;

Expand Down Expand Up @@ -155,6 +157,8 @@ extern vector<int> active_tracklength_tallies;
extern vector<int> active_collision_tallies;
extern vector<int> active_meshsurf_tallies;
extern vector<int> active_surface_tallies;
extern vector<int> active_pulse_height_tallies;
extern vector<int> pulse_height_cells;
} // namespace model

namespace simulation {
Expand Down
9 changes: 8 additions & 1 deletion include/openmc/tallies/tally_scoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,16 @@ void score_tracklength_tally(Particle& p, double distance);
//! Score surface or mesh-surface tallies for particle currents.
//
//! \param p The particle being tracked
//! \param tallies A vector of tallies to score to
//! \param tallies A vector of the indices of the tallies to score to
void score_surface_tally(Particle& p, const vector<int>& tallies);

//! Score the pulse-height tally
//! This is triggered at the end of every particle history
//
//! \param p The particle being tracked
//! \param tallies A vector of the indices of the tallies to score to
void score_pulse_height_tally(Particle& p, const vector<int>& tallies);

} // namespace openmc

#endif // OPENMC_TALLIES_TALLY_SCORING_H
4 changes: 2 additions & 2 deletions openmc/lib/tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@
-5: 'absorption', -6: 'fission', -7: 'nu-fission', -8: 'kappa-fission',
-9: 'current', -10: 'events', -11: 'delayed-nu-fission',
-12: 'prompt-nu-fission', -13: 'inverse-velocity', -14: 'fission-q-prompt',
-15: 'fission-q-recoverable', -16: 'decay-rate'
-15: 'fission-q-recoverable', -16: 'decay-rate', -17: 'pulse-height'
}
_ESTIMATORS = {
0: 'analog', 1: 'tracklength', 2: 'collision'
}
_TALLY_TYPES = {
0: 'volume', 1: 'mesh-surface', 2: 'surface'
0: 'volume', 1: 'mesh-surface', 2: 'surface', 3: 'pulse-height'
}


Expand Down
1 change: 1 addition & 0 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ const std::unordered_map<int, const char*> score_names = {
{SCORE_FISS_Q_PROMPT, "Prompt fission power"},
{SCORE_FISS_Q_RECOV, "Recoverable fission power"},
{SCORE_CURRENT, "Current"},
{SCORE_PULSE_HEIGHT, "pulse-height"},
};

//! Create an ASCII output file showing all tally results.
Expand Down
68 changes: 67 additions & 1 deletion src/particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "openmc/message_passing.h"
#include "openmc/mgxs_interface.h"
#include "openmc/nuclide.h"
#include "openmc/particle_data.h"
#include "openmc/photon.h"
#include "openmc/physics.h"
#include "openmc/physics_mg.h"
Expand Down Expand Up @@ -286,6 +287,11 @@ void Particle::event_collide()
}
}

if (!model::active_pulse_height_tallies.empty() &&
type() == ParticleType::photon) {
pht_collision_energy();
}

// Reset banked weight during collision
n_bank() = 0;
n_bank_second() = 0;
Expand Down Expand Up @@ -350,6 +356,25 @@ void Particle::event_revive_from_secondary()
secondary_bank().pop_back();
n_event() = 0;

// Subtract secondary particle energy from interim pulse-height results
if (!model::active_pulse_height_tallies.empty() &&
cfichtlscherer marked this conversation as resolved.
Show resolved Hide resolved
this->type() == ParticleType::photon) {
// Since the birth cell of the particle has not been set we
// have to determine it before the energy of the secondary particle can be
// removed from the pulse-height of this cell.
if (coord(n_coord() - 1).cell == C_NONE) {
if (!exhaustive_find_cell(*this)) {
mark_as_lost("Could not find the cell containing particle " +
std::to_string(id()));
return;
}
// Set birth cell attribute
if (cell_born() == C_NONE)
cell_born() = coord(n_coord() - 1).cell;
}
pht_secondary_particles();
}

// Enter new particle in particle track file
if (write_track())
add_particle_track(*this);
Expand Down Expand Up @@ -383,6 +408,10 @@ void Particle::event_death()
keff_tally_tracklength() = 0.0;
keff_tally_leakage() = 0.0;

if (!model::active_pulse_height_tallies.empty()) {
score_pulse_height_tally(*this, model::active_pulse_height_tallies);
}

// Record the number of progeny created by this particle.
// This data will be used to efficiently sort the fission bank.
if (settings::run_mode == RunMode::EIGENVALUE) {
Expand All @@ -391,6 +420,41 @@ void Particle::event_death()
}
}

void Particle::pht_collision_energy()
{
// Adds the energy particles lose in a collision to the pulse-height

// determine index of cell in pulse_height_cells
auto it = std::find(model::pulse_height_cells.begin(),
model::pulse_height_cells.end(), coord(n_coord() - 1).cell);

if (it != model::pulse_height_cells.end()) {
int index = std::distance(model::pulse_height_cells.begin(), it);
pht_storage()[index] += E_last() - E();

// If the energy of the particle is below the cutoff, it will not be sampled
// so its energy is added to the pulse-height in the cell
int photon = static_cast<int>(ParticleType::photon);
if (E() < settings::energy_cutoff[photon]) {
pht_storage()[index] += E();
}
}
}

void Particle::pht_secondary_particles()
{
// Removes the energy of secondary produced particles from the pulse-height

// determine index of cell in pulse_height_cells
auto it = std::find(model::pulse_height_cells.begin(),
model::pulse_height_cells.end(), cell_born());

if (it != model::pulse_height_cells.end()) {
int index = std::distance(model::pulse_height_cells.begin(), it);
pht_storage()[index] -= E();
}
}

void Particle::cross_surface()
{
int i_surface = std::abs(surface());
Expand Down Expand Up @@ -433,7 +497,9 @@ void Particle::cross_surface()
#ifdef DAGMC
// in DAGMC, we know what the next cell should be
if (surf->geom_type_ == GeometryType::DAG) {
int32_t i_cell = next_cell(i_surface, cell_last(n_coord() - 1), lowest_coord().universe) - 1;
int32_t i_cell =
next_cell(i_surface, cell_last(n_coord() - 1), lowest_coord().universe) -
1;
// save material and temp
material_last() = material();
sqrtkT_last() = sqrtkT();
Expand Down
5 changes: 5 additions & 0 deletions src/particle_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ ParticleData::ParticleData()
// Create microscopic cross section caches
neutron_xs_.resize(data::nuclides.size());
photon_xs_.resize(data::elements.size());

// Creates the pulse-height storage for the particle
if (!model::pulse_height_cells.empty()) {
pht_storage_.resize(model::pulse_height_cells.size(), 0.0);
}
}

TrackState ParticleData::get_track_state() const
Expand Down
1 change: 1 addition & 0 deletions src/reaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ std::unordered_map<int, std::string> REACTION_NAME_MAP {
{SCORE_INVERSE_VELOCITY, "inverse-velocity"},
{SCORE_FISS_Q_PROMPT, "fission-q-prompt"},
{SCORE_FISS_Q_RECOV, "fission-q-recoverable"},
{SCORE_PULSE_HEIGHT, "pulse-height"},
// Normal ENDF-based reactions
{TOTAL_XS, "(n,total)"},
{ELASTIC, "(n,elastic)"},
Expand Down
3 changes: 3 additions & 0 deletions src/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ void initialize_history(Particle& p, int64_t index_source)
// Reset weight window ratio
p.ww_factor() = 0.0;

// Reset pulse_height_storage
std::fill(p.pht_storage().begin(), p.pht_storage().end(), 0);

// set random number seed
int64_t particle_seed =
(simulation::total_gen + overall_generation() - 1) * settings::n_particles +
Expand Down
Loading