Skip to content

Commit 5204829

Browse files
authored
Merge branch 'develop' into Sensitivity-Analysis
2 parents c52ca39 + f9dca9a commit 5204829

32 files changed

Lines changed: 543 additions & 143 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ list(APPEND libopenmc_SOURCES
426426
src/tallies/filter_surface.cpp
427427
src/tallies/filter_time.cpp
428428
src/tallies/filter_universe.cpp
429+
src/tallies/filter_weight.cpp
429430
src/tallies/filter_zernike.cpp
430431
src/tallies/tally.cpp
431432
src/tallies/tally_scoring.cpp
71.9 KB
Loading

docs/source/pythonapi/base.rst

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,11 @@ Constructing Tallies
144144
openmc.SpatialLegendreFilter
145145
openmc.SphericalHarmonicsFilter
146146
openmc.TimeFilter
147+
openmc.WeightFilter
147148
openmc.ZernikeFilter
148149
openmc.ZernikeRadialFilter
149150
openmc.ParentNuclideFilter
150151
openmc.ParticleFilter
151-
openmc.RegularMesh
152-
openmc.RectilinearMesh
153-
openmc.CylindricalMesh
154-
openmc.SphericalMesh
155-
openmc.UnstructuredMesh
156152
openmc.MeshMaterialVolumes
157153
openmc.Trigger
158154
openmc.TallyDerivative
@@ -161,6 +157,20 @@ Constructing Tallies
161157
openmc.Tally
162158
openmc.Tallies
163159

160+
Meshes
161+
------
162+
163+
.. autosummary::
164+
:toctree: generated
165+
:nosignatures:
166+
:template: myclassinherit.rst
167+
168+
openmc.RegularMesh
169+
openmc.RectilinearMesh
170+
openmc.CylindricalMesh
171+
openmc.SphericalMesh
172+
openmc.UnstructuredMesh
173+
164174
Geometry Plotting
165175
-----------------
166176

docs/source/pythonapi/capi.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Classes
9393
SensitivityTally
9494
UniverseFilter
9595
UnstructuredMesh
96+
WeightFilter
9697
WeightWindows
9798
ZernikeFilter
9899
ZernikeRadialFilter

docs/source/usersguide/processing.rst

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,82 @@ from a statepoint file, the ``openmc.statepoint`` module can be used. An
9191
`example notebook`_ demontrates how to analyze and plot source information.
9292

9393
.. _example notebook: https://nbviewer.jupyter.org/github/openmc-dev/openmc-notebooks/blob/main/post-processing.ipynb
94+
95+
------------------------
96+
VTK Mesh File Generation
97+
------------------------
98+
99+
VTK files of OpenMC meshes can be created using the
100+
:meth:`openmc.Mesh.write_data_to_vtk` method. Data can be applied to the
101+
elements of the resulting mesh from mesh filter objects. This data can be
102+
provided either as a flat array or, in the case of structured meshes
103+
(:class:`~openmc.RegularMesh`, :class:`~openmc.RectilinearMesh`,
104+
:class:`~openmc.CylindricalMesh`, or :class:`SphericalMesh`), the data can be
105+
shaped with dimensions that match the dimensions of the mesh itself.
106+
107+
108+
.. image:: ../_images/sphere-mesh-vtk.png
109+
:width: 400px
110+
:align: center
111+
:alt: OpenMC spherical mesh exported to VTK
112+
113+
114+
For all mesh types, if a flat data array is provided to the mesh, it is expected
115+
that the data is ordered in the same ordering as the :attr:`openmc.Mesh.indices`
116+
for that mesh object. When providing data directly from a tally, as shown below,
117+
a flat array for a given dataset can be passed directly to this method.
118+
119+
::
120+
121+
# create model above
122+
123+
# create a mesh tally
124+
mesh = openmc.RegularMesh()
125+
mesh.dimension = [10, 20, 30]
126+
mesh.lower_left = [-5, -10, -15]
127+
mesh.upper_right = [5, 10, 15]
128+
mesh_filter = openmc.MeshFilter(mesh)
129+
tally = openmc.Tally()
130+
tally.filters = [mesh_filter]
131+
tally.scores = ['flux']
132+
133+
model.tallies = [tally]
134+
model.run(apply_tally_results=True)
135+
136+
# provide the data as-is to the method
137+
mesh.write_data_to_vtk('flux.vtk', {'flux-mean': tally.mean})
138+
139+
The :class:`~openmc.Tally` object also provides a way to expand the dimensions
140+
of the mesh filter into a meaningful form where indexing the mesh filter
141+
dimensions results in intuitive slicing of structured meshes by setting
142+
``expand_dims=True`` when using :meth:`openmc.Tally.get_reshaped_data`. This
143+
reshaping does cause flat indexing of the data to change, however. As noted
144+
above, provided datasets are allowed to be shaped so long as such datasets have
145+
shapes that match the mesh dimensions. The ability to pass datasets in this way
146+
is useful when additional filters are applied to a tally. The example below
147+
demonstrates such a case for tally with both a :class:`~openmc.MeshFilter` and
148+
:class:`~openmc.EnergyFilter` applied.
149+
150+
::
151+
152+
# create model above
153+
154+
# create a mesh tally with energy filter
155+
mesh = openmc.RegularMesh()
156+
mesh.dimension = [10, 20, 30]
157+
mesh.lower_left = [-5, -10, -15]
158+
mesh.upper_right = [5, 10, 15]
159+
mesh_filter = openmc.MeshFilter(mesh)
160+
energy_filter = openmc.EnergyFilter([0.0, 1.0, 20.0e6])
161+
tally = openmc.Tally()
162+
tally.filters = [mesh_filter, energy_filter]
163+
tally.scores = ['flux']
164+
165+
model.tallies = [tally]
166+
model.run(apply_tally_results=True)
167+
168+
# get the data with mesh dimensions expanded, squeeze out length-one dimensions (nuclides, scores)
169+
flux = tally.get_reshaped_data(expand_dims=True).squeeze() # shape: (10, 20, 30, 2)
170+
171+
# write the lowest energy group to a VTK file
172+
mesh.write_data_to_vtk('flux-group1.vtk', datasets={'flux-mean': flux[..., 0]})

include/openmc/photon.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class ElectronSubshell {
3333

3434
int index_subshell; //!< index in SUBSHELLS
3535
int threshold;
36-
double n_electrons;
3736
double binding_energy;
3837
vector<Transition> transitions;
3938
};
@@ -90,6 +89,11 @@ class PhotonInteraction {
9089
xt::xtensor<double, 1> binding_energy_;
9190
xt::xtensor<double, 1> electron_pdf_;
9291

92+
// Map subshells from Compton profile data obtained from Biggs et al,
93+
// "Hartree-Fock Compton profiles for the elements" to ENDF/B atomic
94+
// relaxation data
95+
xt::xtensor<int, 1> subshell_map_;
96+
9397
// Stopping power data
9498
double I_; // mean excitation energy
9599
xt::xtensor<int, 1> n_electrons_;

include/openmc/tallies/filter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum class FilterType {
4545
SURFACE,
4646
TIME,
4747
UNIVERSE,
48+
WEIGHT,
4849
ZERNIKE,
4950
ZERNIKE_RADIAL
5051
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef OPENMC_TALLIES_FILTER_WEIGHT_H
2+
#define OPENMC_TALLIES_FILTER_WEIGHT_H
3+
4+
#include <string>
5+
6+
#include "openmc/span.h"
7+
#include "openmc/tallies/filter.h"
8+
#include "openmc/vector.h"
9+
10+
namespace openmc {
11+
12+
//==============================================================================
13+
//! Bins the weights of the particles.
14+
//==============================================================================
15+
16+
class WeightFilter : public Filter {
17+
public:
18+
//----------------------------------------------------------------------------
19+
// Constructors, destructors
20+
21+
~WeightFilter() = default;
22+
23+
//----------------------------------------------------------------------------
24+
// Methods
25+
26+
std::string type_str() const override { return "weight"; }
27+
FilterType type() const override { return FilterType::WEIGHT; }
28+
29+
void from_xml(pugi::xml_node node) override;
30+
31+
void get_all_bins(const Particle& p, TallyEstimator estimator,
32+
FilterMatch& match) const override;
33+
34+
void to_statepoint(hid_t filter_group) const override;
35+
36+
std::string text_label(int bin) const override;
37+
38+
//----------------------------------------------------------------------------
39+
// Accessors
40+
41+
const vector<double>& bins() const { return bins_; }
42+
void set_bins(span<const double> bins);
43+
44+
protected:
45+
//----------------------------------------------------------------------------
46+
// Data members
47+
vector<double> bins_;
48+
};
49+
50+
} // namespace openmc
51+
#endif // OPENMC_TALLIES_FILTER_WEIGHT_H

openmc/deplete/d1s.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ def apply_time_correction(
141141
time_correction_factors : dict
142142
Time correction factors as returned by :func:`time_correction_factors`
143143
index : int, optional
144-
Index to use for the correction factors
144+
Index of the time of interest. If N timesteps are provided in
145+
:func:`time_correction_factors`, there are N + 1 times to select from.
146+
The default is -1 which corresponds to the final time.
145147
sum_nuclides : bool
146148
Whether to sum over the parent nuclides
147149

openmc/filter.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
'energyout', 'mu', 'musurface', 'polar', 'azimuthal', 'distribcell', 'delayedgroup',
2626
'energyfunction', 'cellfrom', 'materialfrom', 'legendre', 'spatiallegendre',
2727
'sphericalharmonics', 'zernike', 'zernikeradial', 'particle', 'cellinstance',
28-
'collision', 'time', 'importance', 'parentnuclide'
28+
'collision', 'time', 'importance', 'parentnuclide', 'weight'
2929
)
3030

3131
_CURRENT_NAMES = (
@@ -2518,3 +2518,26 @@ def get_pandas_dataframe(self, data_size, stride, **kwargs):
25182518
{self.short_name.lower(): filter_bins})])
25192519

25202520
return df
2521+
2522+
2523+
class WeightFilter(RealFilter):
2524+
"""Bins tally events based on the incoming particle weight.
2525+
2526+
Parameters
2527+
----------
2528+
Values : Iterable of float
2529+
A list or iterable of the weight boundaries, as float values.
2530+
filter_id : int
2531+
Unique identifier for the filter
2532+
2533+
Attributes
2534+
----------
2535+
id : int
2536+
Unique identifier for the filter
2537+
bins : numpy.ndarray
2538+
An array of integer values representing the weights by which to filter
2539+
num_bins : int
2540+
The number of filter bins
2541+
values : numpy.ndarray
2542+
Array of weight boundaries
2543+
"""

0 commit comments

Comments
 (0)