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

Add batchwise pure class #27

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions openmc/deplete/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .pool import deplete
from .transfer_rates import TransferRates
from openmc import Material, Cell
from .batchwise import (BatchwiseCellGeometrical, BatchwiseCellTemperature,
from .batchwise import (BatchwisePure, BatchwiseCellGeometrical, BatchwiseCellTemperature,
BatchwiseMaterialRefuel, BatchwiseMaterialDilute, BatchwiseMaterialAdd,
BatchwiseSchemeStd, BatchwiseSchemeRefuel, BatchwiseSchemeFlex)

Expand Down Expand Up @@ -814,7 +814,7 @@ def integrate(self, final_step=True, output=True):
n, root = self._get_bos_from_batchwise(i, n)
else:
# Store root at previous timestep
root = self.batchwise._get_cell_attrib()
root = self.batchwise.get_root()
else:
root = None
n, res = self._get_bos_data_from_operator(i, source_rate, n)
Expand Down Expand Up @@ -884,7 +884,7 @@ def integrate_adaptive(self, material_id, nuclides, final_step=True,
with change_directory(self.operator.output_dir):
n = self.operator.initial_condition()
t, self._i_res = self._get_start_data()

nuc_ids = [id for nuc,id in self.chain.nuclide_dict.items() if nuc in nuclides]

dt = self.timesteps[0]
Expand Down Expand Up @@ -935,7 +935,7 @@ def integrate_adaptive(self, material_id, nuclides, final_step=True,
n = n_list.pop()
StepResult.save(self.operator, n_list, res_list, [t, t + dt],
source_rate, self._i_res + i, proc_time, root)

for rank in range(comm.size):
number_i = comm.bcast(self.operator.number, root=rank)
if material_id in number_i.materials:
Expand All @@ -947,7 +947,7 @@ def integrate_adaptive(self, material_id, nuclides, final_step=True,
tol, err, rho1, rho2, f)
comm.barrier()
dt = comm.bcast(dt, root=rank_mat)

t += dt
i += 1
# Final simulation -- in the case that final_step is False, a zero
Expand All @@ -969,7 +969,7 @@ def integrate_adaptive(self, material_id, nuclides, final_step=True,

def _adapt_timestep(self, n_pred, n_corr, mat_idx, nuc_ids, tol, err, rho1,
rho2, f ):

filt_pred = take(n_pred[mat_idx], nuc_ids)
filt_corr = take(n_corr[mat_idx], nuc_ids)

Expand Down Expand Up @@ -1072,6 +1072,8 @@ def add_redox(self, mat, buffer, oxidation_states):
self.transfer_rates.set_redox(mat, buffer, oxidation_states)

def add_material(self, mat, value, mat_vector, timestep, quantity='grams'):
if self.batchwise is None:
self.batchwise = BatchwisePure(self.operator, self.operator.model)
self.batchwise.add_material(mat, value, mat_vector, timestep,
quantity)
@add_params
Expand Down
80 changes: 74 additions & 6 deletions openmc/deplete/batchwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def target(self, value):
def from_params(cls, obj, attr, operator, model, **kwargs):
return cls(obj, attr, operator, model, **kwargs)

@abstractmethod
def get_root(self):
"""
"""

@abstractmethod
def _model_builder(self, param):
"""
Expand Down Expand Up @@ -619,6 +624,61 @@ def _add_material(self, x, mat, values):
x[mat_idx][nuc_idx] += val
return x

class BatchwisePure(Batchwise):
def __init__(self, operator, model, density_treatment='constant-volume',
redox_vec=None):
super().__init__(operator, model, [0,1], [-100,100])
self.cell_materials = None

def get_root(self):
return np.nan

def search_for_keff(self, x, step_index):
"""
Perform the criticality search on the parametric cell coefficient and
update materials accordingly.
The :meth:`openmc.search.search_for_keff` solution is then set as the
new cell attribute.
Parameters
----------
x : list of numpy.ndarray
Total atoms concentrations
Returns
-------
x : list of numpy.ndarray
Updated total atoms concentrations
"""
x = super()._update_materials(x, step_index)
# if at least one of the cell materials is depletable, calculate new
# volume and update x and number accordingly.
# Alternatively, if material has been edded x needs to be updated
# TODO: improve this
if self.cell_materials:
volumes = self._calculate_volumes()
x = super()._update_x_and_set_volumes(x, volumes)

return x, np.nan

def _model_builder(self, param):
"""
Builds the parametric model to be passed to the
:meth:`openmc.search.search_for_keff` method.
Callable function which builds a model according to a passed
parameter. This function must return an openmc.model.Model object.
Parameters
----------
param : parameter
model function variable
Returns
-------
_model : openmc.model.Model
OpenMC parametric model
"""

def update_from_restart(self, step_index, x, root):
"""
"""

class BatchwiseCell(Batchwise):
"""Abstract class holding batch wise cell-based functions.

Expand Down Expand Up @@ -714,6 +774,9 @@ def _set_cell_attrib(self, val):
cell coefficient to set
"""

def get_root(self):
return self._get_cell_attrib()

def _get_cell(self, val):
"""Helper method for getting cell from cell instance or cell name or id.
Parameters
Expand Down Expand Up @@ -1173,6 +1236,11 @@ def _model_builder(self, param):
Openmc parametric model
"""

def get_root(self):
for mat in openmc.lib.materials.values():
if mat.id in [m.id for m in self.materials]:
return mat.get_density()

def search_for_keff(self, x, step_index):
"""
Perform the criticality search on parametric material variable.
Expand Down Expand Up @@ -1935,8 +2003,8 @@ def __init__(self, bw_list, n_timesteps, dilute_interval, restart_level,
self.dilute_interval = dilute_interval
self.interrupt = interrupt

def _get_cell_attrib(self):
return self.bw_geom._get_cell_attrib()
def get_root(self):
return self.bw_geom.get_root()

def set_density_function(self, mats, density_func, oxidation_states):
for bw in self.bw_list:
Expand Down Expand Up @@ -2046,8 +2114,8 @@ def __init__(self, bw_list, restart_level):
else:
self.restart_level = restart_level

def _get_cell_attrib(self):
return self.bw_geom._get_cell_attrib()
def get_root(self):
return self.bw_geom.get_root()

def set_density_function(self, mats, density_func, oxidation_states):
for bw in self.bw_list:
Expand Down Expand Up @@ -2176,8 +2244,8 @@ def __init__(self, bw_list, n_timesteps, nuclide, limit, flex_fraction, span,
#
self.converged_flex = False

def _get_cell_attrib(self):
return self.bw_geom_trans._get_cell_attrib()
def get_root(self):
return self.bw_geom_trans.get_root()

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