Don't keep track of non-burnable materials

This commit is contained in:
Paul Romano 2018-02-19 09:17:12 -06:00
parent f113205ab9
commit fe547feb74
3 changed files with 34 additions and 95 deletions

View file

@ -19,8 +19,6 @@ class AtomNumber(object):
A dictionary mapping nuclide name as string to index.
volume : OrderedDict of int to float
Volume of geometry.
n_mat_burn : int
Number of materials to be burned.
n_nuc_burn : int
Number of nuclides to be burned.
@ -33,8 +31,6 @@ class AtomNumber(object):
volume : numpy.array
Volume of geometry indexed by mat_to_ind. If a volume is not found,
it defaults to 1 so that reading density still works correctly.
n_mat_burn : int
Number of materials to be burned.
n_nuc_burn : int
Number of nuclides to be burned.
n_mat : int
@ -45,30 +41,26 @@ class AtomNumber(object):
Array storing total atoms indexed by the above dictionaries.
burn_nuc_list : list of str
A list of all nuclide material names. Used for sorting the simulation.
burn_mat_list : list of str
A list of all burning material names. Used for sorting the simulation.
"""
def __init__(self, mat_to_ind, nuc_to_ind, volume, n_mat_burn, n_nuc_burn):
"""
def __init__(self, mat_to_ind, nuc_to_ind, volume, n_nuc_burn):
self.mat_to_ind = mat_to_ind
self.nuc_to_ind = nuc_to_ind
self.volume = np.ones(self.n_mat)
self.volume = np.ones(len(mat_to_ind))
for mat in volume:
if str(mat) in self.mat_to_ind:
ind = self.mat_to_ind[str(mat)]
if mat in self.mat_to_ind:
ind = self.mat_to_ind[mat]
self.volume[ind] = volume[mat]
self.n_mat_burn = n_mat_burn
self.n_nuc_burn = n_nuc_burn
self.number = np.zeros((self.n_mat, self.n_nuc))
# For performance, create storage for burn_nuc_list, burn_mat_list
self._burn_nuc_list = None
self._burn_mat_list = None
def __getitem__(self, pos):
"""Retrieves total atom number from AtomNumber.
@ -175,7 +167,7 @@ class AtomNumber(object):
if isinstance(mat, str):
mat = self.mat_to_ind[mat]
return self[mat, 0:self.n_nuc_burn]
return self[mat, :self.n_nuc_burn]
def set_mat_slice(self, mat, val):
"""Sets atom quantity indexed by mats for all burned nuclides
@ -191,7 +183,7 @@ class AtomNumber(object):
if isinstance(mat, str):
mat = self.mat_to_ind[mat]
self[mat, 0:self.n_nuc_burn] = val
self[mat, :self.n_nuc_burn] = val
@property
def n_mat(self):
@ -218,19 +210,3 @@ class AtomNumber(object):
self._burn_nuc_list[ind] = nuc
return self._burn_nuc_list
@property
def burn_mat_list(self):
"""burn_mat_list : list of str
A list of all burning material names. Used for sorting the simulation.
"""
if self._burn_mat_list is None:
self._burn_mat_list = [None] * self.n_mat_burn
for mat in self.mat_to_ind:
ind = self.mat_to_ind[mat]
if ind < self.n_mat_burn:
self._burn_mat_list[ind] = mat
return self._burn_mat_list

View file

@ -121,9 +121,9 @@ class OpenMCOperator(Operator):
The depletion chain information necessary to form matrices and tallies.
reaction_rates : openmc.deplete.ReactionRates
Reaction rates from the last operator step.
burn_mat_to_id : OrderedDict of str to int
burn_mat_to_ind : OrderedDict of str to int
Dictionary mapping material ID (as a string) to an index in reaction_rates.
burn_nuc_to_id : OrderedDict of str to int
burn_nuc_to_ind : OrderedDict of str to int
Dictionary mapping nuclide name (as a string) to an index in
reaction_rates.
n_nuc : int
@ -148,18 +148,16 @@ class OpenMCOperator(Operator):
# Clear out OpenMC, create task lists, distribute
if comm.rank == 0:
openmc.reset_auto_ids()
mat_burn_list, mat_not_burn_list, volume, self.mat_tally_ind, \
mat_burn_list, volume, self.mat_tally_ind, \
nuc_dict = self.extract_mat_ids()
else:
# Dummy variables
mat_burn_list = None
mat_not_burn_list = None
volume = None
nuc_dict = None
self.mat_tally_ind = None
mat_burn = comm.scatter(mat_burn_list)
mat_not_burn = comm.scatter(mat_not_burn_list)
nuc_dict = comm.bcast(nuc_dict)
volume = comm.bcast(volume)
self.mat_tally_ind = comm.bcast(self.mat_tally_ind)
@ -168,7 +166,7 @@ class OpenMCOperator(Operator):
self.load_participating()
# Extract number densities from the geometry
self.extract_number(mat_burn, mat_not_burn, volume, nuc_dict)
self.extract_number(mat_burn, volume, nuc_dict)
# Create reaction rates array
index_rx = {rx: i for i, rx in enumerate(self.chain.reactions)}
@ -239,9 +237,7 @@ class OpenMCOperator(Operator):
"""
mat_burn = set()
mat_not_burn = set()
nuc_set = set()
volume = OrderedDict()
# Iterate once through the geometry to get dictionaries
@ -254,19 +250,14 @@ class OpenMCOperator(Operator):
raise RuntimeError("Volume not specified for depletable "
"material with ID={}.".format(mat.id))
volume[str(mat.id)] = mat.volume
else:
mat_not_burn.add(str(mat.id))
# Sort the sets
mat_burn = sorted(mat_burn, key=int)
mat_not_burn = sorted(mat_not_burn, key=int)
nuc_set = sorted(nuc_set)
# Construct a global nuclide dictionary, burned first
nuc_dict = copy.deepcopy(self.chain.nuclide_dict)
i = len(nuc_dict)
for nuc in nuc_set:
if nuc not in nuc_dict:
nuc_dict[nuc] = i
@ -274,47 +265,35 @@ class OpenMCOperator(Operator):
# Decompose geometry
mat_burn_lists = _chunks(mat_burn, comm.size)
mat_not_burn_lists = _chunks(mat_not_burn, comm.size)
mat_tally_ind = OrderedDict()
for i, mat in enumerate(mat_burn):
mat_tally_ind[mat] = i
return mat_burn_lists, mat_not_burn_lists, volume, mat_tally_ind, nuc_dict
return mat_burn_lists, volume, mat_tally_ind, nuc_dict
def extract_number(self, mat_burn, mat_not_burn, volume, nuc_dict):
def extract_number(self, mat_burn, volume, nuc_dict):
"""Construct self.number read from geometry
Parameters
----------
mat_burn : list of int
Materials to be burned managed by this thread.
mat_not_burn
Materials not to be burned managed by this thread.
volume : OrderedDict of str to float
Volumes for the above materials.
nuc_dict : OrderedDict of str to int
Nuclides to be used in the simulation.
"""
# Same with materials
mat_dict = OrderedDict()
self.burn_mat_to_ind = OrderedDict()
i = 0
for mat in mat_burn:
mat_dict[mat] = i
for i, mat in enumerate(mat_burn):
self.burn_mat_to_ind[mat] = i
i += 1
for mat in mat_not_burn:
mat_dict[mat] = i
i += 1
n_mat_burn = len(mat_burn)
n_nuc_burn = len(self.chain)
self.number = AtomNumber(mat_dict, nuc_dict, volume, n_mat_burn, n_nuc_burn)
self.number = AtomNumber(self.burn_mat_to_ind, nuc_dict, volume,
n_nuc_burn)
if self.settings.dilute_initial != 0.0:
for nuc in self.burn_nuc_to_ind:
@ -323,7 +302,7 @@ class OpenMCOperator(Operator):
# Now extract the number densities and store
for mat in self.geometry.get_all_materials().values():
if str(mat.id) in mat_dict:
if str(mat.id) in self.burn_mat_to_ind:
self.set_number_from_mat(mat)
def set_number_from_mat(self, mat):
@ -397,9 +376,6 @@ class OpenMCOperator(Operator):
number_i = comm.bcast(self.number, root=rank)
for mat in number_i.mat_to_ind:
if number_i.mat_to_ind[mat] >= number_i.n_mat_burn:
continue
nuclides = []
densities = []
for nuc in number_i.nuc_to_ind:
@ -507,12 +483,10 @@ class OpenMCOperator(Operator):
Returns
-------
list of numpy.array
A list of np.arrays containing total atoms of each cell.
A list of arrays containing total atoms of each material
"""
total_density = [self.number.get_mat_slice(i) for i in range(self.number.n_mat_burn)]
return total_density
return list(self.number.get_mat_slice(np.s_[:]))
def set_density(self, total_density):
"""Sets density.
@ -522,12 +496,12 @@ class OpenMCOperator(Operator):
Parameters
----------
total_density : list of numpy.array
total_density : list of numpy.ndarray
Total atoms.
"""
"""
# Fill in values
for i in range(self.number.n_mat_burn):
for i in range(self.number.n_mat):
self.number.set_mat_slice(i, total_density[i])
def unpack_tallies_and_normalize(self):
@ -581,7 +555,7 @@ class OpenMCOperator(Operator):
break
# Extract results
for i, mat in enumerate(self.number.burn_mat_list):
for i, mat in enumerate(self.burn_mat_to_ind):
# Get tally index
slab = materials.index(mat)
@ -686,7 +660,7 @@ class OpenMCOperator(Operator):
"""
nuc_list = self.number.burn_nuc_list
burn_list = self.number.burn_mat_list
burn_list = list(self.burn_mat_to_ind)
volume = {}
for i, mat in enumerate(burn_list):

View file

@ -7,11 +7,11 @@ from openmc.deplete import atom_number
def test_indexing():
"""Tests the __getitem__ and __setitem__ routines simultaneously."""
mat_to_ind = {"10000" : 0, "10001" : 1, "10002" : 2}
mat_to_ind = {"10000" : 0, "10001" : 1}
nuc_to_ind = {"U238" : 0, "U235" : 1, "U234" : 2}
volume = {"10000" : 0.38, "10001" : 0.21}
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2, 2)
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2)
number["10000", "U238"] = 1.0
number["10001", "U238"] = 2.0
@ -42,7 +42,7 @@ def test_n_mat():
nuc_to_ind = {"U238" : 0, "U235" : 1, "Gd157" : 2}
volume = {"10000" : 0.38, "10001" : 0.21}
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2, 2)
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2)
assert number.n_mat == 2
@ -53,7 +53,7 @@ def test_n_nuc():
nuc_to_ind = {"U238" : 0, "U235" : 1, "Gd157" : 2}
volume = {"10000" : 0.38, "10001" : 0.21}
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2, 2)
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2)
assert number.n_nuc == 3
@ -64,22 +64,11 @@ def test_burn_nuc_list():
nuc_to_ind = {"U238" : 0, "U235" : 1, "Gd157" : 2}
volume = {"10000" : 0.38, "10001" : 0.21}
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2, 2)
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2)
assert number.burn_nuc_list == ["U238", "U235"]
def test_burn_mat_list():
"""Test the list of burned nuclides property"""
mat_to_ind = {"10000" : 0, "10001" : 1, "10002" : 2}
nuc_to_ind = {"U238" : 0, "U235" : 1, "Gd157" : 2}
volume = {"10000" : 0.38, "10001" : 0.21}
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2, 2)
assert number.burn_mat_list == ["10000", "10001"]
def test_density_indexing():
"""Tests the get and set_atom_density routines simultaneously."""
@ -87,7 +76,7 @@ def test_density_indexing():
nuc_to_ind = {"U238" : 0, "U235" : 1, "U234" : 2}
volume = {"10000" : 0.38, "10001" : 0.21}
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2, 2)
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2)
number.set_atom_density("10000", "U238", 1.0)
number.set_atom_density("10001", "U238", 2.0)
@ -144,7 +133,7 @@ def test_get_mat_slice():
nuc_to_ind = {"U238" : 0, "U235" : 1, "U234" : 2}
volume = {"10000" : 0.38, "10001" : 0.21}
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2, 2)
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2)
number.number = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]])
@ -164,7 +153,7 @@ def test_set_mat_slice():
nuc_to_ind = {"U238" : 0, "U235" : 1, "U234" : 2}
volume = {"10000" : 0.38, "10001" : 0.21}
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2, 2)
number = atom_number.AtomNumber(mat_to_ind, nuc_to_ind, volume, 2)
number.set_mat_slice(0, [1.0, 2.0])