Skip to content

Commit

Permalink
Merge pull request #16 from openmsr/refuel_scheme
Browse files Browse the repository at this point in the history
add authomatic refuel scheme class
  • Loading branch information
church89 authored Oct 30, 2023
2 parents b916c9d + 1b978f0 commit 186a267
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 6 deletions.
7 changes: 4 additions & 3 deletions openmc/deplete/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
from .transfer_rates import TransferRates
from openmc import Material, Cell
from .batchwise import (BatchwiseCellGeometrical, BatchwiseCellTemperature,
BatchwiseMaterialRefuel, BatchwiseMaterialDilute, BatchwiseSchemeStd)
BatchwiseMaterialRefuel, BatchwiseMaterialDilute, BatchwiseSchemeStd,
BatchwiseSchemeRefuel)

__all__ = [
"OperatorResult", "TransportOperator",
Expand Down Expand Up @@ -916,8 +917,8 @@ def add_batchwise_scheme(self, scheme_name, **kwargs):
"""
if scheme_name == 'std':
self.batchwise = BatchwiseSchemeStd(self.batchwise, len(self), **kwargs)
#elif scheme_name == 'flex':
# self.batchwise = BatchwiseSchemeFlex(self.batchwise, **kwargs)
elif scheme_name == 'refuel':
self.batchwise = BatchwiseSchemeRefuel(self.batchwise, **kwargs)

def add_density_function(self, mats, density_func, oxidation_states):
self.batchwise.set_density_function(mats, density_func, oxidation_states)
Expand Down
94 changes: 91 additions & 3 deletions openmc/deplete/batchwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _search_for_keff(self, val):

else:
raise ValueError('ERROR: Search_for_keff output is not valid')

return root

def _get_materials(self, vals):
Expand Down Expand Up @@ -818,7 +818,7 @@ def __init__(self, cell, attrib_name, operator, model, bracket,
check_value('attrib_name', attrib_name,
('rotation', 'translation'))
self.attrib_name = attrib_name

# check if cell is filled with 2 cells
if not isinstance(self.cell.fill, openmc.universe.DAGMCUniverse):

Expand All @@ -831,7 +831,7 @@ def __init__(self, cell, attrib_name, operator, model, bracket,
# Initialize vector
self.vector = np.zeros(3)


check_type('samples', samples, int)
self.samples = samples

Expand Down Expand Up @@ -1565,3 +1565,91 @@ def search_for_keff(self, x, step_index):
for rank in range(comm.size):
comm.Abort()
return x

class BatchwiseSchemeRefuel():
"""
Batchwise wrapper class, it wraps BatchwiseGeom and BatchwiseMat instances,
with some user defined logic.
This class should probably not be defined here, but we can keep it now for
convenience
The loop logic of this wrapper class is the following:
1. Run BatchwiseGeom and return geometrical coefficient
2. check if geometrical coefficient hit upper limit
3.1 if not, continue
3.2 if yes, refuel and reset geometrical coefficient
An instance of this class can be passed directly to an instance of the
integrator class, such as :class:`openmc.deplete.CECMIntegrator`.
Parameters
----------
bw_geom : BatchwiseGeom
openmc.deplete.batchwise.BatchwiseGeom object
bw_mat : BatchwiseMat
openmc.deplete.batchwise.BatchwiseMat object
restart_level : int
Geometrical coefficient after reset
"""

def __init__(self, bw_list, restart_level):

if isinstance(bw_list, list):
for bw in bw_list:
if isinstance(bw, BatchwiseCell):
self.bw_geom = bw
elif isinstance(bw, BatchwiseMaterial):
self.bw_mat = bw
else:
raise ValueError(f'{bw} is not a valid instance of'
' Batchwise class')
else:
raise ValueError(f'{bw_list} is not a list')

self.bw_list = bw_list

if not isinstance(restart_level, (float, int)):
raise ValueError(f'{restart_level} is of type {type(restart_level)},'
' while it should be int or float')
else:
self.restart_level = restart_level

def set_density_function(self, mats, density_func, oxidation_states):
for bw in self.bw_list:
bw.set_density_function(mats, density_func, oxidation_states)

def _update_volumes_after_depletion(self, x):
"""
This is for a restart. TODO update abc class
Parameters
----------
x : list of numpy.ndarray
Total atom concentrations
"""
self.bw_geom._update_volumes(x)

def search_for_keff(self, x, step_index):
"""
Perform the criticality search on the parametric material model.
Will set the root of the `search_for_keff` function to the atoms
concentrations vector.
Parameters
----------
x : list of numpy.ndarray
Total atoms concentrations
Returns
-------
x : list of numpy.ndarray
Updated total atoms concentrations
"""
#Start by doing a geometrical search§
x,root = self.bw_geom.search_for_keff(x, step_index)
#check if upper geometrical limit gets hit
if root >= self.bw_geom.bracket_limit[1]:
# Reset geometry and refuel
self.bw_geom._set_cell_attrib(self.restart_level)
x,root = self.bw_mat.search_for_keff(x, step_index)

return x,root

0 comments on commit 186a267

Please sign in to comment.