Skip to content

Commit 139907c

Browse files
authored
Implement tally filter for filtering by reaction (#3809)
1 parent 153281a commit 139907c

24 files changed

Lines changed: 661 additions & 160 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ list(APPEND libopenmc_SOURCES
412412
src/tallies/filter_particle.cpp
413413
src/tallies/filter_particle_production.cpp
414414
src/tallies/filter_polar.cpp
415+
src/tallies/filter_reaction.cpp
415416
src/tallies/filter_sph_harm.cpp
416417
src/tallies/filter_sptl_legendre.cpp
417418
src/tallies/filter_surface.cpp

‎docs/source/pythonapi/base.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Constructing Tallies
149149
openmc.ZernikeRadialFilter
150150
openmc.ParentNuclideFilter
151151
openmc.ParticleFilter
152+
openmc.ReactionFilter
152153
openmc.MeshMaterialVolumes
153154
openmc.Trigger
154155
openmc.TallyDerivative

‎docs/source/pythonapi/capi.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ Classes
8282
Nuclide
8383
ParentNuclideFilter
8484
ParticleFilter
85+
ParticleProductionFilter
8586
PolarFilter
87+
ReactionFilter
8688
RectilinearMesh
8789
RegularMesh
8890
SpatialLegendreFilter

‎docs/source/usersguide/tallies.rst‎

Lines changed: 118 additions & 103 deletions
Large diffs are not rendered by default.

‎include/openmc/constants.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ enum ReactionType {
227227
N_XA = 207,
228228
HEATING = 301,
229229
DAMAGE_ENERGY = 444,
230+
PHOTON_TOTAL = 501,
230231
COHERENT = 502,
231232
INCOHERENT = 504,
232233
PAIR_PROD_ELEC = 515,

‎include/openmc/endf.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ bool is_disappearance(int MT);
3333
//! \return Whether corresponding reaction is an inelastic scattering reaction
3434
bool is_inelastic_scatter(int MT);
3535

36+
//! Determine whether an MT number matches a target MT, considering that the
37+
//! target may be a summation reaction.
38+
//! \param[in] event_mt MT number of the actual event
39+
//! \param[in] target_mt MT number to check against
40+
//! \return Whether event_mt is a component of target_mt (or equal to it)
41+
bool mt_matches(int event_mt, int target_mt);
42+
3643
//==============================================================================
3744
//! Abstract one-dimensional function
3845
//==============================================================================

‎include/openmc/reaction.h‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,21 @@ class Reaction {
7676
//! \return Name of the corresponding reaction
7777
std::string reaction_name(int mt);
7878

79-
//! Return reaction type (MT value) given a reaction name
79+
//! Return MT value for given a reaction name (including special tally MT
80+
//! values)
8081
//
8182
//! \param[in] name Reaction name
82-
//! \return Corresponding reaction type (MT value)
83-
int reaction_type(std::string name);
83+
//! \return Corresponding MT number or special tally score
84+
int reaction_tally_mt(std::string name);
85+
86+
//! Return ENDF MT number given a reaction name
87+
//
88+
//! Unlike reaction_tally_mt(), this function always returns a positive ENDF MT
89+
//! number and never a special negative tally score.
90+
//!
91+
//! \param[in] name Reaction name
92+
//! \return Corresponding ENDF MT number
93+
int reaction_mt(const std::string& name);
8494

8595
} // namespace openmc
8696

‎include/openmc/tallies/filter.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum class FilterType {
4141
PARTICLE,
4242
PARTICLE_PRODUCTION,
4343
POLAR,
44+
REACTION,
4445
SPHERICAL_HARMONICS,
4546
SPATIAL_LEGENDRE,
4647
SURFACE,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef OPENMC_TALLIES_FILTER_REACTION_H
2+
#define OPENMC_TALLIES_FILTER_REACTION_H
3+
4+
#include "openmc/span.h"
5+
#include "openmc/tallies/filter.h"
6+
#include "openmc/vector.h"
7+
8+
namespace openmc {
9+
10+
//==============================================================================
11+
//! Bins tally events based on the reaction type (MT number).
12+
//==============================================================================
13+
14+
class ReactionFilter : public Filter {
15+
public:
16+
//----------------------------------------------------------------------------
17+
// Constructors, destructors
18+
19+
~ReactionFilter() = default;
20+
21+
//----------------------------------------------------------------------------
22+
// Methods
23+
24+
std::string type_str() const override { return "reaction"; }
25+
FilterType type() const override { return FilterType::REACTION; }
26+
27+
void from_xml(pugi::xml_node node) override;
28+
29+
void get_all_bins(const Particle& p, TallyEstimator estimator,
30+
FilterMatch& match) const override;
31+
32+
void to_statepoint(hid_t filter_group) const override;
33+
34+
std::string text_label(int bin) const override;
35+
36+
//----------------------------------------------------------------------------
37+
// Accessors
38+
39+
const vector<int>& bins() const { return bins_; }
40+
void set_bins(span<const int> bins);
41+
42+
protected:
43+
//----------------------------------------------------------------------------
44+
// Data members
45+
46+
//! MT numbers to match
47+
vector<int> bins_;
48+
};
49+
50+
} // namespace openmc
51+
52+
#endif // OPENMC_TALLIES_FILTER_REACTION_H

‎openmc/data/reaction.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .kalbach_mann import KalbachMann
2222
from .laboratory import LaboratoryAngleEnergy
2323
from .nbody import NBodyPhaseSpace
24+
from .photon import _SUBSHELLS
2425
from .product import Product
2526
from .uncorrelated import UncorrelatedAngleEnergy
2627

@@ -54,6 +55,10 @@
5455
198: '(n,n3p)', 199: '(n,3n2pa)', 200: '(n,5n2p)', 203: '(n,Xp)',
5556
204: '(n,Xd)', 205: '(n,Xt)', 206: '(n,X3He)', 207: '(n,Xa)',
5657
301: 'heating', 444: 'damage-energy',
58+
501: 'photon-total', 502: 'coherent-scatter',
59+
504: 'incoherent-scatter', 515: 'pair-production-electron',
60+
516: 'pair-production', 517: 'pair-production-nuclear',
61+
522: 'photoelectric',
5762
649: '(n,pc)', 699: '(n,dc)', 749: '(n,tc)', 799: '(n,3Hec)',
5863
849: '(n,ac)', 891: '(n,2nc)', 901: 'heating-local'}
5964
REACTION_NAME.update({i: f'(n,n{i - 50})' for i in range(51, 91)})
@@ -63,9 +68,16 @@
6368
REACTION_NAME.update({i: f'(n,3He{i - 750})' for i in range(750, 799)})
6469
REACTION_NAME.update({i: f'(n,a{i - 800})' for i in range(800, 849)})
6570
REACTION_NAME.update({i: f'(n,2n{i - 875})' for i in range(875, 891)})
71+
REACTION_NAME.update(
72+
{534 + i: f'photoelectric-{shell}' for i, shell in enumerate(_SUBSHELLS[1:])}
73+
)
6674

6775
REACTION_MT = {name: mt for mt, name in REACTION_NAME.items()}
76+
REACTION_MT['total'] = 1
77+
REACTION_MT['elastic'] = 2
6878
REACTION_MT['fission'] = 18
79+
REACTION_MT['absorption'] = 27
80+
REACTION_MT['capture'] = 102
6981

7082
FISSION_MTS = (18, 19, 20, 21, 38)
7183

0 commit comments

Comments
 (0)