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

Random Ray Transport #2823

Merged
merged 188 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 112 commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
d76033a
first commit. File layout, classes, source region init.
jtramm Jun 12, 2023
c2fa6aa
added source update function
jtramm Jun 12, 2023
dc30912
added high level control function
jtramm Jun 12, 2023
31609b0
added cell normalization routine
jtramm Jun 12, 2023
0e2dcec
added add source to flux function
jtramm Jun 12, 2023
7db4a7d
added k-eff update function
jtramm Jun 12, 2023
a782fa4
basic iteration code is in.
jtramm Jun 12, 2023
785c4d6
adding ray methods.
jtramm Jun 12, 2023
2ccc838
adding more ray methods.
jtramm Jun 12, 2023
168ca04
whitespace fixes
jtramm Jun 12, 2023
2c45008
working on debugging the compile. All basic pieces in place though, s…
jtramm Jun 12, 2023
003c646
continued debugging
jtramm Jun 13, 2023
f232980
Compile-time bug fixes and refactoring to use particle_data accessors.
jtramm Jun 13, 2023
04e7e12
assed basic printout. Results look decent.
jtramm Jun 13, 2023
d66cdbb
removed tallying (besides basic things like k-eff)
jtramm Jun 13, 2023
588f1ce
added clean timing/result output function.
jtramm Jun 13, 2023
442153c
added the basics of clean tally-based output
jtramm Jun 13, 2023
baf1f5a
fixed first tally init issue that was causing seg fault. Getting 0 va…
jtramm Jun 13, 2023
2c2770b
ensured that all active tallies are used, not just analog
jtramm Jun 13, 2023
e785b26
generic tally solution working. A little slow
jtramm Jun 14, 2023
9566890
added energy integrated version. About 2x fast, but still too slow. W…
jtramm Jun 14, 2023
7646594
added tally mapper, but now there is a problem where what if we did n…
jtramm Jun 14, 2023
7b46663
Added ability for tally conversion to run multiple times if not all F…
jtramm Jun 14, 2023
f28d655
minor cleanup of tally task conversion code
jtramm Jun 14, 2023
2b43008
moved tallying and tally conversion functions into separate file
jtramm Jun 14, 2023
5548628
added some comments
jtramm Jun 14, 2023
7503eb6
moved initialization of tally task array to where other cell-wise arr…
jtramm Jun 14, 2023
1eb5eec
parallelized flux/volume zeroing routines. Streamlined instability an…
jtramm Jun 14, 2023
958a73a
added more output metrics
jtramm Jun 14, 2023
ec78527
changed parallelization scheme for normalization routines. Removed ta…
jtramm Jun 14, 2023
eeda6ab
first commit. File layout, classes, source region init.
jtramm Jun 12, 2023
6a6d100
added source update function
jtramm Jun 12, 2023
34c35db
added high level control function
jtramm Jun 12, 2023
e19e3e3
added cell normalization routine
jtramm Jun 12, 2023
68af51e
added add source to flux function
jtramm Jun 12, 2023
7673afb
added k-eff update function
jtramm Jun 12, 2023
cfab02a
basic iteration code is in.
jtramm Jun 12, 2023
f40f807
adding ray methods.
jtramm Jun 12, 2023
c373560
adding more ray methods.
jtramm Jun 12, 2023
ebee0ef
whitespace fixes
jtramm Jun 12, 2023
25f1fcc
working on debugging the compile. All basic pieces in place though, s…
jtramm Jun 12, 2023
aa9b732
continued debugging
jtramm Jun 13, 2023
a3ed5dd
Compile-time bug fixes and refactoring to use particle_data accessors.
jtramm Jun 13, 2023
e9708d6
assed basic printout. Results look decent.
jtramm Jun 13, 2023
8d22e78
removed tallying (besides basic things like k-eff)
jtramm Jun 13, 2023
247e8df
added clean timing/result output function.
jtramm Jun 13, 2023
9610a2d
added the basics of clean tally-based output
jtramm Jun 13, 2023
84cfdaa
fixed first tally init issue that was causing seg fault. Getting 0 va…
jtramm Jun 13, 2023
d74781e
ensured that all active tallies are used, not just analog
jtramm Jun 13, 2023
68bee19
generic tally solution working. A little slow
jtramm Jun 14, 2023
a3c9804
added energy integrated version. About 2x fast, but still too slow. W…
jtramm Jun 14, 2023
0c5200b
added tally mapper, but now there is a problem where what if we did n…
jtramm Jun 14, 2023
4b60bd5
Added ability for tally conversion to run multiple times if not all F…
jtramm Jun 14, 2023
64a6d6e
minor cleanup of tally task conversion code
jtramm Jun 14, 2023
b1167d9
moved tallying and tally conversion functions into separate file
jtramm Jun 14, 2023
6566cdc
added some comments
jtramm Jun 14, 2023
738910a
moved initialization of tally task array to where other cell-wise arr…
jtramm Jun 14, 2023
1d9254e
parallelized flux/volume zeroing routines. Streamlined instability an…
jtramm Jun 14, 2023
d998d06
added more output metrics
jtramm Jun 14, 2023
58d516b
changed parallelization scheme for normalization routines. Removed ta…
jtramm Jun 14, 2023
7ffb30d
allowed for different cell instances to be given different material t…
jtramm Jun 16, 2023
5ff2be8
fixed fast forward issue
jtramm Oct 3, 2023
69abd98
updated to use zero temp and angle indices when accessing XS data. Ad…
jtramm Oct 3, 2023
2cb971c
used OpenMC init sim
jtramm Nov 21, 2023
504cb54
using init and finalize batch
jtramm Nov 21, 2023
a6a00b3
using generations now as well
jtramm Nov 21, 2023
ecc0087
using integrated keff tally
jtramm Nov 21, 2023
f363645
commented out unneeded init statements
jtramm Nov 21, 2023
c5fbb4c
set weight to 1.0
jtramm Nov 21, 2023
56e84f7
Switched random ray enum check to use a new solver type variable inst…
jtramm Nov 21, 2023
bbd325d
removed duplicate timer
jtramm Nov 21, 2023
2854d51
figured out bug -- was due to actual bug in openmc where it is revert…
jtramm Nov 22, 2023
8e91d50
input validation is well along -- maybe complete?
jtramm Nov 22, 2023
94705ef
added fixed source checking
jtramm Nov 22, 2023
54f39de
refactor from Ray to RandomRay
jtramm Nov 28, 2023
b3ea0f6
added source validation
jtramm Nov 29, 2023
2d90cd4
refactored to use settings/globals directly rather than passing as ar…
jtramm Nov 29, 2023
872ff56
adding comments, and switched to setting to previous source instead o…
jtramm Nov 29, 2023
39cdd66
moved validation code to end of file
jtramm Nov 29, 2023
43df38a
partial addition of docs and python interface
jtramm Dec 1, 2023
6cf75a6
finished up python interface?
jtramm Dec 1, 2023
dad86a0
fixed issue with int vs real in python interface, and added check for…
jtramm Dec 1, 2023
f7e0400
partial domain replication. Need to not print double, and need to red…
jtramm Dec 1, 2023
6eb99bd
fixed issue with tallies in mpi mode. Issue was solely with the cell …
jtramm Dec 4, 2023
b4fffb8
added more comments
jtramm Dec 4, 2023
ed34ab2
added reduction of intersection counts
jtramm Dec 4, 2023
fe4194d
added timer for source reductions, and added warning about slow reduc…
jtramm Dec 4, 2023
bec2b82
removed extra comment
jtramm Dec 4, 2023
1fbd373
added lots of comments
jtramm Dec 5, 2023
027653b
fixed comment issue
jtramm Dec 5, 2023
1789d41
removed assert statements and replaced with errors
jtramm Dec 5, 2023
fefe9aa
added vtk plotter
jtramm Dec 5, 2023
3bf3134
added FSR and material plots, but FSR plot is weird.
jtramm Dec 5, 2023
811c399
FSRs appear much better as floats rather than modulused ints, for som…
jtramm Dec 5, 2023
95ebeed
simplified plotting routine a bit
jtramm Dec 5, 2023
b3a38e0
parallelized plotter
jtramm Dec 5, 2023
00f0e4c
using plot.xml inputs for plots
jtramm Dec 5, 2023
4939ceb
plotter is using xml input fname
jtramm Dec 5, 2023
bce3b70
added nice output before plotting, and enforcement of acceptable plot…
jtramm Dec 5, 2023
8704ee7
only plot if there is a plotting xml file
jtramm Dec 5, 2023
98f0696
added storage of accumulated final flux and plotting at the end
jtramm Dec 5, 2023
3254e3b
added first try at tolerant testing harness
jtramm Dec 6, 2023
a7d90df
tweaks to tolerant testing. Report k-eff simulation for k-eff combine…
jtramm Dec 6, 2023
54d0a71
added random ray pincell example
jtramm Dec 6, 2023
8a49e5d
removed unneeded headers
jtramm Dec 6, 2023
1419f39
added endianness flipping function, ability to output multiple plots …
jtramm Dec 6, 2023
dd90d63
adjusted comment
jtramm Dec 6, 2023
1818989
fixed merge issue
jtramm Jan 8, 2024
cf0f69b
improved pincell example
jtramm Jan 8, 2024
2248ec4
ran git clang-format develop
jtramm Jan 8, 2024
8216a6c
Added a loop before plotting to change filenames first, so the plot s…
jtramm Jan 8, 2024
735fcfd
ran git clang-format develop
jtramm Jan 8, 2024
33c333b
updated test to use RectangularPrism instead of rectangular_prism`
jtramm Jan 10, 2024
0b0dc42
Revert "fixed fast forward issue"
jtramm Jan 10, 2024
12f24f0
ran clang-format on settings.h
jtramm Jan 10, 2024
69ae4f4
added back in comment
jtramm Jan 10, 2024
99a34cc
removed comments/debugging code
jtramm Jan 10, 2024
a07c534
ran git clang-format develop
jtramm Jan 10, 2024
e0b62a7
Update src/random_ray/iteration.cpp
jtramm Jan 10, 2024
63857aa
incorporation of @gridley review comments
jtramm Jan 11, 2024
57dad69
Merge branch 'random_ray_merge' of github.com:jtramm/openmc into rand…
jtramm Jan 11, 2024
d3cfd4b
Merge branch 'develop' of github.com:openmc-dev/openmc into random_ra…
jtramm Jan 17, 2024
ead8cfa
added random_ray.rst methods file and updated index
jtramm Jan 17, 2024
561d8fa
fixed over/underbars
jtramm Jan 25, 2024
bb24326
added random ray user guide
jtramm Jan 26, 2024
a060d4e
added lots more documentation to theory section
jtramm Jan 26, 2024
a42e0eb
added compressed image files to random ray documentation
jtramm Jan 26, 2024
53d3a5e
continued work on docs
jtramm Jan 28, 2024
74d7ac7
continued work on docs
jtramm Jan 28, 2024
2893ecf
continued updated to docs
jtramm Jan 28, 2024
872bcfe
continued work on docs
jtramm Jan 28, 2024
32c65d8
updating random ray docs
jtramm Jan 29, 2024
66387b4
More random ray docs. Fixed equation notation, added more references,…
jtramm Jan 29, 2024
2ec33be
Added random_ray_source option to IndependentSource to flag source as…
jtramm Feb 6, 2024
5c63a31
ran git clang-format HEAD~1
jtramm Feb 6, 2024
4a0500f
Refactored random ray source indicator to use particle type rather th…
jtramm Feb 6, 2024
4727569
ran git clang-format HEAD~1
jtramm Feb 6, 2024
f20bc1e
removed the rest of old random_ray_source source field.
jtramm Feb 6, 2024
98b65d1
removed unneeded lines throughout
jtramm Feb 6, 2024
916b2bd
updated docs to account for new random ray source specification inter…
jtramm Feb 6, 2024
524f2b4
added accessors for cell material/temperature fields to abstract logi…
jtramm Feb 7, 2024
f122ef0
ran git clang-format HEAD~1
jtramm Feb 7, 2024
4a92297
Merge branch 'develop' into random_ray_merge
jtramm Feb 12, 2024
3821eb2
fixed bug in Cell::sqrtkT accessor return type
jtramm Feb 12, 2024
00d07dc
incorporation of review comments
jtramm Feb 13, 2024
14faa19
refactor into classes mostly complete. Just some cleanup remaining.
jtramm Feb 13, 2024
5555dd9
refactor into classes complete and working (still needs cleanup)
jtramm Feb 14, 2024
28942b9
refactor of random ray filenames
jtramm Feb 14, 2024
383bd31
code cleanup, comments, formatting
jtramm Feb 14, 2024
e3bc76a
ran git clang-format develop
jtramm Feb 14, 2024
e5cdc3e
changed include guard names
jtramm Feb 14, 2024
eb66a04
ran git clang-format develop
jtramm Feb 14, 2024
b715f03
added comment for TolerantPyAPITestHarness class
jtramm Feb 15, 2024
b4ad777
enabled tracklength and collision tallies. Fixed vacuum BC bug where …
jtramm Feb 15, 2024
2d7eec3
updated documents and example to remove the requirement of analog tal…
jtramm Feb 15, 2024
ef0fdca
Remove docs for random_ray_source option that was removed from python…
jtramm Feb 16, 2024
30d0d1d
added TODO item on inheriting from GeometryState instead of Particle.
jtramm Feb 16, 2024
7de305b
Changed random ray interface on python side.
jtramm Feb 16, 2024
007a935
refactor C++ random ray interface to use random_ray object
jtramm Feb 16, 2024
15e6bec
updated docs, examples, and tests to use new interface. Also added va…
jtramm Feb 16, 2024
591d0e2
updated docs
jtramm Feb 16, 2024
1d8722f
ran git clang-format develop
jtramm Feb 16, 2024
a58be8c
removed random ray particle type from C++ and python
jtramm Feb 16, 2024
3d2eab9
ran git clang-format develop
jtramm Feb 16, 2024
982272c
fixed bug with outputting empty random ray dictionary
jtramm Feb 16, 2024
43b842d
simplified docs example slightly
jtramm Feb 16, 2024
4819aaa
incorporation of @gridley docs review comments
jtramm Feb 18, 2024
c9c691d
Line spacing in random ray documentation
paulromano Mar 5, 2024
03333d2
Small changes in user's guide random ray section
paulromano Mar 5, 2024
e8ff8f5
Edits in random ray methods docs
paulromano Mar 5, 2024
0d94bbe
Small changes and updates
paulromano Mar 5, 2024
66b4a3d
Fix XML roundtrip of settings.random_ray
paulromano Mar 5, 2024
06d4343
incorporation of @promano review comments pt 1
jtramm Mar 6, 2024
3c13dd2
changed \vec to \mathbf in random ray docs
jtramm Mar 6, 2024
433b000
incorporation of @promano review comments pt 2
jtramm Mar 6, 2024
3f585ef
changed dV to d\mathbf{r}
jtramm Mar 6, 2024
cb813ce
incorporation of @promano review comments pt3
jtramm Mar 6, 2024
fa0b844
incorporation of @promano review comments pt 4
jtramm Mar 6, 2024
45e3bc9
ran git clang-format develop
jtramm Mar 6, 2024
de456e0
updated random ray test expected results due to bug fix with ray term…
jtramm Mar 6, 2024
936d703
removed unneeded vector header
jtramm Mar 6, 2024
d426075
Small fix in random_ray.rst
paulromano Mar 22, 2024
efe6353
marked random_ray_tally as const, and removed unneeded prototype
jtramm Mar 29, 2024
581229e
updated docs comment
jtramm Mar 29, 2024
d60c3c0
incorporation of @yardasol review comments
jtramm Apr 3, 2024
93bb5b2
Merge branch 'develop' into random_ray_merge
jtramm Apr 4, 2024
c8ffddb
Merge branch 'develop' into pr/jtramm/2823
paulromano Apr 18, 2024
f3dec7d
Small fixes in docstring
paulromano Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ list(APPEND libopenmc_SOURCES
src/progress_bar.cpp
src/random_dist.cpp
src/random_lcg.cpp
src/random_ray/iteration.cpp
src/random_ray/random_ray.cpp
src/random_ray/source_region.cpp
src/random_ray/tally_convert.cpp
src/random_ray/vtk_plot.cpp
src/reaction.cpp
src/reaction_product.cpp
src/scattdata.cpp
Expand Down
28 changes: 28 additions & 0 deletions docs/source/io_formats/settings.rst
gridley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,24 @@ or sub-elements and can be set to either "false" or "true".

.. note:: This element is not used in the multi-group :ref:`energy_mode`.

-----------------------
``<random_ray_distance_active>`` Element
-----------------------

The ``<random_ray_distance_active>`` element is used to set the active distance
each ray will travel in random ray mode.

*Default*: None

-----------------------
``<random_ray_distance_inactive>`` Element
-----------------------

The ``<random_ray_distance_inactive>`` element is used to set the inactive
distance (dead zone length) each ray will travel in random ray mode.

*Default*: None

----------------------------------
``<resonance_scattering>`` Element
----------------------------------
Expand Down Expand Up @@ -475,6 +493,16 @@ pseudo-random number generator.

.. _source_element:

--------------------
``<solver_type>`` Element
--------------------

The ``solver_type`` element is used to select the transport method used by the
simulation. This element has no attributes or sub-elements and can be set to
"monte carlo" or "random ray".

*Default*: monte carlo

--------------------
``<source>`` Element
--------------------
Expand Down
211 changes: 211 additions & 0 deletions examples/pincell_random_ray/build_xml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
from math import log10

import numpy as np

import openmc
import openmc.mgxs

###############################################################################
# Create multigroup data

# Instantiate the energy group data
ebins = [1e-5, 0.0635, 10.0, 1.0e2, 1.0e3, 0.5e6, 1.0e6, 20.0e6]
groups = openmc.mgxs.EnergyGroups(group_edges=ebins)

# Instantiate the 7-group (C5G7) cross section data
uo2_xsdata = openmc.XSdata('UO2', groups)
uo2_xsdata.order = 0
uo2_xsdata.set_total(
[0.1779492, 0.3298048, 0.4803882, 0.5543674, 0.3118013, 0.3951678,
0.5644058])
uo2_xsdata.set_absorption([8.0248E-03, 3.7174E-03, 2.6769E-02, 9.6236E-02,
3.0020E-02, 1.1126E-01, 2.8278E-01])
scatter_matrix = np.array(
[[[0.1275370, 0.0423780, 0.0000094, 0.0000000, 0.0000000, 0.0000000, 0.0000000],
[0.0000000, 0.3244560, 0.0016314, 0.0000000, 0.0000000, 0.0000000, 0.0000000],
[0.0000000, 0.0000000, 0.4509400, 0.0026792, 0.0000000, 0.0000000, 0.0000000],
[0.0000000, 0.0000000, 0.0000000, 0.4525650, 0.0055664, 0.0000000, 0.0000000],
[0.0000000, 0.0000000, 0.0000000, 0.0001253, 0.2714010, 0.0102550, 0.0000000],
[0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0012968, 0.2658020, 0.0168090],
[0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0085458, 0.2730800]]])
scatter_matrix = np.rollaxis(scatter_matrix, 0, 3)
uo2_xsdata.set_scatter_matrix(scatter_matrix)
uo2_xsdata.set_fission([7.21206E-03, 8.19301E-04, 6.45320E-03,
1.85648E-02, 1.78084E-02, 8.30348E-02,
2.16004E-01])
uo2_xsdata.set_nu_fission([2.005998E-02, 2.027303E-03, 1.570599E-02,
4.518301E-02, 4.334208E-02, 2.020901E-01,
5.257105E-01])
uo2_xsdata.set_chi([5.8791E-01, 4.1176E-01, 3.3906E-04, 1.1761E-07, 0.0000E+00,
0.0000E+00, 0.0000E+00])

h2o_xsdata = openmc.XSdata('LWTR', groups)
h2o_xsdata.order = 0
h2o_xsdata.set_total([0.15920605, 0.412969593, 0.59030986, 0.58435,
0.718, 1.2544497, 2.650379])
h2o_xsdata.set_absorption([6.0105E-04, 1.5793E-05, 3.3716E-04,
1.9406E-03, 5.7416E-03, 1.5001E-02,
3.7239E-02])
scatter_matrix = np.array(
[[[0.0444777, 0.1134000, 0.0007235, 0.0000037, 0.0000001, 0.0000000, 0.0000000],
[0.0000000, 0.2823340, 0.1299400, 0.0006234, 0.0000480, 0.0000074, 0.0000010],
[0.0000000, 0.0000000, 0.3452560, 0.2245700, 0.0169990, 0.0026443, 0.0005034],
[0.0000000, 0.0000000, 0.0000000, 0.0910284, 0.4155100, 0.0637320, 0.0121390],
[0.0000000, 0.0000000, 0.0000000, 0.0000714, 0.1391380, 0.5118200, 0.0612290],
[0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0022157, 0.6999130, 0.5373200],
[0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.1324400, 2.4807000]]])
scatter_matrix = np.rollaxis(scatter_matrix, 0, 3)
h2o_xsdata.set_scatter_matrix(scatter_matrix)

mg_cross_sections_file = openmc.MGXSLibrary(groups)
mg_cross_sections_file.add_xsdatas([uo2_xsdata, h2o_xsdata])
mg_cross_sections_file.export_to_hdf5()

###############################################################################
# Create materials for the problem

# Instantiate some Macroscopic Data
uo2_data = openmc.Macroscopic('UO2')
h2o_data = openmc.Macroscopic('LWTR')

# Instantiate some Materials and register the appropriate Macroscopic objects
uo2 = openmc.Material(name='UO2 fuel')
uo2.set_density('macro', 1.0)
uo2.add_macroscopic(uo2_data)

water = openmc.Material(name='Water')
water.set_density('macro', 1.0)
water.add_macroscopic(h2o_data)

# Instantiate a Materials collection and export to XML
materials_file = openmc.Materials([uo2, water])
materials_file.cross_sections = "mgxs.h5"
materials_file.export_to_xml()

###############################################################################
# Define problem geometry

# The geometry we will define a simplified pincell with fuel radius 0.54 cm
# surrounded by moderator (same as in the multigroup example).
# In random ray, we typically want several radial regions and azimuthal
# sectors in both the fuel and moderator areas of the pincell. This is
# due to the flat source approximation requiring that source regions are
# small compared to the typical mean free path of a neutron. Below we
# sudivide the basic pincell into 8 aziumthal sectors (pizza slices) and
# 5 concentric rings in both the fuel and moderator.

# TODO: When available in OpenMC, use cylindrical lattice instead to
# simplify definition and improve runtime performance.

pincell_base = openmc.Universe()

# These are the subdivided radii (creating 5 concentric regions in the
# fuel and moderator)
ring_radii = [0.241, 0.341, 0.418, 0.482, 0.54, 0.572, 0.612, 0.694, 0.786]
fills = [uo2, uo2, uo2, uo2, uo2, water, water, water, water, water]

# We then create cells representing the bounded rings, with special
# treatment for both the innermost and outermost cells
cells = []
for r in range(10):
cell = []
if r == 0:
outer_bound = openmc.ZCylinder(r=ring_radii[r])
cell = openmc.Cell(fill=fills[r], region=-outer_bound)
elif r == 9:
inner_bound = openmc.ZCylinder(r=ring_radii[r-1])
cell = openmc.Cell(fill=fills[r], region=+inner_bound)
else:
inner_bound = openmc.ZCylinder(r=ring_radii[r-1])
outer_bound = openmc.ZCylinder(r=ring_radii[r])
cell = openmc.Cell(fill=fills[r], region=+inner_bound & -outer_bound)
pincell_base.add_cell(cell)

# We then generate 8 planes to bound 8 azimuthal sectors
azimuthal_planes = []
for i in range(8):
angle = 2 * i * openmc.pi / 8
normal_vector = (-openmc.sin(angle), openmc.cos(angle), 0)
azimuthal_planes.append(openmc.Plane(a=normal_vector[0], b=normal_vector[1], c=normal_vector[2], d=0))

# Create a cell for each azimuthal sector using the pincell base class
azimuthal_cells = []
for i in range(8):
azimuthal_cell = openmc.Cell(name=f'azimuthal_cell_{i}')
azimuthal_cell.fill = pincell_base
azimuthal_cell.region = +azimuthal_planes[i] & -azimuthal_planes[(i+1) % 8]
azimuthal_cells.append(azimuthal_cell)

# Create the (subdivided) geometry with the azimuthal universes
pincell = openmc.Universe(cells=azimuthal_cells)

# Create a region represented as the inside of a rectangular prism
pitch = 1.26
box = openmc.model.RectangularPrism(pitch, pitch, boundary_type='reflective')
shimwell marked this conversation as resolved.
Show resolved Hide resolved
pincell_bounded = openmc.Cell(fill=pincell, region=-box, name='pincell')

# Create a geometry (specifying merge surfaces option to remove
# all the redundant cylinder/plane surfaces) and export to XML
geometry = openmc.Geometry([pincell_bounded], merge_surfaces=True)
geometry.export_to_xml()

###############################################################################
# Define problem settings

# Instantiate a Settings object, set all runtime parameters, and export to XML
settings = openmc.Settings()
settings.energy_mode = "multi-group"
settings.batches = 600
settings.inactive = 300
settings.particles = 50
settings.solver_type = 'random ray'
settings.random_ray_distance_inactive = 40.0
settings.random_ray_distance_active = 400.0

# Create an initial uniform spatial source distribution for sampling rays.
# Note that this must be uniform in space and angle.
lower_left = (-pitch/2, -pitch/2, -1)
upper_right = (pitch/2, pitch/2, 1)
uniform_dist = openmc.stats.Box(lower_left, upper_right, only_fissionable=False)
settings.source = openmc.IndependentSource(space=uniform_dist)
settings.export_to_xml()

###############################################################################
# Define tallies

# Create a mesh that will be used for tallying
mesh = openmc.RegularMesh()
mesh.dimension = (2, 2)
mesh.lower_left = (-pitch/2, -pitch/2)
mesh.upper_right = (pitch/2, pitch/2)

# Create a mesh filter that can be used in a tally
mesh_filter = openmc.MeshFilter(mesh)

# Let's also create a filter to measure each group
# indepdendently
energy_filter = openmc.EnergyFilter(ebins)

# Now use the mesh filter in a tally and indicate what scores are desired
tally = openmc.Tally(name="Mesh and Energy tally")
tally.filters = [mesh_filter, energy_filter]
tally.scores = ['flux', 'fission', 'nu-fission']
tally.estimator = 'analog'

# Instantiate a Tallies collection and export to XML
tallies = openmc.Tallies([tally])
tallies.export_to_xml()

###############################################################################
# Exporting to OpenMC plots.xml file
###############################################################################

plot = openmc.Plot()
plot.origin = [0, 0, 0]
plot.width = [pitch, pitch, pitch]
plot.pixels = [1000, 1000, 1]
plot.type = 'voxel'

# Instantiate a Plots collection and export to XML
plot_file = openmc.Plots([plot])
plot_file.export_to_xml()
1 change: 1 addition & 0 deletions include/openmc/boundary_condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace openmc {

// Forward declare some types used in function arguments.
class Particle;
class RandomRay;
class Surface;

//==============================================================================
Expand Down
2 changes: 2 additions & 0 deletions include/openmc/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ enum class RunMode {
VOLUME
};

enum class SolverType { MONTE_CARLO, RANDOM_RAY };
gridley marked this conversation as resolved.
Show resolved Hide resolved

//==============================================================================
// Geometry Constants

Expand Down
3 changes: 2 additions & 1 deletion include/openmc/mgxs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Mgxs {
int num_delayed_groups; // number of delayed neutron groups
vector<XsData> xs; // Cross section data
// MGXS Incoming Flux Angular grid information
bool is_isotropic; // used to skip search for angle indices if isotropic
int n_pol;
int n_azi;
vector<double> polar;
Expand Down Expand Up @@ -85,6 +84,8 @@ class Mgxs {
std::string name; // name of dataset, e.g., UO2
double awr; // atomic weight ratio
bool fissionable; // Is this fissionable
bool is_isotropic {
jtramm marked this conversation as resolved.
Show resolved Hide resolved
true}; // used to skip search for angle indices if isotropic
jtramm marked this conversation as resolved.
Show resolved Hide resolved

Mgxs() = default;

Expand Down
2 changes: 0 additions & 2 deletions include/openmc/openmp_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ inline int thread_num()

//==============================================================================
//! An object used to prevent concurrent access to a piece of data.
//
//! This type meets the C++ "Lockable" requirements.
//==============================================================================

class OpenMPMutex {
Expand Down
6 changes: 5 additions & 1 deletion include/openmc/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ void print_runtime();
//! Display results for global tallies including k-effective estimators
void print_results();

//! Display timing results and global statistics for random ray simulations
void print_results_random_ray(
uint64_t total_geometric_intersections, double avg_miss_rate);

void write_tallies();

} // namespace openmc
Expand All @@ -80,4 +84,4 @@ struct formatter<std::array<T, 2>> {
}
};

} // namespace fmt
} // namespace fmt
1 change: 1 addition & 0 deletions include/openmc/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class PlottableInterface {
virtual void print_info() const = 0;

const std::string& path_plot() const { return path_plot_; }
std::string& path_plot() { return path_plot_; }
jtramm marked this conversation as resolved.
Show resolved Hide resolved
int id() const { return id_; }
int level() const { return level_; }

Expand Down
30 changes: 30 additions & 0 deletions include/openmc/random_ray/iteration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef OPENMC_RANDOM_RAY_ITERATION_H
#define OPENMC_RANDOM_RAY_ITERATION_H

#include "openmc/random_ray/random_ray.h"
#include "openmc/random_ray/source_region.h"

namespace openmc {

void update_neutron_source(double k_eff);
double compute_k_eff(double k_eff_old);
void normalize_scalar_flux_and_volumes();
int64_t add_source_to_scalar_flux();
double calculate_miss_rate();
int openmc_run_random_ray();
void instability_check(int64_t n_hits, double k_eff, double& avg_miss_rate);
void validate_random_ray_inputs();
void all_reduce_random_ray_batch_results(bool mapped_all_tallies);

template<typename T>
void parallel_fill(std::vector<T>& arr, T value)
{
#pragma omp parallel for schedule(static)
for (int i = 0; i < arr.size(); i++) {
arr[i] = value;
}
}

} // namespace openmc

#endif // OPENMC_RANDOM_RAY_ITERATION_H