mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Address @promano comments
This commit is contained in:
parent
f404ffb20b
commit
62d1a650e3
4 changed files with 41 additions and 23 deletions
|
|
@ -271,7 +271,7 @@ Functions
|
|||
Get number of batches to simulate
|
||||
|
||||
:param int* n_batches: Number of batches to simulate
|
||||
:param int* get_max_batches: Whether to return `n_batches` or `n_max_batches` (only relevant when triggers are used)
|
||||
:param bool get_max_batches: Whether to return `n_batches` or `n_max_batches` (only relevant when triggers are used)
|
||||
:return: Return status (negative if an error occurred)
|
||||
:rtype: int
|
||||
|
||||
|
|
|
|||
|
|
@ -66,14 +66,14 @@ class _Settings:
|
|||
_dll.openmc_set_seed(seed)
|
||||
|
||||
def set_batches(self, n_batches, set_max_batches=True, add_sp_batch=True):
|
||||
"""Set n_batches
|
||||
"""Set number of batches or maximum number of batches
|
||||
|
||||
Parameters
|
||||
----------
|
||||
n_batches : int
|
||||
Number of batches to simulate
|
||||
set_max_batches : int
|
||||
Whether to set maximum number of batches. If true, the value of
|
||||
set_max_batches : bool
|
||||
Whether to set maximum number of batches. If True, the value of
|
||||
`n_max_batches` is overridden, otherwise the value of `n_batches`
|
||||
is overridden. Only has an effect when triggers are used
|
||||
add_sp_batch : bool
|
||||
|
|
|
|||
|
|
@ -849,13 +849,13 @@ openmc_set_n_batches(int32_t n_batches, bool set_max_batches,
|
|||
// Set n_batches and n_max_batches to same value
|
||||
settings::n_batches = n_batches;
|
||||
settings::n_max_batches = n_batches;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Set n_batches and n_max_batches based on value of set_max_batches
|
||||
if (set_max_batches)
|
||||
if (set_max_batches) {
|
||||
settings::n_max_batches = n_batches;
|
||||
else
|
||||
} else {
|
||||
settings::n_batches = n_batches;
|
||||
}
|
||||
}
|
||||
|
||||
// Update size of k_generation and entropy
|
||||
|
|
@ -874,10 +874,7 @@ openmc_set_n_batches(int32_t n_batches, bool set_max_batches,
|
|||
extern "C" int
|
||||
openmc_get_n_batches(int* n_batches, bool get_max_batches)
|
||||
{
|
||||
if (get_max_batches)
|
||||
*n_batches = settings::n_max_batches;
|
||||
else
|
||||
*n_batches = settings::n_batches;
|
||||
*n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,37 @@ def pincell_model():
|
|||
yield
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def uo2_trigger_model():
|
||||
"""Set up a simple UO2 model with k-eff trigger"""
|
||||
model = openmc.model.Model()
|
||||
m = openmc.Material(name='UO2')
|
||||
m.add_nuclide('U235', 1.0)
|
||||
m.add_nuclide('O16', 2.0)
|
||||
m.set_density('g/cm3', 10.0)
|
||||
model.materials.append(m)
|
||||
|
||||
cyl = openmc.ZCylinder(r=1.0, boundary_type='vacuum')
|
||||
c = openmc.Cell(fill=m, region=-cyl)
|
||||
model.geometry.root_universe = openmc.Universe(cells=[c])
|
||||
|
||||
model.settings.batches = 10
|
||||
model.settings.inactive = 5
|
||||
model.settings.particles = 100
|
||||
model.settings.source = openmc.Source(space=openmc.stats.Box(
|
||||
[-0.5, -0.5, -1], [0.5, 0.5, 1], only_fissionable=True))
|
||||
model.settings.verbosity = 1
|
||||
model.settings.keff_trigger = {'type': 'std_dev', 'threshold': 0.001}
|
||||
model.settings.trigger_active = True
|
||||
model.settings.trigger_max_batches = 10
|
||||
model.settings.trigger_batch_interval = 1
|
||||
|
||||
# Write XML files in tmpdir
|
||||
with cdtemp():
|
||||
model.export_to_xml()
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def lib_init(pincell_model, mpi_intracomm):
|
||||
openmc.lib.init(intracomm=mpi_intracomm)
|
||||
|
|
@ -550,17 +581,7 @@ def test_global_bounding_box(lib_init):
|
|||
assert tuple(urc) == expected_urc
|
||||
|
||||
|
||||
def test_trigger_set_n_batches(lib_run, mpi_intracomm):
|
||||
openmc.reset_auto_ids()
|
||||
pincell = openmc.examples.pwr_pin_cell()
|
||||
pincell.settings.verbosity = 1
|
||||
pincell.settings.keff_trigger = {'type': 'std_dev', 'threshold': 0.01}
|
||||
pincell.settings.trigger_active = True
|
||||
pincell.settings.trigger_max_batches = 10
|
||||
pincell.settings.trigger_batch_interval = 1
|
||||
|
||||
pincell.export_to_xml()
|
||||
openmc.lib.hard_reset()
|
||||
def test_trigger_set_n_batches(uo2_trigger_model, mpi_intracomm):
|
||||
openmc.lib.finalize()
|
||||
openmc.lib.init(intracomm=mpi_intracomm)
|
||||
openmc.lib.simulation_init()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue