From 06d531aa39419478298d2cde3bdc25eaafc54ec6 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 30 Jun 2015 16:19:53 +0700 Subject: [PATCH] Add check_greater_than and check_less_than functions --- openmc/checkvalue.py | 54 ++++++++++++++++++++++ openmc/cmfd.py | 24 +++------- openmc/material.py | 7 +-- openmc/mesh.py | 12 ++--- openmc/plots.py | 44 +++++------------- openmc/settings.py | 107 ++++++++++--------------------------------- openmc/surface.py | 9 ++-- openmc/tallies.py | 15 ++---- openmc/universe.py | 46 +++++-------------- 9 files changed, 122 insertions(+), 196 deletions(-) diff --git a/openmc/checkvalue.py b/openmc/checkvalue.py index 1568e3b5b1..01613908ba 100644 --- a/openmc/checkvalue.py +++ b/openmc/checkvalue.py @@ -81,3 +81,57 @@ def check_value(name, value, accepted_values): msg = 'Unable to set {0} to {1} since it is not in {2}'.format( name, value, accepted_values) raise ValueError(msg) + +def check_less_than(name, value, maximum, equality=False): + """Ensure that an object's value is less than a given value. + + Parameters + ---------- + name : str + Description of the value being checked + value : object + Object to check + maximum : object + Maximum value to check against + equality : bool, optional + Whether equality is allowed. Defaluts to False. + + """ + + if equality: + if value > maximum: + msg = 'Unable to set {0} to {1} since it is greater than ' \ + '{2}'.format(name, value, maximum) + raise ValueError(msg) + else: + if value >= maximum: + msg = 'Unable to set {0} to {1} since it is greater than ' \ + 'or equal to {2}'.format(name, value, maximum) + raise ValueError(msg) + +def check_greater_than(name, value, minimum, equality=False): + """Ensure that an object's value is less than a given value. + + Parameters + ---------- + name : str + Description of the value being checked + value : object + Object to check + minimum : object + Minimum value to check against + equality : bool, optional + Whether equality is allowed. Defaluts to False. + + """ + + if equality: + if value < minimum: + msg = 'Unable to set {0} to {1} since it is less than ' \ + '{2}'.format(name, value, minimum) + raise ValueError(msg) + else: + if value <= minimum: + msg = 'Unable to set {0} to {1} since it is less than ' \ + 'or equal to {2}'.format(name, value, minimum) + raise ValueError(msg) diff --git a/openmc/cmfd.py b/openmc/cmfd.py index 76a44aba33..c247719c94 100644 --- a/openmc/cmfd.py +++ b/openmc/cmfd.py @@ -18,7 +18,8 @@ import sys import numpy as np from openmc.clean_xml import * -from openmc.checkvalue import check_type, check_length, check_value +from openmc.checkvalue import (check_type, check_length, check_value, + check_greater_than, check_less_than) if sys.version_info[0] >= 3: basestring = str @@ -135,10 +136,7 @@ class CMFDMesh(object): def energy(self, energy): check_type('CMFD mesh energy', energy, Iterable, Real) for e in energy: - if e < 0: - msg = 'Unable to set CMFD Mesh energy to {0} which is ' \ - 'is a negative integer'.format(e) - raise ValueError(msg) + check_greater_than('CMFD mesh energy', e, 0, True) self._energy = energy @albedo.setter @@ -146,20 +144,15 @@ class CMFDMesh(object): check_type('CMFD mesh albedo', albedo, Iterable, Real) check_length('CMFD mesh albedo', albedo, 6) for a in albedo: - if a < 0 or a > 1: - msg = 'Unable to set CMFD Mesh albedo to {0} which is ' \ - 'is not in [0,1]'.format(a) - raise ValueError(msg) + check_greater_than('CMFD mesh albedo', a, 0, True) + check_less_than('CMFD mesh albedo', a, 1, True) self._albedo = albedo @map.setter def map(self, meshmap): check_type('CMFD mesh map', meshmap, Iterable, Integral) for m in meshmap: - if m != 1 and m != 2: - msg = 'Unable to set CMFD Mesh map to {0} which is ' \ - 'is not 1 or 2'.format(m) - raise ValueError(msg) + check_value('CMFD mesh map', m, [1, 2]) self._map = meshmap def _get_xml_element(self): @@ -338,10 +331,7 @@ class CMFDFile(object): @begin.setter def begin(self, begin): check_type('CMFD begin batch', begin, Integral) - if begin <= 0: - msg = 'Unable to set CMFD begin batch batch to a negative ' \ - 'value {0}'.format(begin) - raise ValueError(msg) + check_greater_than('CMFD begin batch', begin, 0) self._begin = begin @dhat_reset.setter diff --git a/openmc/material.py b/openmc/material.py index 4e18ee0b05..2c10144b33 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -8,7 +8,7 @@ if sys.version_info[0] >= 3: basestring = str import openmc -from openmc.checkvalue import check_type, check_value +from openmc.checkvalue import check_type, check_value, check_greater_than from openmc.clean_xml import * @@ -125,10 +125,7 @@ class Material(object): msg = 'Unable to set Material ID to {0} since a Material with ' \ 'this ID was already initialized'.format(material_id) raise ValueError(msg) - elif material_id < 0: - msg = 'Unable to set Material ID to {0} since it must be a ' \ - 'non-negative integer'.format(material_id) - raise ValueError(msg) + check_greater_than('material ID', material_id, 0) self._id = material_id MATERIAL_IDS.append(material_id) diff --git a/openmc/mesh.py b/openmc/mesh.py index f03c61b329..1ba0f28a5b 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -4,7 +4,8 @@ from numbers import Real, Integral from xml.etree import ElementTree as ET import sys -from openmc.checkvalue import check_type, check_length, check_value +from openmc.checkvalue import (check_type, check_length, check_value, + check_greater_than) if sys.version_info[0] >= 3: basestring = str @@ -36,9 +37,9 @@ class Mesh(object): Name of the mesh type : str Type of the mesh - dimension : Sequnce of int + dimension : Iterable of int The number of mesh cells in each direction. - lower_left : Seuqnce of float + lower_left : Iterable of float The lower-left corner of the structured mesh. If only two coordinate are given, it is assumed that the mesh is an x-y mesh. upper_right : Iterable of float @@ -142,10 +143,7 @@ class Mesh(object): AUTO_MESH_ID += 1 else: check_type('mesh ID', mesh_id, Integral) - if mesh_id < 0: - msg = 'Unable to set Mesh ID to {0} since it must be a ' \ - 'non-negative integer'.format(mesh_id) - raise ValueError(msg) + check_greater_than('mesh ID', mesh_id, 0) self._id = mesh_id @name.setter diff --git a/openmc/plots.py b/openmc/plots.py index e605786c56..44dde153ab 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -6,7 +6,8 @@ import sys import numpy as np from openmc.clean_xml import * -from openmc.checkvalue import check_type, check_value, check_length +from openmc.checkvalue import (check_type, check_value, check_length, + check_greater_than, check_less_than) if sys.version_info[0] >= 3: basestring = str @@ -143,10 +144,7 @@ class Plot(object): AUTO_PLOT_ID += 1 else: check_type('plot ID', plot_id, Integral) - if plot_id < 0: - msg = 'Unable to set Plot ID to {0} since it must be a ' \ - 'non-negative integer'.format(plot_id) - raise ValueError(msg) + check_greater_than('plot ID', plot_id, 0) self._id = plot_id @name.setter @@ -171,10 +169,7 @@ class Plot(object): check_type('plot pixels', pixels, Iterable, Integral) check_length('plot pixels', pixels, 2, 3) for dim in pixels: - if dim < 0: - msg = 'Unable to create Plot ID={0} with pixel value {1} ' \ - 'which is less than 0'.format(self._id, dim) - raise ValueError(msg) + check_greater_than('plot pixels', dim, 0) self._pixels = pixels @filename.setter @@ -205,27 +200,16 @@ class Plot(object): check_type('plot background', background, Iterable, Integral) check_length('plot background', background, 3) for rgb in background: - if rgb < 0 or rgb > 255: - msg = 'Unable to create Plot ID={0} with background RGB value ' \ - '{1} which is not between 0 and 255'.format(self._id, rgb) - raise ValueError(msg) + check_greater_than('plot background',rgb, 0, True) + check_less_than('plot background', rgb, 256) self._background = background @col_spec.setter def col_spec(self, col_spec): - if not isinstance(col_spec, dict): - msg = 'Unable to create Plot ID={0} with col_spec parameter {1} ' \ - 'which is not a Python dictionary of IDs to ' \ - 'pixels'.format(self._id, col_spec) - raise ValueError(msg) + check_type('plot col_spec parameter', col_spec, dict, Integral) for key in col_spec: - if not isinstance(key, Integral): - msg = 'Unable to create Plot ID={0} with col_spec ID {1} ' \ - 'which is not an integer'.format(self._id, key) - raise ValueError(msg) - - elif key < 0: + if key < 0: msg = 'Unable to create Plot ID={0} with col_spec ID {1} ' \ 'which is less than 0'.format(self._id, key) raise ValueError(msg) @@ -247,10 +231,7 @@ class Plot(object): def mask_components(self, mask_components): check_type('plot mask_components', mask_components, Iterable, Integral) for component in mask_components: - if component < 0: - msg = 'Unable to create Plot ID={0} with mask component {1} ' \ - 'which is less than 0'.format(self._id, component) - raise ValueError(msg) + check_greater_than('plot mask_components', component, 0, True) self._mask_components = mask_components @mask_background.setter @@ -258,11 +239,8 @@ class Plot(object): check_type('plot mask background', mask_background, Iterable, Integral) check_length('plot mask background', mask_background, 3) for rgb in mask_background: - if rgb < 0 or rgb > 255: - msg = 'Unable to create Plot ID={0} with mask bacground ' \ - 'RGB value {1} which is not between 0 and ' \ - '255'.format(self._id, rgb) - raise ValueError(msg) + check_greater_than('plot mask background', rgb, 0, True) + check_less_than('plot mask background', rgb, 256) self._mask_background = mask_background def __repr__(self): diff --git a/openmc/settings.py b/openmc/settings.py index 59b07f803a..f66987d185 100644 --- a/openmc/settings.py +++ b/openmc/settings.py @@ -7,7 +7,8 @@ import sys import numpy as np from openmc.clean_xml import * -from openmc.checkvalue import check_type, check_length, check_value +from openmc.checkvalue import (check_type, check_length, check_value, + check_greater_than, check_less_than) if sys.version_info[0] >= 3: basestring = str @@ -401,37 +402,25 @@ class SettingsFile(object): @batches.setter def batches(self, batches): check_type('batches', batches, Integral) - if batches <= 0: - msg = 'Unable to set batches to a negative ' \ - 'value {0}'.format(batches) - raise ValueError(msg) + check_greater_than('batches', batches, 0) self._batches = batches @generations_per_batch.setter def generations_per_batch(self, generations_per_batch): - check_type('generation per patch', generations_per_batch, Integral) - if generations_per_batch <= 0: - msg = 'Unable to set generations per batch to a negative ' \ - 'value {0}'.format(generations_per_batch) - raise ValueError(msg) + check_type('generations per patch', generations_per_batch, Integral) + check_greater_than('generations per batch', generations_per_batch, 0) self._generations_per_batch = generations_per_batch @inactive.setter def inactive(self, inactive): check_type('inactive batches', inactive, Integral) - if inactive <= 0: - msg = 'Unable to set inactive batches to a negative ' \ - 'value {0}'.format(inactive) - raise ValueError(msg) + check_greater_than('inactive batches', inactive, 0) self._inactive = inactive @particles.setter def particles(self, particles): check_type('particles', particles, Integral) - if particles <= 0: - msg = 'Unable to set particles to a negative ' \ - 'value {0}'.format(particles) - raise ValueError(msg) + check_greater_than('particles', particles, 0) self._particles = particles @keff_trigger.setter @@ -496,7 +485,7 @@ class SettingsFile(object): check_type('source space type', stype, basestring) check_value('source space type', stype, ['box', 'fission', 'point']) check_type('source space parameters', params, Iterable, Real) - if stype in ['box', 'fission'] and len(params) != 6: + if stype in ['box', 'fission']: check_length('source space parameters for a ' 'box/fission distribution', params, 6) elif stype == 'point': @@ -611,20 +600,15 @@ class SettingsFile(object): @verbosity.setter def verbosity(self, verbosity): check_type('verbosity', verbosity, Integral) - if verbosity < 1 or verbosity > 10: - msg = 'Unable to set verbosity to {0} which is not between ' \ - '1 and 10'.format(verbosity) - raise ValueError(msg) + check_greater_than('verbosity', verbosity, 1, True) + check_less_than('verbosity', verbosity, 10, True) self._verbosity = verbosity @statepoint_batches.setter def statepoint_batches(self, batches): check_type('statepoint batches', batches, Iterable, Integral) for batch in batches: - if batch <= 0: - msg = 'Unable to set statepoint batches with {0} which is ' \ - 'less than or equal to zero'.format(batch) - raise ValueError(msg) + check_greater_than('statepoint batch', batch, 0) self._statepoint_batches = batches @statepoint_interval.setter @@ -636,10 +620,7 @@ class SettingsFile(object): def sourcepoint_batches(self, batches): check_type('sourcepoint batches', batches, Iterable, Integral) for batch in batches: - if batch <= 0: - msg = 'Unable to set sourcepoint batches with {0} which is ' \ - 'less than or equal to zero'.format(batch) - raise ValueError(msg) + check_greater_than('sourcepoint batch', batch, 0) self._sourcepoint_batches = batches @sourcepoint_interval.setter @@ -691,9 +672,7 @@ class SettingsFile(object): @seed.setter def seed(self, seed): check_type('random number generator seed', seed, Integral) - if seed <= 0: - msg = 'Unable to set seed to non-positive integer {0}'.format(seed) - raise ValueError(msg) + check_greater_than('random number generator seed', seed, 0) self._seed = seed @survival_biasing.setter @@ -704,19 +683,13 @@ class SettingsFile(object): @weight.setter def weight(self, weight): check_type('weight cutoff', weight, Real) - if weight < 0.0: - msg = 'Unable to set weight cutoff to negative ' \ - 'value {0}'.format(weight) - raise ValueError(msg) + check_greater_than('weight cutoff', weight, 0.0) self._weight = weight @weight_avg.setter def weight_avg(self, weight_avg): check_type('average survival weight', weight_avg, Real) - if weight_avg < 0.0: - msg = 'Unable to set weight avg. to negative ' \ - 'value {0}'.format(weight_avg) - raise ValueError(msg) + check_greater_than('average survival weight', weight_avg, 0.0) self._weight_avg = weight_avg @entropy_dimension.setter @@ -747,19 +720,13 @@ class SettingsFile(object): @trigger_max_batches.setter def trigger_max_batches(self, trigger_max_batches): check_type('trigger maximum batches', trigger_max_batches, Integral) - if trigger_max_batches <= 0: - msg = 'Unable to set trigger max batches to a non-positive ' \ - 'value {0}'.format(trigger_max_batches) - raise ValueError(msg) + check_greater_than('trigger maximum batches', trigger_max_batches, 0) self._trigger_max_batches = trigger_max_batches @trigger_batch_interval.setter def trigger_batch_interval(self, trigger_batch_interval): check_type('trigger batch interval', trigger_batch_interval, Integral) - if trigger_batch_interval <= 0: - msg = 'Unable to set trigger batch interval to a non-positive ' \ - 'value {0}'.format(trigger_batch_interval) - raise ValueError(msg) + check_greater_than('trigger batch interval', trigger_batch_interval, 0) self._trigger_batch_interval = trigger_batch_interval @no_reduce.setter @@ -770,28 +737,16 @@ class SettingsFile(object): @threads.setter def threads(self, threads): check_type('number of threads', threads, Integral) - if threads <= 0: - msg = 'Unable to set the threads to a negative ' \ - 'value {0}'.format(threads) - raise ValueError(msg) + check_greater_than('number of threads', threads, 0) self._threads = threads @trace.setter def trace(self, trace): check_type('trace', trace, Iterable, Integral) check_length('trace', trace, 3) - if trace[0] < 1: - msg = 'Unable to set the trace batch to {0} since it must be ' \ - 'greater than or equal to 1'.format(trace[0]) - raise ValueError(msg) - elif trace[1] < 1: - msg = 'Unable to set the trace generation to {0} since it ' \ - 'must be greater than or equal to 1'.format(trace[1]) - raise ValueError(msg) - elif trace[2] < 1: - msg = 'Unable to set the trace particle to {0} since it ' \ - 'must be greater than or equal to 1'.format(trace[2]) - raise ValueError(msg) + check_greater_than('trace batch', trace[0], 0) + check_greater_than('trace generation', trace[1], 0) + check_greater_than('trace particle', trace[2], 0) self._trace = trace @track.setter @@ -802,18 +757,9 @@ class SettingsFile(object): 'not a multiple of 3'.format(track) raise ValueError(msg) for t in zip(track[::3], track[1::3], track[2::3]): - if t[0] < 1: - msg = 'Unable to set the track batch to {0} since it must be ' \ - 'greater than or equal to 1'.format(t[0]) - raise ValueError(msg) - elif t[1] < 1: - msg = 'Unable to set the track generation to {0} since it must ' \ - 'be greater than or equal to 1'.format(t[1]) - raise ValueError(msg) - elif t[2] < 1: - msg = 'Unable to set the track particle to {0} since it must ' \ - 'be greater than or equal to 1'.format(t[2]) - raise ValueError(msg) + check_greater_than('track batch', t[0], 0) + check_greater_than('track generation', t[0], 0) + check_greater_than('track particle', t[0], 0) self._track = track @ufs_dimension.setter @@ -821,10 +767,7 @@ class SettingsFile(object): check_type('UFS mesh dimension', dimension, Iterable, Integral) check_length('UFS mesh dimension', dimension, 3) for dim in dimension: - if dim < 1: - msg = 'Unable to set UFS dimension to value {0} which is ' \ - 'less than one'.format(dimension) - raise ValueError(msg) + check_greater_than('UFS mesh dimension', dim, 1, True) self._ufs_dimension = dimension @ufs_lower_left.setter diff --git a/openmc/surface.py b/openmc/surface.py index 527bf17917..d5d258fa7a 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -3,7 +3,7 @@ from numbers import Real, Integral from xml.etree import ElementTree as ET import sys -from openmc.checkvalue import check_type, check_value +from openmc.checkvalue import check_type, check_value, check_greater_than from openmc.constants import BC_TYPES if sys.version_info[0] >= 3: @@ -95,10 +95,7 @@ class Surface(object): AUTO_SURFACE_ID += 1 else: check_type('surface ID', surface_id, Integral) - if surface_id < 0: - msg = 'Unable to set Surface ID to {0} since it must be a ' \ - 'non-negative integer'.format(surface_id) - raise ValueError(msg) + check_greater_than('surface ID', surface_id, 0) self._id = surface_id @name.setter @@ -547,7 +544,7 @@ class YCylinder(Cylinder): @z0.setter def z0(self, z0): - check_type('y0 coefficient', y0, Real) + check_type('z0 coefficient', z0, Real) self._coeffs['z0'] = z0 diff --git a/openmc/tallies.py b/openmc/tallies.py index be6905d1a6..ec68de8e5c 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -11,7 +11,7 @@ import numpy as np from openmc import Mesh, Filter, Trigger, Nuclide from openmc.summary import Summary -from openmc.checkvalue import check_type, check_value +from openmc.checkvalue import check_type, check_value, check_greater_than from openmc.clean_xml import * @@ -305,10 +305,7 @@ class Tally(object): AUTO_TALLY_ID += 1 else: check_type('tally ID', tally_id, Integral) - if tally_id < 0: - msg = 'Unable to set Tally ID to {0} since it must be a ' \ - 'non-negative integer'.format(tally_id) - raise ValueError(msg) + check_greater_than('tally ID', tally_id, 0) self._id = tally_id @name.setter @@ -373,11 +370,7 @@ class Tally(object): @num_realizations.setter def num_realizations(self, num_realizations): check_type('number of realizations', num_realizations, Integral) - if num_realizations < 0: - msg = 'Unable to set the number of realizations to "{0}" for ' \ - 'Tally ID={1} since it is a negative ' \ - 'value'.format(num_realizations) - raise ValueError(msg) + check_greater_than('number of realizations', num_realizations, 0, True) self._num_realizations = num_realizations @with_summary.setter @@ -1311,7 +1304,7 @@ class Tally(object): elif not isinstance(append, bool): msg = 'Unable to export the results for Tally ID={0} since the ' \ - 'append parameters is not True/False'.format(self.id, append) + 'append parameter is not True/False'.format(self.id, append) raise ValueError(msg) # Make directory if it does not exist diff --git a/openmc/universe.py b/openmc/universe.py index e72c9f4781..e7d34a030d 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -7,7 +7,7 @@ import sys import numpy as np import openmc -from openmc.checkvalue import check_type, check_length +from openmc.checkvalue import check_type, check_length, check_greater_than if sys.version_info[0] >= 3: basestring = str @@ -112,10 +112,7 @@ class Cell(object): AUTO_CELL_ID += 1 else: check_type('cell ID', cell_id, Integral) - if cell_id < 0: - msg = 'Unable to set Cell ID to {0} since it must be a ' \ - 'non-negative integer'.format(cell_id) - raise ValueError(msg) + check_greater_than('cell ID', cell_id, 0) self._id = cell_id @name.setter @@ -436,10 +433,7 @@ class Universe(object): AUTO_UNIVERSE_ID += 1 else: check_type('universe ID', universe_id, Integral) - if universe_id < 0: - msg = 'Unable to set Universe ID to {0} since it must be a ' \ - 'non-negative integer'.format(universe_id) - raise ValueError(msg) + check_greater_than('universe ID', universe_id, 0, True) self._id = universe_id @name.setter @@ -678,10 +672,7 @@ class Lattice(object): AUTO_UNIVERSE_ID += 1 else: check_type('lattice ID', lattice_id, Integral) - if lattice_id < 0: - msg = 'Unable to set Lattice ID to {0} since it must be a ' \ - 'non-negative integer'.format(lattice_id) - raise ValueError(msg) + check_greater_than('lattice ID', lattice_id, 0) self._id = lattice_id @name.setter @@ -837,10 +828,7 @@ class RectLattice(Lattice): check_type('lattice dimension', dimension, Iterable, Integral) check_length('lattice dimension', dimension, 2, 3) for dim in dimension: - if dim < 0: - msg = 'Unable to set RectLattice ID={0} dimension to {1} ' \ - 'since it is a negative value'.format(self._id, dim) - raise ValueError(msg) + check_greater_than('lattice dimension', dim, 0) self._dimension = dimension @lower_left.setter @@ -859,10 +847,7 @@ class RectLattice(Lattice): check_type('lattice pitch', pitch, Iterable, Real) check_length('lattice pitch', pitch, 2, 3) for dim in pitch: - if dim < 0: - msg = 'Unable to set Lattice ID={0} pitch to {1} since it ' \ - 'is a negative value'.format(self._id, dim) - raise ValueError(msg) + check_greater_than('lattice pitch', dim, 0.0) self._pitch = pitch def get_offset(self, path, filter_offset): @@ -1055,20 +1040,14 @@ class HexLattice(Lattice): @num_rings.setter def num_rings(self, num_rings): - if not isinstance(num_rings, Integral) and num_rings < 1: - msg = 'Unable to set HexLattice ID={0} number of rings to {1} ' \ - 'since it is not a positive integer'.format(self._id, num_rings) - raise ValueError(msg) - + check_type('number of rings', num_rings, Integral) + check_greater_than('number of rings', num_rings, 0) self._num_rings = num_rings @num_axial.setter def num_axial(self, num_axial): - if not isinstance(num_axial, Integral) and num_axial < 1: - msg = 'Unable to set HexLattice ID={0} number of axial to {1} ' \ - 'since it is not a positive integer'.format(self._id, num_axial) - raise ValueError(msg) - + check_type('number of axial', num_axial, Integral) + check_greater_than('number of axial', num_axial, 0) self._num_axial = num_axial @center.setter @@ -1082,10 +1061,7 @@ class HexLattice(Lattice): check_type('lattice pitch', pitch, Iterable, Real) check_length('lattice pitch', pitch, 2, 3) for dim in pitch: - if dim < 0: - msg = 'Unable to set Lattice ID={0} pitch to {1} since it ' \ - 'is a negative value'.format(self._id, dim) - raise ValueError(msg) + check_greater_than('lattice pitch', dim, 0) self._pitch = pitch @Lattice.universes.setter