2016-01-29 16:54:07 -05:00
|
|
|
from numbers import Integral
|
2023-12-13 08:11:32 -06:00
|
|
|
|
2023-05-09 11:41:04 -04:00
|
|
|
import lxml.etree as ET
|
2016-01-30 23:18:08 -05:00
|
|
|
|
2016-10-30 15:31:19 -04:00
|
|
|
import openmc.checkvalue as cv
|
2020-04-06 15:16:09 -05:00
|
|
|
from .mixin import EqualityMixin, IDManagerMixin
|
2025-08-08 20:47:55 +03:00
|
|
|
from ._xml import get_text
|
2016-01-30 23:43:11 -05:00
|
|
|
|
|
|
|
|
|
2017-06-02 13:25:34 -05:00
|
|
|
class TallyDerivative(EqualityMixin, IDManagerMixin):
|
2016-01-29 16:54:07 -05:00
|
|
|
"""A material perturbation derivative to apply to a tally.
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
2017-03-13 10:00:41 -05:00
|
|
|
derivative_id : int, optional
|
2016-01-29 16:54:07 -05:00
|
|
|
Unique identifier for the tally derivative. If none is specified, an
|
|
|
|
|
identifier will automatically be assigned
|
2016-11-13 13:49:30 -05:00
|
|
|
variable : str, optional
|
|
|
|
|
Accepted values are 'density', 'nuclide_density', and 'temperature'
|
2017-03-13 10:00:41 -05:00
|
|
|
material : int, optional
|
2017-03-15 11:25:24 -04:00
|
|
|
The perturbed material ID
|
2016-11-13 13:49:30 -05:00
|
|
|
nuclide : str, optional
|
|
|
|
|
The perturbed nuclide. Only needed for 'nuclide_density' derivatives.
|
|
|
|
|
Ex: 'Xe135'
|
2016-01-29 16:54:07 -05:00
|
|
|
|
|
|
|
|
Attributes
|
|
|
|
|
----------
|
2017-03-13 10:00:41 -05:00
|
|
|
id : int
|
2016-01-29 16:54:07 -05:00
|
|
|
Unique identifier for the tally derivative
|
|
|
|
|
variable : str
|
2016-02-08 22:00:51 -05:00
|
|
|
Accepted values are 'density', 'nuclide_density', and 'temperature'
|
2017-03-13 10:00:41 -05:00
|
|
|
material : int
|
2016-11-13 13:49:30 -05:00
|
|
|
The perturubed material ID
|
2016-01-29 16:54:07 -05:00
|
|
|
nuclide : str
|
|
|
|
|
The perturbed nuclide. Only needed for 'nuclide_density' derivatives.
|
2016-11-13 13:49:30 -05:00
|
|
|
Ex: 'Xe135'
|
2016-01-29 16:54:07 -05:00
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
2017-06-02 13:25:34 -05:00
|
|
|
next_id = 1
|
|
|
|
|
used_ids = set()
|
|
|
|
|
|
2016-11-13 13:49:30 -05:00
|
|
|
def __init__(self, derivative_id=None, variable=None, material=None,
|
|
|
|
|
nuclide=None):
|
2016-01-29 16:54:07 -05:00
|
|
|
# Initialize Tally class attributes
|
|
|
|
|
self.id = derivative_id
|
2016-11-13 13:49:30 -05:00
|
|
|
self.variable = variable
|
|
|
|
|
self.material = material
|
|
|
|
|
self.nuclide = nuclide
|
2016-01-29 16:54:07 -05:00
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
string = 'Tally Derivative\n'
|
2016-11-13 13:49:30 -05:00
|
|
|
string += '{: <16}=\t{}\n'.format('\tID', self.id)
|
|
|
|
|
string += '{: <16}=\t{}\n'.format('\tVariable', self.variable)
|
2020-04-01 13:36:10 -05:00
|
|
|
string += '{: <16}=\t{}\n'.format('\tMaterial', self.material)
|
|
|
|
|
if self.variable == 'nuclide_density':
|
2016-11-13 13:49:30 -05:00
|
|
|
string += '{: <16}=\t{}\n'.format('\tNuclide', self.nuclide)
|
2016-01-29 16:54:07 -05:00
|
|
|
|
|
|
|
|
return string
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def variable(self):
|
|
|
|
|
return self._variable
|
|
|
|
|
|
|
|
|
|
@variable.setter
|
|
|
|
|
def variable(self, var):
|
|
|
|
|
if var is not None:
|
2017-12-24 16:06:05 +07:00
|
|
|
cv.check_type('derivative variable', var, str)
|
2016-11-13 13:49:30 -05:00
|
|
|
cv.check_value('derivative variable', var,
|
|
|
|
|
('density', 'nuclide_density', 'temperature'))
|
2016-10-30 15:31:19 -04:00
|
|
|
self._variable = var
|
2016-01-29 16:54:07 -05:00
|
|
|
|
2023-06-17 04:34:02 +01:00
|
|
|
@property
|
|
|
|
|
def material(self):
|
|
|
|
|
return self._material
|
|
|
|
|
|
2016-01-29 16:54:07 -05:00
|
|
|
@material.setter
|
|
|
|
|
def material(self, mat):
|
|
|
|
|
if mat is not None:
|
|
|
|
|
cv.check_type('derivative material', mat, Integral)
|
2016-10-30 15:31:19 -04:00
|
|
|
self._material = mat
|
2016-01-29 16:54:07 -05:00
|
|
|
|
2023-06-17 04:34:02 +01:00
|
|
|
@property
|
|
|
|
|
def nuclide(self):
|
|
|
|
|
return self._nuclide
|
|
|
|
|
|
2016-01-29 16:54:07 -05:00
|
|
|
@nuclide.setter
|
|
|
|
|
def nuclide(self, nuc):
|
|
|
|
|
if nuc is not None:
|
2017-12-24 16:06:05 +07:00
|
|
|
cv.check_type('derivative nuclide', nuc, str)
|
2016-10-30 15:31:19 -04:00
|
|
|
self._nuclide = nuc
|
2016-01-29 16:54:07 -05:00
|
|
|
|
2016-11-13 13:49:30 -05:00
|
|
|
def to_xml_element(self):
|
2016-01-29 16:54:07 -05:00
|
|
|
"""Return XML representation of the tally derivative
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
2023-05-09 11:41:04 -04:00
|
|
|
element : lxml.etree._Element
|
2016-01-29 16:54:07 -05:00
|
|
|
XML element containing derivative data
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
element = ET.Element("derivative")
|
|
|
|
|
element.set("id", str(self.id))
|
|
|
|
|
element.set("variable", self.variable)
|
|
|
|
|
element.set("material", str(self.material))
|
|
|
|
|
if self.variable == 'nuclide_density':
|
|
|
|
|
element.set("nuclide", self.nuclide)
|
|
|
|
|
return element
|
2022-01-20 17:51:16 -06:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_xml_element(cls, elem):
|
|
|
|
|
"""Generate tally derivative from an XML element
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
2023-05-09 11:41:04 -04:00
|
|
|
elem : lxml.etree._Element
|
2022-01-20 17:51:16 -06:00
|
|
|
XML element
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
openmc.TallyDerivative
|
|
|
|
|
Tally derivative object
|
|
|
|
|
|
|
|
|
|
"""
|
2025-08-08 20:47:55 +03:00
|
|
|
derivative_id = int(get_text(elem, "id"))
|
|
|
|
|
variable = get_text(elem, "variable")
|
|
|
|
|
material = int(get_text(elem, "material"))
|
|
|
|
|
nuclide = get_text(elem, "nuclide") if variable == "nuclide_density" else None
|
2022-01-20 17:51:16 -06:00
|
|
|
return cls(derivative_id, variable, material, nuclide)
|