diff --git a/openmc/material.py b/openmc/material.py index 292fc82ca7..caad3a1cd6 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -83,6 +83,29 @@ class Material(object): # If specified, this file will be used instead of composition values self._distrib_otf_file = None + def __eq__(self, other): + if not isinstance(other, Material): + return False + elif self.id != other.id: + return False + elif self.name != other.name: + return False + elif self.density != other.density: + return False + elif self.density_units != other.density_units: + return False + elif self._nuclides != other.nuclides: + return False + elif self._elements != other._elements: + return False + elif self._sab != other._sab: + return False + else: + return True + + def __ne__(self, other): + return not self == other + def __repr__(self): string = 'Material\n' string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id) diff --git a/openmc/region.py b/openmc/region.py index 97069d797b..936e6e5121 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -29,6 +29,17 @@ class Region(object): def __str__(self): return '' + def __eq__(self, other): + if not isinstance(other, type(self)): + return False + elif str(self) != str(other): + return False + else: + return True + + def __ne__(self, other): + return not self == other + @staticmethod def from_expression(expression, surfaces): """Generate a region given an infix expression. diff --git a/openmc/universe.py b/openmc/universe.py index b74dde656d..1fb29e2603 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -73,6 +73,29 @@ class Cell(object): self._translation = None self._offsets = None + def __eq__(self, other): + if not isinstance(other, Cell): + return False + elif self.id != other.id: + return False + elif self.name != other.name: + return False + # FIXME: This won't work for materials fills since OpenMC only outputs + # nuclide densities in units of atom/b-cm irregardless of input units + # elif self.fill != other.fill: + # return False + elif self.region != other.region: + return False + elif self.rotation != other.rotation: + return False + elif self.translation != other.translation: + return False + else: + return True + + def __ne__(self, other): + return not self == other + def __repr__(self): string = 'Cell\n' string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id) @@ -443,6 +466,31 @@ class Universe(object): self._cell_offsets = OrderedDict() self._num_regions = 0 + def __eq__(self, other): + if not isinstance(other, Universe): + return False + elif self.id != other.id: + return False + elif self.name != other.name: + return False + elif self.cells != other.cells: + return False + else: + return True + + def __ne__(self, other): + return not self == other + + def __repr__(self): + string = 'Universe\n' + string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id) + string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name) + string += '{0: <16}{1}{2}\n'.format('\tCells', '=\t', + list(self._cells.keys())) + string += '{0: <16}{1}{2}\n'.format('\t# Regions', '=\t', + self._num_regions) + return string + @property def id(self): return self._id @@ -630,16 +678,6 @@ class Universe(object): return universes - def __repr__(self): - string = 'Universe\n' - string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id) - string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name) - string += '{0: <16}{1}{2}\n'.format('\tCells', '=\t', - list(self._cells.keys())) - string += '{0: <16}{1}{2}\n'.format('\t# Regions', '=\t', - self._num_regions) - return string - def create_xml_subelement(self, xml_element): # Iterate over all Cells @@ -695,6 +733,25 @@ class Lattice(object): self._outer = None self._universes = None + def __eq__(self, other): + if not isinstance(other, Lattice): + return False + elif self.id != other.id: + return False + elif self.name != other.name: + return False + elif self.pitch != other.pitch: + return False + elif self.outer != other.outer: + return False + elif self.universes != other.universes: + return False + else: + return True + + def __ne__(self, other): + return not self == other + @property def id(self): return self._id @@ -894,6 +951,21 @@ class RectLattice(Lattice): self._lower_left = None self._offsets = None + def __eq__(self, other): + if not isinstance(other, RectLattice): + return False + elif not super(RectLattice, self).__eq__(other): + return False + elif self.dimension != other.dimension: + return False + elif self.lower_left != other.lower_left: + return False + else: + return True + + def __ne__(self, other): + return not self == other + def __repr__(self): string = 'RectLattice\n' string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id) @@ -1111,6 +1183,23 @@ class HexLattice(Lattice): self._num_axial = None self._center = None + def __eq__(self, other): + if not isinstance(other, HexLattice): + return False + elif not super(HexLattice, self).__eq__(other): + return False + elif self.num_rings != other.num_rings: + return False + elif self.num_axial != other.num_axial: + return False + elif self.center != other.center: + return False + else: + return True + + def __ne__(self, other): + return not self == other + def __repr__(self): string = 'HexLattice\n' string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)