44Variance Reduction
55==================
66
7- Global variance reduction in OpenMC is accomplished by weight windowing
8- or source biasing techniques, the latter of which additionally provides a
9- local variance reduction capability. OpenMC is capable of generating weight
10- windows using either the MAGIC or FW-CADIS methods . Both techniques will
11- produce a ``weight_windows.h5 `` file that can be loaded and used later on. In
7+ Global and local variance reduction are possible in OpenMC through both weight
8+ windowing and source biasing techniques. OpenMC is capable of generating weight
9+ windows using either the MAGIC or FW-CADIS methods, the latter with an optional
10+ capability for local variance reduction . Both techniques will produce a
11+ ``weight_windows.h5 `` file that can be loaded and used later on. In
1212this section, we first break down the steps required to generate and apply
1313weight windows, then describe how source biasing may be applied.
1414
1515.. _ww_generator :
1616
17- ------------------------------------
18- Generating Weight Windows with MAGIC
19- ------------------------------------
17+ -------------------------------------------
18+ Generating Global Weight Windows with MAGIC
19+ -------------------------------------------
2020
2121As discussed in the :ref: `methods section <methods_variance_reduction >`, MAGIC
2222is an iterative method that uses flux tally information from a Monte Carlo
23- simulation to produce weight windows for a user-defined mesh. While generating
24- the weight windows, OpenMC is capable of applying the weight windows generated
25- from a previous batch while processing the next batch, allowing for progressive
26- improvement in the weight window quality across iterations.
23+ simulation to produce weight windows for a user-defined mesh with the objective
24+ of global variance reduction. While generating the weight windows, OpenMC is
25+ capable of applying the weight windows generated from a previous batch while
26+ processing the next batch, allowing for progressive improvement in the weight
27+ window quality across iterations.
2728
2829The typical way of generating weight windows is to define a mesh and then add an
2930:class: `openmc.WeightWindowGenerator ` object to an :attr: `openmc.Settings `
@@ -71,15 +72,20 @@ At the end of the simulation, a ``weight_windows.h5`` file will be saved to disk
7172for later use. Loading it in another subsequent simulation will be discussed in
7273the "Using Weight Windows" section below.
7374
74- ------------------------------------------------------
75- Generating Weight Windows with FW-CADIS and Random Ray
76- ------------------------------------------------------
75+ .. _usersguide_fw_cadis :
76+
77+ ----------------------------------------------------------------------
78+ Generating Global or Local Weight Windows with FW-CADIS and Random Ray
79+ ----------------------------------------------------------------------
7780
7881Weight window generation with FW-CADIS and random ray in OpenMC uses the same
79- exact strategy as with MAGIC. An :class: `openmc.WeightWindowGenerator ` object is
80- added to the :attr: `openmc.Settings ` object, and a ``weight_windows.h5 `` will be
81- generated at the end of the simulation. The only difference is that the code
82- must be run in random ray mode. A full description of how to enable and setup
82+ exact strategy as with MAGIC. Using FW-CADIS, however, also enables
83+ local variance reduction in fixed source problems through the :attr: `targets `
84+ attribute, which is described later in this section. To enable FW-CADIS, an
85+ :class: `openmc.WeightWindowGenerator ` object is added to the
86+ :attr: `openmc.Settings ` object, and a ``weight_windows.h5 `` will be generated
87+ at the end of the simulation. The only procedural difference is that the code
88+ must be run in random ray mode. A full description of how to enable and setup
8389random ray mode can be found in the :ref: `Random Ray User Guide <random_ray >`.
8490
8591.. note ::
@@ -90,7 +96,7 @@ random ray mode can be found in the :ref:`Random Ray User Guide <random_ray>`.
9096 ray solver. A high level overview of the current workflow for generation of
9197 weight windows with FW-CADIS using random ray is given below.
9298
93- 1. Begin by making a deepy copy of your continuous energy Python model and then
99+ 1. Begin by making a deep copy of your continuous energy Python model and then
94100 convert the copy to be multigroup and use the random ray transport solver.
95101 The conversion process can largely be automated as described in more detail
96102 in the :ref: `random ray quick start guide <quick_start >`, summarized below::
@@ -148,7 +154,53 @@ random ray mode can be found in the :ref:`Random Ray User Guide <random_ray>`.
148154 assigning to ``model.settings.random_ray['source_region_meshes'] ``) and for
149155 weight window generation.
150156
151- 3. When running your multigroup random ray input deck, OpenMC will automatically
157+ 3. (Optional) If local variance reduction is desired in a fixed-source problem,
158+ populate the :attr: `targets ` attribute with an :class: `openmc.Tallies `
159+ instance or an iterable of tally IDs indicating the tallies of interest for
160+ variance reduction::
161+
162+ # Build a new example and WWG for local variance reduction
163+ from openmc.examples import random_ray_three_region_cube_with_detectors
164+ new_model = random_ray_three_region_cube_with_detectors()
165+
166+ ww_mesh = openmc.RegularMesh()
167+ n = 7
168+ width = 35.0
169+ ww_mesh.dimension = (n, n, n)
170+ ww_mesh.lower_left = (0.0, 0.0, 0.0)
171+ ww_mesh.upper_right = (width, width, width)
172+
173+ wwg = openmc.WeightWindowGenerator(
174+ method="fw_cadis",
175+ mesh=ww_mesh,
176+ max_realizations=new_model.settings.batches
177+ )
178+ new_model.settings.weight_window_generators = wwg
179+ new_model.settings.random_ray['volume_estimator'] = 'naive'
180+
181+ # Get the tallies of interest
182+ target_tallies = openmc.Tallies()
183+
184+ for tally in list(new_model.tallies):
185+ if tally.name in {"Detector 1 Tally", "Detector 2 Tally"}:
186+ target_tallies.append(tally)
187+
188+ # Add to WeightWindowGenerator
189+ wwg.targets = target_tallies
190+
191+ .. warning ::
192+ The tallies designated as FW-CADIS targets to the
193+ :class: `~openmc.WeightWindowGenerator ` must be present under the
194+ :class: `~openmc.model.Model.tallies ` attribute of the
195+ :class: `~openmc.model.Model ` as well in order to be recognized as valid
196+ local variance reduction targets. This check is performed when the
197+ :func: `openmc.model.Model.export_to_model_xml ` or
198+ :func: `openmc.model.Model.export_to_xml ` functions are called, meaning
199+ that the standalone :func: `openmc.Settings.export_to_xml ` and
200+ :func: `openmc.Tallies.export_to_xml ` methods should not be used with
201+ FW-CADIS local variance reduction.
202+
203+ 4. When running your multigroup random ray input deck, OpenMC will automatically
152204 run a forward solve followed by an adjoint solve, with a
153205 ``weight_windows.h5 `` file generated at the end. The ``weight_windows.h5 ``
154206 file will contain FW-CADIS generated weight windows. This file can be used in
0 commit comments