mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Merge pull request #404 from paulromano/pyapi-type-checks
Improve checks for property setters in Python API
This commit is contained in:
commit
c5cc890df6
16 changed files with 583 additions and 1604 deletions
|
|
@ -108,7 +108,7 @@ energy_filter = openmc.Filter(type='energy', bins=[0., 20.])
|
|||
energyout_filter = openmc.Filter(type='energyout', bins=[0., 20.])
|
||||
|
||||
# Instantiate the first Tally
|
||||
first_tally = openmc.Tally(tally_id=1, label='first tally')
|
||||
first_tally = openmc.Tally(tally_id=1, name='first tally')
|
||||
first_tally.add_filter(cell_filter)
|
||||
scores = ['total', 'scatter', 'nu-scatter', \
|
||||
'absorption', 'fission', 'nu-fission']
|
||||
|
|
@ -116,7 +116,7 @@ for score in scores:
|
|||
first_tally.add_score(score)
|
||||
|
||||
# Instantiate the second Tally
|
||||
second_tally = openmc.Tally(tally_id=2, label='second tally')
|
||||
second_tally = openmc.Tally(tally_id=2, name='second tally')
|
||||
second_tally.add_filter(cell_filter)
|
||||
second_tally.add_filter(energy_filter)
|
||||
scores = ['total', 'scatter', 'nu-scatter', \
|
||||
|
|
@ -125,7 +125,7 @@ for score in scores:
|
|||
second_tally.add_score(score)
|
||||
|
||||
# Instantiate the third Tally
|
||||
third_tally = openmc.Tally(tally_id=3, label='third tally')
|
||||
third_tally = openmc.Tally(tally_id=3, name='third tally')
|
||||
third_tally.add_filter(cell_filter)
|
||||
third_tally.add_filter(energy_filter)
|
||||
third_tally.add_filter(energyout_filter)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,137 @@
|
|||
import numpy as np
|
||||
def check_type(name, value, expected_type, expected_iter_type=None):
|
||||
"""Ensure that an object is of an expected type. Optionally, if the object is
|
||||
iterable, check that each element is of a particular type.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
Description of value being checked
|
||||
value : object
|
||||
Object to check type of
|
||||
expected_type : type
|
||||
type to check object against
|
||||
expected_iter_type : type or None, optional
|
||||
Expected type of each element in value, assuming it is iterable. If
|
||||
None, no check will be performed.
|
||||
|
||||
"""
|
||||
|
||||
if not isinstance(value, expected_type):
|
||||
msg = 'Unable to set {0} to {1} which is not of type {2}'.format(
|
||||
name, value, expected_type.__name__)
|
||||
raise ValueError(msg)
|
||||
|
||||
if expected_iter_type:
|
||||
for item in value:
|
||||
if not isinstance(item, expected_iter_type):
|
||||
msg = 'Unable to set {0} to {1} since each item must be ' \
|
||||
'of type {2}'.format(name, value,
|
||||
expected_iter_type.__name__)
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
def is_integer(val):
|
||||
return isinstance(val, (int, np.int32, np.int64))
|
||||
def check_length(name, value, length_min, length_max=None):
|
||||
"""Ensure that a sized object has length within a given range.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
Description of value being checked
|
||||
value : collections.Sized
|
||||
Object to check length of
|
||||
length_min : int
|
||||
Minimum length of object
|
||||
length_max : int or None, optional
|
||||
Maximum length of object. If None, it is assumed object must be of
|
||||
length length_min.
|
||||
|
||||
"""
|
||||
|
||||
if length_max is None:
|
||||
if len(value) != length_min:
|
||||
msg = 'Unable to set {0} to {1} since it must be of ' \
|
||||
'length {2}'.format(name, value, length_min)
|
||||
raise ValueError(msg)
|
||||
elif not length_min <= len(value) <= length_max:
|
||||
if length_min == length_max:
|
||||
msg = 'Unable to set {0} to {1} since it must be of ' \
|
||||
'length {2}'.format(name, value, length_min)
|
||||
else:
|
||||
msg = 'Unable to set {0} to {1} since it must have length ' \
|
||||
'between {2} and {3}'.format(name, value, length_min,
|
||||
length_max)
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
def is_float(val):
|
||||
return isinstance(val, (float, np.float32, np.float64))
|
||||
def check_value(name, value, accepted_values):
|
||||
"""Ensure that an object's value is contained in a set of acceptable values.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
Description of value being checked
|
||||
value : collections.Iterable
|
||||
Object to check
|
||||
accepted_values : collections.Container
|
||||
Container of acceptable values
|
||||
|
||||
def is_string(val):
|
||||
return isinstance(val, (str, np.str))
|
||||
"""
|
||||
|
||||
if value not in 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)
|
||||
|
|
|
|||
287
openmc/cmfd.py
287
openmc/cmfd.py
|
|
@ -10,12 +10,19 @@ References
|
|||
|
||||
"""
|
||||
|
||||
from collections import Iterable
|
||||
from numbers import Real, Integral
|
||||
from xml.etree import ElementTree as ET
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
from openmc.checkvalue import *
|
||||
from openmc.clean_xml import *
|
||||
from openmc.checkvalue import (check_type, check_length, check_value,
|
||||
check_greater_than, check_less_than)
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
|
||||
class CMFDMesh(object):
|
||||
|
|
@ -24,26 +31,26 @@ class CMFDMesh(object):
|
|||
|
||||
Attributes
|
||||
----------
|
||||
lower_left : tuple or list or ndarray
|
||||
lower_left : Iterable of float
|
||||
The lower-left corner of the structured mesh. If only two coordinates are
|
||||
given, it is assumed that the mesh is an x-y mesh.
|
||||
upper_right : tuple or list or ndarray
|
||||
upper_right : Iterable of float
|
||||
The upper-right corner of the structrued mesh. If only two coordinates
|
||||
are given, it is assumed that the mesh is an x-y mesh.
|
||||
dimension : tuple or list or ndarray
|
||||
dimension : Iterable of int
|
||||
The number of mesh cells in each direction.
|
||||
width : tuple or list or ndarray
|
||||
width : Iterable of float
|
||||
The width of mesh cells in each direction.
|
||||
energy : tuple or list or ndarray
|
||||
energy : Iterable of float
|
||||
Energy bins in MeV, listed in ascending order (e.g. [0.0, 0.625e-7,
|
||||
20.0]) for CMFD tallies and acceleration. If no energy bins are listed,
|
||||
OpenMC automatically assumes a one energy group calculation over the
|
||||
entire energy range.
|
||||
albedo : tuple or list or ndarray
|
||||
albedo : Iterable of float
|
||||
Surface ratio of incoming to outgoing partial currents on global
|
||||
boundary conditions. They are listed in the following order: -x +x -y +y
|
||||
-z +z.
|
||||
map : tuple or list or ndarray
|
||||
map : Iterable of int
|
||||
An optional acceleration map can be specified to overlay on the coarse
|
||||
mesh spatial grid. If this option is used, a ``1`` is used for a
|
||||
non-accelerated region and a ``2`` is used for an accelerated region.
|
||||
|
|
@ -103,144 +110,50 @@ class CMFDMesh(object):
|
|||
|
||||
@lower_left.setter
|
||||
def lower_left(self, lower_left):
|
||||
if not isinstance(lower_left, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set CMFD Mesh with lower_left {0} which is ' \
|
||||
'not a Python list, tuple or NumPy array'.format(lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(lower_left) != 2 and len(lower_left) != 3:
|
||||
msg = 'Unable to set CMFD Mesh with lower_left {0} since it ' \
|
||||
'must include 2 or 3 dimensions'.format(lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
for coord in lower_left:
|
||||
if not is_integer(coord) and not is_float(coord):
|
||||
msg = 'Unable to set CMFD Mesh with lower_left {0} which is ' \
|
||||
'not an integer or a floating point value'.format(coord)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD mesh lower_left', lower_left, Iterable, Real)
|
||||
check_length('CMFD mesh lower_left', lower_left, 2, 3)
|
||||
self._lower_left = lower_left
|
||||
|
||||
@upper_right.setter
|
||||
def upper_right(self, upper_right):
|
||||
|
||||
if not isinstance(upper_right, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set CMFD Mesh with upper_right {0} which is ' \
|
||||
'not a Python list, tuple or NumPy array'.format(upper_right)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(upper_right) != 2 and len(upper_right) != 3:
|
||||
msg = 'Unable to set CMFD Mesh with upper_right {0} since it ' \
|
||||
'must include 2 or 3 dimensions'.format(upper_right)
|
||||
raise ValueError(msg)
|
||||
|
||||
for coord in upper_right:
|
||||
if not is_integer(coord) and not is_float(coord):
|
||||
msg = 'Unable to set CMFD Mesh with upper_right {0} which ' \
|
||||
'is not an integer or floating point value'.format(coord)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD mesh upper_right', upper_right, Iterable, Real)
|
||||
check_length('CMFD mesh upper_right', upper_right, 2, 3)
|
||||
self._upper_right = upper_right
|
||||
|
||||
@dimension.setter
|
||||
def dimension(self, dimension):
|
||||
if not isinstance(dimension, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set CMFD Mesh with dimension {0} which is ' \
|
||||
'not a Python list, tuple or NumPy array'.format(dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(dimension) != 2 and len(dimension) != 3:
|
||||
msg = 'Unable to set CMFD Mesh with dimension {0} since it ' \
|
||||
'must include 2 or 3 dimensions'.format(dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in dimension:
|
||||
if not is_integer(dim):
|
||||
msg = 'Unable to set CMFD Mesh with dimension {0} which ' \
|
||||
'is a non-integer'.format(dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD mesh dimension', dimension, Iterable, Integral)
|
||||
check_length('CMFD mesh dimension', dimension, 2, 3)
|
||||
self._dimension = dimension
|
||||
|
||||
@width.setter
|
||||
def width(self, width):
|
||||
if width is not None:
|
||||
if not isinstance(width, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set CMFD Mesh with width {0} which ' \
|
||||
'is not a Python list, tuple or NumPy array'.format(width)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(width) != 2 and len(width) != 3:
|
||||
msg = 'Unable to set CMFD Mesh with width {0} since it must ' \
|
||||
'include 2 or 3 dimensions'.format(width)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in width:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to set CMFD Mesh with width {0} which is ' \
|
||||
'not an integer or floating point value'.format(width)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD mesh width', width, Iterable, Real)
|
||||
check_length('CMFD mesh width', width, 2, 3)
|
||||
self._width = width
|
||||
|
||||
@energy.setter
|
||||
def energy(self, energy):
|
||||
if not isinstance(energy, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set CMFD Mesh energy to {0} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(energy)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD mesh energy', energy, Iterable, Real)
|
||||
for e in energy:
|
||||
if not is_integer(e) and not is_float(e):
|
||||
msg = 'Unable to set CMFD Mesh energy to {0} which is not ' \
|
||||
'an integer or floating point value'.format(e)
|
||||
raise ValueError(msg)
|
||||
elif 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
|
||||
def albedo(self, albedo):
|
||||
if not isinstance(albedo, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set CMFD Mesh albedo to {0} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(albedo)
|
||||
raise ValueError(msg)
|
||||
|
||||
if not len(albedo) == 6:
|
||||
msg = 'Unable to set CMFD Mesh albedo to {0} which is not ' \
|
||||
'length 6 for +/-x,y,z'.format(albedo)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD mesh albedo', albedo, Iterable, Real)
|
||||
check_length('CMFD mesh albedo', albedo, 6)
|
||||
for a in albedo:
|
||||
if not is_integer(a) and not is_float(a):
|
||||
msg = 'Unable to set CMFD Mesh albedo to {0} which is not ' \
|
||||
'an integer or floating point value'.format(a)
|
||||
raise ValueError(msg)
|
||||
elif 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, map):
|
||||
|
||||
if not isinstance(map, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set CMFD Mesh map to {0} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(map)
|
||||
raise ValueError(msg)
|
||||
|
||||
for m in map:
|
||||
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)
|
||||
|
||||
self._map = map
|
||||
def map(self, meshmap):
|
||||
check_type('CMFD mesh map', meshmap, Iterable, Integral)
|
||||
for m in meshmap:
|
||||
check_value('CMFD mesh map', m, [1, 2])
|
||||
self._map = meshmap
|
||||
|
||||
def _get_xml_element(self):
|
||||
element = ET.Element("mesh")
|
||||
|
|
@ -301,7 +214,7 @@ class CMFDFile(object):
|
|||
feedback : bool
|
||||
Indicate or not the CMFD diffusion result is used to adjust the weight
|
||||
of fission source neutrons on the next OpenMC batch. Defaults to False.
|
||||
gauss_seidel_tolerance : tuple or list or ndarray of float
|
||||
gauss_seidel_tolerance : Iterable of float
|
||||
Two parameters specifying the absolute inner tolerance and the relative
|
||||
inner tolerance for Gauss-Seidel iterations when performing CMFD.
|
||||
ktol : float
|
||||
|
|
@ -417,175 +330,87 @@ class CMFDFile(object):
|
|||
|
||||
@begin.setter
|
||||
def begin(self, begin):
|
||||
if not is_integer(begin):
|
||||
msg = 'Unable to set CMFD begin batch to a non-integer ' \
|
||||
'value {0}'.format(begin)
|
||||
raise ValueError(msg)
|
||||
|
||||
if begin <= 0:
|
||||
msg = 'Unable to set CMFD begin batch batch to a negative ' \
|
||||
'value {0}'.format(begin)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD begin batch', begin, Integral)
|
||||
check_greater_than('CMFD begin batch', begin, 0)
|
||||
self._begin = begin
|
||||
|
||||
@dhat_reset.setter
|
||||
def dhat_reset(self, dhat_reset):
|
||||
if not isinstance(dhat_reset, bool):
|
||||
msg = 'Unable to set Dhat reset to {0} which is ' \
|
||||
'a non-boolean value'.format(dhat_reset)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD Dhat reset', dhat_reset, bool)
|
||||
self._dhat_reset = dhat_reset
|
||||
|
||||
@display.setter
|
||||
def display(self, display):
|
||||
if not is_string(display):
|
||||
msg = 'Unable to set CMFD display to a non-string ' \
|
||||
'value'.format(display)
|
||||
raise ValueError(msg)
|
||||
|
||||
if display not in ['balance', 'dominance', 'entropy', 'source']:
|
||||
msg = 'Unable to set CMFD display to {0} which is ' \
|
||||
'not an accepted value'.format(display)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD display', display, basestring)
|
||||
check_value('CMFD display', display,
|
||||
['balance', 'dominance', 'entropy', 'source'])
|
||||
self._display = display
|
||||
|
||||
@downscatter.setter
|
||||
def downscatter(self, downscatter):
|
||||
if not isinstance(downscatter, bool):
|
||||
msg = 'Unable to set downscatter to {0} which is ' \
|
||||
'a non-boolean value'.format(downscatter)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD downscatter', downscatter, bool)
|
||||
self._downscatter = downscatter
|
||||
|
||||
@feedback.setter
|
||||
def feedback(self, feedback):
|
||||
if not isinstance(feedback, bool):
|
||||
msg = 'Unable to set CMFD feedback to {0} which is ' \
|
||||
'a non-boolean value'.format(feedback)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD feedback', feedback, bool)
|
||||
self._feedback = feedback
|
||||
|
||||
@gauss_seidel_tolerance.setter
|
||||
def gauss_seidel_tolerance(self, gauss_seidel_tolerance):
|
||||
if not isinstance(gauss_seidel_tolerance, (float, list, np.ndarray)):
|
||||
msg = 'Unable to set Gauss-Seidel tolerance to {0} which is ' \
|
||||
'not a Python tuple/list or NumPy array'.format(
|
||||
gauss_seidel_tolerance)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(gauss_seidel_tolerance) != 2:
|
||||
msg = 'Unable to set Gauss-Seidel tolerance with {0} since ' \
|
||||
'it must be of length 2'.format(width)
|
||||
raise ValueError(msg)
|
||||
|
||||
for t in gauss_seidel_tolerance:
|
||||
if not is_integer(t) and not is_float(t):
|
||||
msg = 'Unable to set Gauss-Seidel tolerance with {0} which ' \
|
||||
'is not an integer or floating point value'.format(t)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD Gauss-Seidel tolerance', gauss_seidel_tolerance,
|
||||
Iterable, Real)
|
||||
check_length('Gauss-Seidel tolerance', gauss_seidel_tolerance, 2)
|
||||
self._gauss_seidel_tolerance = gauss_seidel_tolerance
|
||||
|
||||
@ktol.setter
|
||||
def ktol(self, ktol):
|
||||
if not is_integer(ktol) and not is_float(ktol):
|
||||
msg = 'Unable to set the eigenvalue tolerance to {0} which is ' \
|
||||
'not an integer or floating point value'.format(ktol)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD eigenvalue tolerance', ktol, Real)
|
||||
self._ktol = ktol
|
||||
|
||||
@cmfd_mesh.setter
|
||||
def cmfd_mesh(self, mesh):
|
||||
if not isinstance(mesh, CMFDMesh):
|
||||
msg = 'Unable to set CMFD mesh to {0} which is not a ' \
|
||||
'CMFDMesh object'.format(mesh)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD mesh', mesh, CMFDMesh)
|
||||
self._mesh = mesh
|
||||
|
||||
@norm.setter
|
||||
def norm(self, norm):
|
||||
if not is_integer(norm) and not is_float(norm):
|
||||
msg = 'Unable to set the CMFD norm to {0} which is not ' \
|
||||
'an integer or floating point value'.format(norm)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD norm', norm, Real)
|
||||
self._norm = norm
|
||||
|
||||
@power_monitor.setter
|
||||
def power_monitor(self, power_monitor):
|
||||
if not isinstance(power_monitor, bool):
|
||||
msg = 'Unable to set CMFD power monitor to {0} which is a ' \
|
||||
'non-boolean value'.format(power_monitor)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD power monitor', power_monitor, bool)
|
||||
self._power_monitor = power_monitor
|
||||
|
||||
@run_adjoint.setter
|
||||
def run_adjoint(self, run_adjoint):
|
||||
if not isinstance(run_adjoint, bool):
|
||||
msg = 'Unable to set CMFD run adjoint to {0} which is a ' \
|
||||
'non-boolean value'.format(run_adjoint)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD run adjoint', run_adjoint, bool)
|
||||
self._run_adjoint = run_adjoint
|
||||
|
||||
@shift.setter
|
||||
def shift(self, shift):
|
||||
if not is_integer(shift) and not is_float(shift):
|
||||
msg = 'Unable to set the Wielandt shift to {0} which is ' \
|
||||
'not an integer or floating point value'.format(shift)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD Wielandt shift', shift, Real)
|
||||
self._shift = shift
|
||||
|
||||
@spectral.setter
|
||||
def spectral(self, spectral):
|
||||
if not is_integer(spectral) and not is_float(spectral):
|
||||
msg = 'Unable to set the spectral radius to {0} which is ' \
|
||||
'not an integer or floating point value'.format(spectral)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD spectral radius', spectral, Real)
|
||||
self._spectral = spectral
|
||||
|
||||
@stol.setter
|
||||
def stol(self, stol):
|
||||
if not is_integer(stol) and not is_float(stol):
|
||||
msg = 'Unable to set the fission source tolerance to {0} which ' \
|
||||
'is not an integer or floating point value'.format(stol)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD fission source tolerance', stol, Real)
|
||||
self._stol = stol
|
||||
|
||||
@tally_reset.setter
|
||||
def tally_reset(self, tally_reset):
|
||||
if not isinstance(tally_reset, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set tally reset batches to {0} which is ' \
|
||||
'not a Python tuple/list or NumPy array'.format(
|
||||
tally_reset)
|
||||
raise ValueError(msg)
|
||||
|
||||
for t in tally_reset:
|
||||
if not is_integer(t):
|
||||
msg = 'Unable to set tally reset batch to {0} which ' \
|
||||
'is not an integer'.format(t)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('tally reset batches', tally_reset, Iterable, Integral)
|
||||
self._tally_reset = tally_reset
|
||||
|
||||
@write_matrices.setter
|
||||
def write_matrices(self, write_matrices):
|
||||
if not isinstance(write_matrices, bool):
|
||||
msg = 'Unable to set CMFD write matrices to {0} which is a ' \
|
||||
'non-boolean value'.format(write_matrices)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('CMFD write matrices', write_matrices, bool)
|
||||
self._write_matrices = write_matrices
|
||||
|
||||
def _create_begin_subelement(self):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
from openmc.checkvalue import *
|
||||
import sys
|
||||
|
||||
from openmc.checkvalue import check_type
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
|
||||
class Element(object):
|
||||
|
|
@ -59,20 +64,12 @@ class Element(object):
|
|||
|
||||
@xs.setter
|
||||
def xs(self, xs):
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to set cross-section identifier xs for Element ' \
|
||||
'with a non-string value {0}'.format(xs)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('cross section identifier', xs, basestring)
|
||||
self._xs = xs
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Element with a non-string ' \
|
||||
'value {0}'.format(name)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('name', name, basestring)
|
||||
self._name = name
|
||||
|
||||
def __repr__(self):
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
from __future__ import print_function
|
||||
import subprocess
|
||||
from numbers import Integral
|
||||
import os
|
||||
import sys
|
||||
|
||||
from openmc.checkvalue import *
|
||||
from openmc.checkvalue import check_type
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
|
||||
class Executor(object):
|
||||
|
|
@ -39,12 +44,9 @@ class Executor(object):
|
|||
|
||||
@working_directory.setter
|
||||
def working_directory(self, working_directory):
|
||||
if not is_string(working_directory):
|
||||
msg = 'Unable to set Executor\'s working directory to {0} ' \
|
||||
'since it is not a string'.format(working_directory)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not os.path.isdir(working_directory):
|
||||
check_type("Executor's working directory", working_directory,
|
||||
basestring)
|
||||
if not os.path.isdir(working_directory):
|
||||
msg = 'Unable to set Executor\'s working directory to {0} ' \
|
||||
'which does not exist'.format(working_directory)
|
||||
raise ValueError(msg)
|
||||
|
|
@ -83,22 +85,22 @@ class Executor(object):
|
|||
post_args = ' '
|
||||
pre_args = ''
|
||||
|
||||
if is_integer(particles) and particles > 0:
|
||||
if isinstance(particles, Integral) and particles > 0:
|
||||
post_args += '-n {0} '.format(particles)
|
||||
|
||||
if is_integer(threads) and threads > 0:
|
||||
if isinstance(threads, Integral) and threads > 0:
|
||||
post_args += '-s {0} '.format(threads)
|
||||
|
||||
if geometry_debug:
|
||||
post_args += '-g '
|
||||
|
||||
if is_string(restart_file):
|
||||
if isinstance(restart_file, basestring):
|
||||
post_args += '-r {0} '.format(restart_file)
|
||||
|
||||
if tracks:
|
||||
post_args += '-t'
|
||||
|
||||
if is_integer(mpi_procs) and mpi_procs > 1:
|
||||
if isinstance(mpi_procs, Integral) and mpi_procs > 1:
|
||||
pre_args += 'mpirun -n {0} '.format(mpi_procs)
|
||||
|
||||
command = pre_args + 'openmc ' + post_args
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
from collections import Iterable
|
||||
import copy
|
||||
from numbers import Real, Integral
|
||||
|
||||
import numpy as np
|
||||
|
||||
from openmc import Mesh
|
||||
from openmc.checkvalue import *
|
||||
from openmc.constants import *
|
||||
|
||||
from openmc.checkvalue import check_type
|
||||
|
||||
class Filter(object):
|
||||
"""A filter used to constrain a tally to a specific criterion, e.g. only tally
|
||||
|
|
@ -15,7 +18,7 @@ class Filter(object):
|
|||
The type of the tally filter. Acceptable values are "universe",
|
||||
"material", "cell", "cellborn", "surface", "mesh", "energy",
|
||||
"energyout", and "distribcell".
|
||||
bins : int or list of int or list of float or ndarray
|
||||
bins : int or Iterable of int or Iterable of float
|
||||
The bins for the filter. This takes on different meaning for different
|
||||
filters.
|
||||
|
||||
|
|
@ -23,7 +26,7 @@ class Filter(object):
|
|||
----------
|
||||
type : str
|
||||
The type of the tally filter.
|
||||
bins : int or list of int or list of float or ndarray
|
||||
bins : int or Iterable of int or Iterable of float
|
||||
The bins for the filter
|
||||
|
||||
"""
|
||||
|
|
@ -122,7 +125,7 @@ class Filter(object):
|
|||
raise ValueError(msg)
|
||||
|
||||
# If the bin edge is a single value, it is a Cell, Material, etc. ID
|
||||
if not isinstance(bins, (tuple, list, np.ndarray)):
|
||||
if not isinstance(bins, Iterable):
|
||||
bins = [bins]
|
||||
|
||||
# If the bins are in a collection, convert it to a list
|
||||
|
|
@ -132,18 +135,18 @@ class Filter(object):
|
|||
if self._type in ['cell', 'cellborn', 'surface', 'material',
|
||||
'universe', 'distribcell']:
|
||||
for edge in bins:
|
||||
if not is_integer(edge):
|
||||
if not isinstance(edge, Integral):
|
||||
msg = 'Unable to add bin "{0}" to a {1} Filter since ' \
|
||||
'it is a non-integer'.format(edge, self._type)
|
||||
'it is not an integer'.format(edge, self._type)
|
||||
raise ValueError(msg)
|
||||
elif edge < 0:
|
||||
msg = 'Unable to add bin "{0}" to a {1} Filter since ' \
|
||||
'it is a negative integer'.format(edge, self._type)
|
||||
'it is negative'.format(edge, self._type)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif self._type in ['energy', 'energyout']:
|
||||
for edge in bins:
|
||||
if not is_integer(edge) and not is_float(edge):
|
||||
if not isinstance(edge, Real):
|
||||
msg = 'Unable to add bin edge "{0}" to a {1} Filter ' \
|
||||
'since it is a non-integer or floating point ' \
|
||||
'value'.format(edge, self._type)
|
||||
|
|
@ -167,7 +170,7 @@ class Filter(object):
|
|||
msg = 'Unable to add bins "{0}" to a mesh Filter since ' \
|
||||
'only a single mesh can be used per tally'.format(bins)
|
||||
raise ValueError(msg)
|
||||
elif not is_integer(bins[0]):
|
||||
elif not isinstance(bins[0], Integral):
|
||||
msg = 'Unable to add bin "{0}" to mesh Filter since it ' \
|
||||
'is a non-integer'.format(bins[0])
|
||||
raise ValueError(msg)
|
||||
|
|
@ -182,7 +185,7 @@ class Filter(object):
|
|||
# FIXME
|
||||
@num_bins.setter
|
||||
def num_bins(self, num_bins):
|
||||
if not is_integer(num_bins) or num_bins < 0:
|
||||
if not isinstance(num_bins, Integral) or num_bins < 0:
|
||||
msg = 'Unable to set the number of bins "{0}" for a {1} Filter ' \
|
||||
'since it is not a positive ' \
|
||||
'integer'.format(num_bins, self._type)
|
||||
|
|
@ -192,10 +195,7 @@ class Filter(object):
|
|||
|
||||
@mesh.setter
|
||||
def mesh(self, mesh):
|
||||
if not isinstance(mesh, Mesh):
|
||||
msg = 'Unable to set Mesh to "{0}" for Filter since it is not a ' \
|
||||
'Mesh object'.format(mesh)
|
||||
raise ValueError(msg)
|
||||
check_type('filter mesh', mesh, Mesh)
|
||||
|
||||
self._mesh = mesh
|
||||
self.type = 'mesh'
|
||||
|
|
@ -203,20 +203,12 @@ class Filter(object):
|
|||
|
||||
@offset.setter
|
||||
def offset(self, offset):
|
||||
if not is_integer(offset):
|
||||
msg = 'Unable to set offset "{0}" for a {1} Filter since it is a ' \
|
||||
'non-integer value'.format(offset, self._type)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('filter offset', offset, Integral)
|
||||
self._offset = offset
|
||||
|
||||
@stride.setter
|
||||
def stride(self, stride):
|
||||
if not is_integer(stride):
|
||||
msg = 'Unable to set stride "{0}" for a {1} Filter since it is a ' \
|
||||
'non-integer value'.format(stride, self._type)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('filter stride', stride, Integral)
|
||||
if stride < 0:
|
||||
msg = 'Unable to set stride "{0}" for a {1} Filter since it is a ' \
|
||||
'negative value'.format(stride, self._type)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from xml.etree import ElementTree as ET
|
|||
|
||||
import openmc
|
||||
from openmc.clean_xml import *
|
||||
|
||||
from openmc.checkvalue import check_type
|
||||
|
||||
def reset_auto_ids():
|
||||
openmc.reset_auto_material_id()
|
||||
|
|
@ -32,13 +32,8 @@ class Geometry(object):
|
|||
|
||||
@root_universe.setter
|
||||
def root_universe(self, root_universe):
|
||||
|
||||
if not isinstance(root_universe, openmc.Universe):
|
||||
msg = 'Unable to add root Universe {0} to Geometry since ' \
|
||||
'it is not a Universe'.format(root_universe)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif root_universe._id != 0:
|
||||
check_type('root universe', root_universe, openmc.Universe)
|
||||
if root_universe._id != 0:
|
||||
msg = 'Unable to add root Universe {0} to Geometry since ' \
|
||||
'it has ID={1} instead of ' \
|
||||
'ID=0'.format(root_universe, root_universe._id)
|
||||
|
|
@ -195,11 +190,7 @@ class GeometryFile(object):
|
|||
|
||||
@geometry.setter
|
||||
def geometry(self, geometry):
|
||||
if not isinstance(geometry, Geometry):
|
||||
msg = 'Unable to set the Geometry to {0} for the GeometryFile ' \
|
||||
'since it is not a Geometry object'.format(geometry)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('the geometry', geometry, Geometry)
|
||||
self._geometry = geometry
|
||||
|
||||
def export_to_xml(self):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
from collections import MappingView
|
||||
from collections import Iterable
|
||||
from copy import deepcopy
|
||||
from numbers import Real, Integral
|
||||
import warnings
|
||||
from xml.etree import ElementTree as ET
|
||||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
import openmc
|
||||
from openmc.checkvalue import *
|
||||
from openmc.checkvalue import check_type, check_value, check_greater_than
|
||||
from openmc.clean_xml import *
|
||||
|
||||
|
||||
|
|
@ -115,35 +119,22 @@ class Material(object):
|
|||
self._id = AUTO_MATERIAL_ID
|
||||
MATERIAL_IDS.append(AUTO_MATERIAL_ID)
|
||||
AUTO_MATERIAL_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(material_id):
|
||||
msg = 'Unable to set a non-integer Material ' \
|
||||
'ID {0}'.format(material_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif material_id in MATERIAL_IDS:
|
||||
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)
|
||||
|
||||
else:
|
||||
check_type('material ID', material_id, Integral)
|
||||
if material_id in MATERIAL_IDS:
|
||||
msg = 'Unable to set Material ID to {0} since a Material with ' \
|
||||
'this ID was already initialized'.format(material_id)
|
||||
raise ValueError(msg)
|
||||
check_greater_than('material ID', material_id, 0)
|
||||
|
||||
self._id = material_id
|
||||
MATERIAL_IDS.append(material_id)
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Material ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
else:
|
||||
self._name = name
|
||||
check_type('name for Material ID={0}'.format(self._id),
|
||||
name, basestring)
|
||||
self._name = name
|
||||
|
||||
def set_density(self, units, density=NO_DENSITY):
|
||||
"""Set the density of the material
|
||||
|
|
@ -158,15 +149,9 @@ class Material(object):
|
|||
|
||||
"""
|
||||
|
||||
if not is_float(density):
|
||||
msg = 'Unable to set the density for Material ID={0} to a ' \
|
||||
'non-floating point value {1}'.format(self._id, density)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif units not in DENSITY_UNITS:
|
||||
msg = 'Unable to set the density for Material ID={0} with ' \
|
||||
'units {1}'.format(self._id, units)
|
||||
raise ValueError(msg)
|
||||
check_type('the density for Material ID={0}'.format(self._id),
|
||||
density, Real)
|
||||
check_value('density units', units, DENSITY_UNITS)
|
||||
|
||||
if density == NO_DENSITY and units is not 'sum':
|
||||
msg = 'Unable to set the density Material ID={0} ' \
|
||||
|
|
@ -183,7 +168,7 @@ class Material(object):
|
|||
warnings.warn('This feature is not yet implemented in a release '
|
||||
'version of openmc')
|
||||
|
||||
if not is_string(filename) and filename is not None:
|
||||
if not isinstance(filename, basestring) and filename is not None:
|
||||
msg = 'Unable to add OTF material file to Material ID={0} with a ' \
|
||||
'non-string name {1}'.format(self._id, filename)
|
||||
raise ValueError(msg)
|
||||
|
|
@ -217,7 +202,7 @@ class Material(object):
|
|||
'non-Nuclide value {1}'.format(self._id, nuclide)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not is_float(percent):
|
||||
elif not isinstance(percent, Real):
|
||||
msg = 'Unable to add a Nuclide to Material ID={0} with a ' \
|
||||
'non-floating point value {1}'.format(self._id, percent)
|
||||
raise ValueError(msg)
|
||||
|
|
@ -274,7 +259,7 @@ class Material(object):
|
|||
'non-Element value {1}'.format(self._id, element)
|
||||
raise ValueError(msg)
|
||||
|
||||
if not is_float(percent):
|
||||
if not isinstance(percent, Real):
|
||||
msg = 'Unable to add an Element to Material ID={0} with a ' \
|
||||
'non-floating point value {1}'.format(self._id, percent)
|
||||
raise ValueError(msg)
|
||||
|
|
@ -315,12 +300,12 @@ class Material(object):
|
|||
|
||||
"""
|
||||
|
||||
if not is_string(name):
|
||||
if not isinstance(name, basestring):
|
||||
msg = 'Unable to add an S(a,b) table to Material ID={0} with a ' \
|
||||
'non-string table name {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
if not is_string(xs):
|
||||
if not isinstance(xs, basestring):
|
||||
msg = 'Unable to add an S(a,b) table to Material ID={0} with a ' \
|
||||
'non-string cross-section identifier {1}'.format(self._id, xs)
|
||||
raise ValueError(msg)
|
||||
|
|
@ -523,10 +508,7 @@ class MaterialsFile(object):
|
|||
|
||||
@default_xs.setter
|
||||
def default_xs(self, xs):
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to set default xs to a non-string value'.format(xs)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('default xs', xs, basestring)
|
||||
self._default_xs = xs
|
||||
|
||||
def add_material(self, material):
|
||||
|
|
@ -556,9 +538,9 @@ class MaterialsFile(object):
|
|||
|
||||
"""
|
||||
|
||||
if not isinstance(materials, (tuple, list, MappingView)):
|
||||
if not isinstance(materials, Iterable):
|
||||
msg = 'Unable to create OpenMC materials.xml file from {0} which ' \
|
||||
'is not a Python tuple/list'.format(materials)
|
||||
'is not iterable'.format(materials)
|
||||
raise ValueError(msg)
|
||||
|
||||
for material in materials:
|
||||
|
|
|
|||
134
openmc/mesh.py
134
openmc/mesh.py
|
|
@ -1,8 +1,14 @@
|
|||
from collections import Iterable
|
||||
import copy
|
||||
from numbers import Real, Integral
|
||||
from xml.etree import ElementTree as ET
|
||||
import sys
|
||||
|
||||
from openmc.checkvalue import *
|
||||
from openmc.checkvalue import (check_type, check_length, check_value,
|
||||
check_greater_than)
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
# "Static" variable for auto-generated and Mesh IDs
|
||||
AUTO_MESH_ID = 10000
|
||||
|
|
@ -31,15 +37,15 @@ class Mesh(object):
|
|||
Name of the mesh
|
||||
type : str
|
||||
Type of the mesh
|
||||
dimension : tuple or list or ndarray
|
||||
dimension : Iterable of int
|
||||
The number of mesh cells in each direction.
|
||||
lower_left : tuple or list or ndarray
|
||||
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 : tuple or list or ndarray
|
||||
upper_right : Iterable of float
|
||||
The upper-right corner of the structrued mesh. If only two coordinate
|
||||
are given, it is assumed that the mesh is an x-y mesh.
|
||||
width : tuple or list or ndarray
|
||||
width : Iterable of float
|
||||
The width of mesh cells in each direction.
|
||||
|
||||
"""
|
||||
|
|
@ -135,128 +141,46 @@ class Mesh(object):
|
|||
global AUTO_MESH_ID
|
||||
self._id = AUTO_MESH_ID
|
||||
AUTO_MESH_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(mesh_id):
|
||||
msg = 'Unable to set a non-integer Mesh ID {0}'.format(mesh_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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)
|
||||
|
||||
else:
|
||||
check_type('mesh ID', mesh_id, Integral)
|
||||
check_greater_than('mesh ID', mesh_id, 0)
|
||||
self._id = mesh_id
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Mesh ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
else:
|
||||
self._name = name
|
||||
check_type('name for mesh ID={0}'.format(self._id), name, basestring)
|
||||
self._name = name
|
||||
|
||||
@type.setter
|
||||
def type(self, type):
|
||||
if not is_string(type):
|
||||
msg = 'Unable to set Mesh ID={0} for type {1} which is not ' \
|
||||
'a string'.format(self._id, type)
|
||||
raise ValueError(msg)
|
||||
elif type not in ['rectangular', 'hexagonal']:
|
||||
msg = 'Unable to set Mesh ID={0} for type {1} which since ' \
|
||||
'only rectangular and hexagonal meshes are ' \
|
||||
'supported '.format(self._id, type)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._type = type
|
||||
def type(self, meshtype):
|
||||
check_type('type for mesh ID={0}'.format(self._id),
|
||||
meshtype, basestring)
|
||||
check_value('type for mesh ID={0}'.format(self._id),
|
||||
meshtype, ['rectangular', 'hexagonal'])
|
||||
self._type = meshtype
|
||||
|
||||
@dimension.setter
|
||||
def dimension(self, dimension):
|
||||
if not isinstance(dimension, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set Mesh ID={0} with dimension {1} which is ' \
|
||||
'not a Python list, tuple or NumPy ' \
|
||||
'array'.format(self._id, dimension)
|
||||
raise ValueError(msg)
|
||||
elif len(dimension) != 2 and len(dimension) != 3:
|
||||
msg = 'Unable to set Mesh ID={0} with dimension {1} since it ' \
|
||||
'must include 2 or 3 dimensions'.format(self._id, dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in dimension:
|
||||
if not is_integer(dim):
|
||||
msg = 'Unable to set Mesh ID={0} with dimension {1} which ' \
|
||||
'is a non-integer'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('mesh dimension', dimension, Iterable, Integral)
|
||||
check_length('mesh dimension', dimension, 2, 3)
|
||||
self._dimension = dimension
|
||||
|
||||
@lower_left.setter
|
||||
def lower_left(self, lower_left):
|
||||
if not isinstance(lower_left, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set Mesh ID={0} with lower_left {1} which is ' \
|
||||
'not a Python list, tuple or NumPy ' \
|
||||
'array'.format(self._id, lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(lower_left) != 2 and len(lower_left) != 3:
|
||||
msg = 'Unable to set Mesh ID={0} with lower_left {1} since it ' \
|
||||
'must include 2 or 3 dimensions'.format(self._id, lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
for coord in lower_left:
|
||||
if not is_integer(coord) and not is_float(coord):
|
||||
msg = 'Unable to set Mesh ID={0} with lower_left {1} which ' \
|
||||
'is neither neither an integer nor a floating point ' \
|
||||
'value'.format(self._id, coord)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('mesh lower_left', lower_left, Iterable, Real)
|
||||
check_length('mesh lower_left', lower_left, 2, 3)
|
||||
self._lower_left = lower_left
|
||||
|
||||
@upper_right.setter
|
||||
def upper_right(self, upper_right):
|
||||
if not isinstance(upper_right, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set Mesh ID={0} with upper_right {1} which ' \
|
||||
'is not a Python list, tuple or NumPy ' \
|
||||
'array'.format(self._id, upper_right)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(upper_right) != 2 and len(upper_right) != 3:
|
||||
msg = 'Unable to set Mesh ID={0} with upper_right {1} since it ' \
|
||||
'must include 2 or 3 dimensions'.format(self._id, upper_right)
|
||||
raise ValueError(msg)
|
||||
|
||||
for coord in upper_right:
|
||||
if not is_integer(coord) and not is_float(coord):
|
||||
msg = 'Unable to set Mesh ID={0} with upper_right {1} which ' \
|
||||
'is neither an integer nor a floating point ' \
|
||||
'value'.format(self._id, coord)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('mesh upper_right', upper_right, Iterable, Real)
|
||||
check_length('mesh upper_right', upper_right, 2, 3)
|
||||
self._upper_right = upper_right
|
||||
|
||||
@width.setter
|
||||
def width(self, width):
|
||||
if width is not None:
|
||||
if not isinstance(width, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set Mesh ID={0} with width {1} which ' \
|
||||
'is not a Python list, tuple or NumPy ' \
|
||||
'array'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(width) != 2 and len(width) != 3:
|
||||
msg = 'Unable to set Mesh ID={0} with width {1} since it must ' \
|
||||
'include 2 or 3 dimensions'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in width:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to set Mesh ID={0} with width {1} which is ' \
|
||||
'neither an integer nor a floating point ' \
|
||||
'value'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('mesh width', width, Iterable, Real)
|
||||
check_length('mesh width', width, 2, 3)
|
||||
self._width = width
|
||||
|
||||
def __repr__(self):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
from openmc.checkvalue import *
|
||||
from numbers import Integral
|
||||
import sys
|
||||
|
||||
from openmc.checkvalue import check_type
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
|
||||
class Nuclide(object):
|
||||
|
|
@ -68,29 +74,17 @@ class Nuclide(object):
|
|||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Nuclide with a non-string ' \
|
||||
'value {0}'.format(name)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('name', name, basestring)
|
||||
self._name = name
|
||||
|
||||
@xs.setter
|
||||
def xs(self, xs):
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to set cross-section identifier xs for Nuclide ' \
|
||||
'with a non-string value {0}'.format(xs)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('cross-section identifier', xs, basestring)
|
||||
self._xs = xs
|
||||
|
||||
@zaid.setter
|
||||
def zaid(self, zaid):
|
||||
if not is_integer(zaid):
|
||||
msg = 'Unable to set zaid for Nuclide ' \
|
||||
'with a non-integer {0}'.format(zaid)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('zaid', zaid, Integral)
|
||||
self._zaid = zaid
|
||||
|
||||
def __repr__(self):
|
||||
|
|
|
|||
238
openmc/plots.py
238
openmc/plots.py
|
|
@ -1,10 +1,16 @@
|
|||
from collections import Iterable
|
||||
from numbers import Real, Integral
|
||||
from xml.etree import ElementTree as ET
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
from openmc.checkvalue import *
|
||||
from openmc.clean_xml import *
|
||||
from openmc.checkvalue import (check_type, check_value, check_length,
|
||||
check_greater_than, check_less_than)
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
# A static variable for auto-generated Plot IDs
|
||||
AUTO_PLOT_ID = 10000
|
||||
|
|
@ -35,9 +41,9 @@ class Plot(object):
|
|||
Unique identifier
|
||||
name : str
|
||||
Name of the plot
|
||||
width : tuple or list or ndarray
|
||||
width : Iterable of float
|
||||
Width of the plot in each basis direction
|
||||
pixels : tuple or list or ndarray
|
||||
pixels : Iterable of int
|
||||
Number of pixels to use in each basis direction
|
||||
origin : tuple or list of ndarray
|
||||
Origin (center) of the plot
|
||||
|
|
@ -51,9 +57,9 @@ class Plot(object):
|
|||
The basis directions for the plot
|
||||
background : tuple or list of ndarray
|
||||
Color of the background defined by RGB
|
||||
mask_components : tuple or list or ndarray
|
||||
mask_components : Iterable of int
|
||||
Unique id numbers of the cells or materials to plot
|
||||
mask_background : tuple or list or ndarray
|
||||
mask_background : Iterable of int
|
||||
Color to apply to all cells/materials not listed in mask_components
|
||||
defined by RGB
|
||||
col_spec : dict
|
||||
|
|
@ -136,199 +142,81 @@ class Plot(object):
|
|||
global AUTO_PLOT_ID
|
||||
self._id = AUTO_PLOT_ID
|
||||
AUTO_PLOT_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(plot_id):
|
||||
msg = 'Unable to set a non-integer Plot ID {0}'.format(plot_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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)
|
||||
|
||||
else:
|
||||
check_type('plot ID', plot_id, Integral)
|
||||
check_greater_than('plot ID', plot_id, 0)
|
||||
self._id = plot_id
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Plot ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._name = name
|
||||
check_type('plot name', name, basestring)
|
||||
self._name = name
|
||||
|
||||
@width.setter
|
||||
def width(self, width):
|
||||
if not isinstance(width, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with width {1} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(width) != 2 and len(width) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with width {1} since only 2D ' \
|
||||
'and 3D plots are supported'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in width:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to create Plot ID={0} with width {1} since ' \
|
||||
'each element must be a floating point value or ' \
|
||||
'integer'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('plot width', width, Iterable, Real)
|
||||
check_length('plot width', width, 2, 3)
|
||||
self._width = width
|
||||
|
||||
@origin.setter
|
||||
def origin(self, origin):
|
||||
if not isinstance(origin, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with origin {1} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(self._id, origin)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(origin) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with origin {1} since only ' \
|
||||
'a 3D coordinate must be input'.format(self._id, origin)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in origin:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to create Plot ID={0} with origin {1} since ' \
|
||||
'each element must be a floating point value or ' \
|
||||
'integer'.format(self._id, origin)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('plot origin', origin, Iterable, Real)
|
||||
check_length('plot origin', origin, 3)
|
||||
self._origin = origin
|
||||
|
||||
@pixels.setter
|
||||
def pixels(self, pixels):
|
||||
if not isinstance(pixels, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with pixels {1} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(self._id, pixels)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(pixels) != 2 and len(pixels) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with pixels {1} since ' \
|
||||
'only 2D and 3D plots are supported'.format(self._id, pixels)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('plot pixels', pixels, Iterable, Integral)
|
||||
check_length('plot pixels', pixels, 2, 3)
|
||||
for dim in pixels:
|
||||
if not is_integer(dim):
|
||||
msg = 'Unable to create Plot ID={0} with pixel value {1} ' \
|
||||
'which is not an integer'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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
|
||||
def filename(self, filename):
|
||||
if not is_string(filename):
|
||||
msg = 'Unable to create Plot ID={0} with filename {1} which is ' \
|
||||
'not a string'.format(self._id, filename)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('filename', filename, basestring)
|
||||
self._filename = filename
|
||||
|
||||
@color.setter
|
||||
def color(self, color):
|
||||
if not is_string(color):
|
||||
msg = 'Unable to create Plot ID={0} with color {1} which is not ' \
|
||||
'a string'.format(self._id, color)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif color not in ['cell', 'mat']:
|
||||
msg = 'Unable to create Plot ID={0} with color {1} which is not ' \
|
||||
'a cell or mat'.format(self._id, color)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('plot color', color, basestring)
|
||||
check_value('plot color', color, ['cell', 'mat'])
|
||||
self._color = color
|
||||
|
||||
@type.setter
|
||||
def type(self, type):
|
||||
if not is_string(type):
|
||||
msg = 'Unable to create Plot ID={0} with type {1} which is not ' \
|
||||
'a string'.format(self._id, type)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif type not in ['slice', 'voxel']:
|
||||
msg = 'Unable to create Plot ID={0} with type {1} which is not ' \
|
||||
'slice or voxel'.format(self._id, type)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._type = type
|
||||
def type(self, plottype):
|
||||
check_type('plot type', plottype, basestring)
|
||||
check_value('plot type', plottype, ['slice', 'voxel'])
|
||||
self._type = plottype
|
||||
|
||||
@basis.setter
|
||||
def basis(self, basis):
|
||||
if not is_string(basis):
|
||||
msg = 'Unable to create Plot ID={0} with basis {1} which is not ' \
|
||||
'a string'.format(self._id, basis)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif basis not in ['xy', 'xz', 'yz']:
|
||||
msg = 'Unable to create Plot ID={0} with basis {1} which is not ' \
|
||||
'xy, xz, or yz'.format(self._id, basis)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('plot basis', basis, basestring)
|
||||
check_value('plot basis', basis, ['xy', 'xz', 'yz'])
|
||||
self._basis = basis
|
||||
|
||||
@background.setter
|
||||
def background(self, background):
|
||||
if not isinstance(background, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with background {1} ' \
|
||||
'which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, background)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(background) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with background {1} ' \
|
||||
'which is not 3 integer RGB ' \
|
||||
'values'.format(self._id, background)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('plot background', background, Iterable, Integral)
|
||||
check_length('plot background', background, 3)
|
||||
for rgb in background:
|
||||
if not is_integer(rgb):
|
||||
msg = 'Unable to create Plot ID={0} with background RGB ' \
|
||||
'value {1} which is not an integer'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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 is_integer(key):
|
||||
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)
|
||||
|
||||
elif not isinstance(col_spec[key], (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with col_spec RGB ' \
|
||||
'values {1} which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, col_spec[key])
|
||||
elif not isinstance(col_spec[key], Iterable):
|
||||
msg = 'Unable to create Plot ID={0} with col_spec RGB values' \
|
||||
' {1} which is not iterable'.format(self._id, col_spec[key])
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(col_spec[key]) != 3:
|
||||
|
|
@ -341,52 +229,18 @@ class Plot(object):
|
|||
|
||||
@mask_componenets.setter
|
||||
def mask_components(self, mask_components):
|
||||
if not isinstance(mask_components, (list, tuple, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with mask components {1} ' \
|
||||
'which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, mask_components)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('plot mask_components', mask_components, Iterable, Integral)
|
||||
for component in mask_components:
|
||||
if not is_integer(component):
|
||||
msg = 'Unable to create Plot ID={0} with mask component {1} ' \
|
||||
'which is not an integer'.format(self._id, component)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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
|
||||
def mask_background(self, mask_background):
|
||||
if not isinstance(mask_background, (list, tuple, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with mask background {1} ' \
|
||||
'which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, mask_background)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(mask_background) != 3 and len(mask_background) != 0:
|
||||
msg = 'Unable to create Plot ID={0} with mask background ' \
|
||||
'{1} since 3 RGB values must be ' \
|
||||
'input'.format(self._id, mask_background)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('plot mask background', mask_background, Iterable, Integral)
|
||||
check_length('plot mask background', mask_background, 3)
|
||||
for rgb in mask_background:
|
||||
|
||||
if not is_integer(rgb):
|
||||
msg = 'Unable to create Plot ID={0} with mask background RGB ' \
|
||||
'value {1} which is not an integer'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
import collections
|
||||
from collections import Iterable
|
||||
from numbers import Real, Integral
|
||||
import warnings
|
||||
from xml.etree import ElementTree as ET
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
from openmc.checkvalue import *
|
||||
from openmc.clean_xml import *
|
||||
from openmc.checkvalue import (check_type, check_length, check_value,
|
||||
check_greater_than, check_less_than)
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
|
||||
class SettingsFile(object):
|
||||
|
|
@ -38,11 +44,11 @@ class SettingsFile(object):
|
|||
Path to write output to
|
||||
verbosity : int
|
||||
Verbosity during simulation between 1 and 10
|
||||
statepoint_batches : tuple or list or ndarray
|
||||
statepoint_batches : Iterable of int
|
||||
List of batches at which to write statepoint files
|
||||
statepoint_interval : int
|
||||
Number of batches after which a new statepoint file should be written
|
||||
sourcepoint_batches : tuple or list or ndarray
|
||||
sourcepoint_batches : Iterable of int
|
||||
List of batches at which to write source files
|
||||
sourcepoint_interval : int
|
||||
Number of batches after which a new source file should be written
|
||||
|
|
@ -395,58 +401,26 @@ class SettingsFile(object):
|
|||
|
||||
@batches.setter
|
||||
def batches(self, batches):
|
||||
if not is_integer(batches):
|
||||
msg = 'Unable to set batches to a non-integer ' \
|
||||
'value {0}'.format(batches)
|
||||
raise ValueError(msg)
|
||||
|
||||
if batches <= 0:
|
||||
msg = 'Unable to set batches to a negative ' \
|
||||
'value {0}'.format(batches)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('batches', batches, Integral)
|
||||
check_greater_than('batches', batches, 0)
|
||||
self._batches = batches
|
||||
|
||||
@generations_per_batch.setter
|
||||
def generations_per_batch(self, generations_per_batch):
|
||||
if not is_integer(generations_per_batch):
|
||||
msg = 'Unable to set generations per batch to a non-integer ' \
|
||||
'value {0}'.format(generations_per_batch)
|
||||
raise ValueError(msg)
|
||||
|
||||
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):
|
||||
if not is_integer(inactive):
|
||||
msg = 'Unable to set inactive batches to a non-integer ' \
|
||||
'value {0}'.format(inactive)
|
||||
raise ValueError(msg)
|
||||
|
||||
if inactive <= 0:
|
||||
msg = 'Unable to set inactive batches to a negative ' \
|
||||
'value {0}'.format(inactive)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('inactive batches', inactive, Integral)
|
||||
check_greater_than('inactive batches', inactive, 0)
|
||||
self._inactive = inactive
|
||||
|
||||
@particles.setter
|
||||
def particles(self, particles):
|
||||
if not is_integer(particles):
|
||||
msg = 'Unable to set particles to a non-integer ' \
|
||||
'value {0}'.format(particles)
|
||||
raise ValueError(msg)
|
||||
|
||||
if particles <= 0:
|
||||
msg = 'Unable to set particles to a negative ' \
|
||||
'value {0}'.format(particles)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('particles', particles, Integral)
|
||||
check_greater_than('particles', particles, 0)
|
||||
self._particles = particles
|
||||
|
||||
@keff_trigger.setter
|
||||
|
|
@ -471,7 +445,7 @@ class SettingsFile(object):
|
|||
'does not have a "threshold" key'.format(keff_trigger)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not is_float(keff_trigger['threshold']):
|
||||
elif not isinstance(keff_trigger['threshold'], Real):
|
||||
msg = 'Unable to set a trigger on keff with ' \
|
||||
'threshold {0}'.format(keff_trigger['threshold'])
|
||||
raise ValueError(msg)
|
||||
|
|
@ -480,11 +454,7 @@ class SettingsFile(object):
|
|||
|
||||
@source_file.setter
|
||||
def source_file(self, source_file):
|
||||
if not is_string(source_file):
|
||||
msg = 'Unable to set source file to a non-string ' \
|
||||
'value {0}'.format(source_file)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('source file', source_file, basestring)
|
||||
self._source_file = source_file
|
||||
|
||||
def set_source_space(self, stype, params):
|
||||
|
|
@ -499,7 +469,7 @@ class SettingsFile(object):
|
|||
distribution samples locations from a "box" distribution but only
|
||||
locations in fissionable materials are accepted. A "point" spatial
|
||||
distribution has coordinates specified by a triplet.
|
||||
params : tuple or list or ndarray
|
||||
params : Iterable of float
|
||||
For a "box" or "fission" spatial distribution, ``params`` should be
|
||||
given as six real numbers, the first three of which specify the
|
||||
lower-left corner of a parallelepiped and the last three of which
|
||||
|
|
@ -512,37 +482,15 @@ class SettingsFile(object):
|
|||
|
||||
"""
|
||||
|
||||
if not is_string(stype):
|
||||
msg = 'Unable to set source space type to a non-string ' \
|
||||
'value {0}'.format(stype)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype not in ['box', 'fission', 'point']:
|
||||
msg = 'Unable to set source space type to {0} since it is not ' \
|
||||
'box or point'.format(stype)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not isinstance(params, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set source space parameters to {0} since it is ' \
|
||||
'not a Python tuple, list or NumPy array'.format(params)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype in ['box', 'fission'] and len(params) != 6:
|
||||
msg = 'Unable to set source space parameters for a box/fission ' \
|
||||
'distribution to {0} since it does not contain 6 values'\
|
||||
.format(params)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype == 'point' and len(params) != 3:
|
||||
msg = 'Unable to set source space parameters for a point to {0} ' \
|
||||
'since it does not contain 3 values'.format(params)
|
||||
raise ValueError(msg)
|
||||
|
||||
for param in params:
|
||||
if not is_integer(param) and not is_float(param):
|
||||
msg = 'Unable to set source space parameters to {0} since it ' \
|
||||
'is not an integer or floating point value'.format(param)
|
||||
raise ValueError(msg)
|
||||
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']:
|
||||
check_length('source space parameters for a '
|
||||
'box/fission distribution', params, 6)
|
||||
elif stype == 'point':
|
||||
check_length('source space parameters for a point source',
|
||||
params, 3)
|
||||
|
||||
self._source_space_type = stype
|
||||
self._source_space_params = params
|
||||
|
|
@ -558,7 +506,7 @@ class SettingsFile(object):
|
|||
site is isotropic if the "isotropic" option is given. The angle of
|
||||
the particle emitted from a source site is the direction specified
|
||||
in ``params`` if the "monodirectional" option is given.
|
||||
params : tuple or list or ndarray
|
||||
params : Iterable of float
|
||||
For an "isotropic" angular distribution, ``params`` should not
|
||||
be specified.
|
||||
|
||||
|
|
@ -568,37 +516,17 @@ class SettingsFile(object):
|
|||
|
||||
"""
|
||||
|
||||
if not is_string(stype):
|
||||
msg = 'Unable to set source angle type to a non-string ' \
|
||||
'value {0}'.format(stype)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype not in ['isotropic', 'monodirectional']:
|
||||
msg = 'Unable to set source angle type to {0} since it is not ' \
|
||||
'isotropic or monodirectional'.format(stype)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not isinstance(params, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set source angle parameters to {0} since it is ' \
|
||||
'not a Python list/tuple or NumPy array'.format(params)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype == 'isotropic' and params is not None:
|
||||
check_type('source angle type', stype, basestring)
|
||||
check_value('source angle type', stype,
|
||||
['isotropic', 'monodirectional'])
|
||||
check_type('source angle parameters', params, Iterable, Real)
|
||||
if stype == 'isotropic' and params is not None:
|
||||
msg = 'Unable to set source angle parameters since they are not ' \
|
||||
'it is not supported for isotropic type sources'
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype == 'monodirectional' and len(params) != 3:
|
||||
msg = 'Unable to set source angle parameters to {0} ' \
|
||||
'since 3 parameters are required for monodirectional ' \
|
||||
'sources'.format(params)
|
||||
raise ValueError(msg)
|
||||
|
||||
for param in params:
|
||||
if not is_integer(param) and not is_float(param):
|
||||
msg = 'Unable to set source angle parameters to {0} since it ' \
|
||||
'is not an integer or floating point value'.format(param)
|
||||
raise ValueError(msg)
|
||||
elif stype == 'monodirectional':
|
||||
check_length('source angle parameters for a monodirectional '
|
||||
'source', params, 3)
|
||||
|
||||
self._source_angle_type = stype
|
||||
self._source_angle_params = params
|
||||
|
|
@ -615,7 +543,7 @@ class SettingsFile(object):
|
|||
whose energy is sampled from a Watt fission spectrum. The "maxwell"
|
||||
option produce source sites whose energy is sampled from a Maxwell
|
||||
fission spectrum.
|
||||
params : tuple or list or ndarray
|
||||
params : Iterable of float
|
||||
For a "monoenergetic" energy distribution, ``params`` should be
|
||||
given as the energy in MeV of the source sites.
|
||||
|
||||
|
|
@ -629,44 +557,16 @@ class SettingsFile(object):
|
|||
|
||||
"""
|
||||
|
||||
if not is_string(stype):
|
||||
msg = 'Unable to set source energy type to a non-string ' \
|
||||
'value {0}'.format(stype)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype not in ['monoenergetic', 'watt', 'maxwell']:
|
||||
msg = 'Unable to set source energy type to {0} since it is not ' \
|
||||
'monoenergetic, watt or maxwell'.format(stype)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not isinstance(params, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set source energy params to {0} since it ' \
|
||||
'is not a Python list/tuple or NumPy array'.format(params)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype == 'monoenergetic' and not len(params) != 1:
|
||||
msg = 'Unable to set source energy params to {0} ' \
|
||||
'since 1 paramater is required for monenergetic ' \
|
||||
'sources'.format(params)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype == 'watt' and len(params) != 2:
|
||||
msg = 'Unable to set source energy params to {0} ' \
|
||||
'since 2 params are required for monoenergetic ' \
|
||||
'sources'.format(params)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif stype == 'maxwell' and len(params) != 2:
|
||||
msg = 'Unable to set source energy params to {0} since 1 ' \
|
||||
'parameter is required for maxwell sources'.format(params)
|
||||
raise ValueError(msg)
|
||||
|
||||
for param in params:
|
||||
if not is_integer(param) and not is_float(param):
|
||||
msg = 'Unable to set source energy params to {0} ' \
|
||||
'since it is not an integer or floating point ' \
|
||||
'value'.format(param)
|
||||
raise ValueError(msg)
|
||||
check_type('source energy type', stype, basestring)
|
||||
check_value('source energy type', stype,
|
||||
['monoenergetic', 'watt', 'maxwell'])
|
||||
check_type('source energy parameters', params, Iterable, Real)
|
||||
if stype in ['monoenergetic', 'maxwell']:
|
||||
check_length('source energy parameters for a monoenergetic '
|
||||
'or Maxwell source', params, 1)
|
||||
elif stype == 'watt':
|
||||
check_length('source energy parameters for a Watt source',
|
||||
params, 2)
|
||||
|
||||
self._source_energy_type = stype
|
||||
self._source_energy_params = params
|
||||
|
|
@ -694,433 +594,192 @@ class SettingsFile(object):
|
|||
|
||||
@output_path.setter
|
||||
def output_path(self, output_path):
|
||||
if not is_string(output_path):
|
||||
msg = 'Unable to set output path to non-string ' \
|
||||
'value {0}'.format(output_path)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('output path', output_path, basestring)
|
||||
self._output_path = output_path
|
||||
|
||||
@verbosity.setter
|
||||
def verbosity(self, verbosity):
|
||||
if not is_integer(verbosity):
|
||||
msg = 'Unable to set verbosity to non-integer ' \
|
||||
'value {0}'.format(verbosity)
|
||||
raise ValueError(msg)
|
||||
|
||||
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_type('verbosity', verbosity, Integral)
|
||||
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):
|
||||
if not isinstance(batches, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set statepoint batches to {0} which is not a ' \
|
||||
'Python tuple/list or NumPy array'.format(batches)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('statepoint batches', batches, Iterable, Integral)
|
||||
for batch in batches:
|
||||
if not is_integer(batch):
|
||||
msg = 'Unable to set statepoint batches with non-integer ' \
|
||||
'value {0}'.format(batch)
|
||||
raise ValueError(msg)
|
||||
|
||||
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
|
||||
def statepoint_interval(self, interval):
|
||||
if not is_integer(interval):
|
||||
msg = 'Unable to set statepoint interval to non-integer ' \
|
||||
'value {0}'.format(interval)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('statepoint interval', interval, Integral)
|
||||
self._statepoint_interval = interval
|
||||
|
||||
@sourcepoint_batches.setter
|
||||
def sourcepoint_batches(self, batches):
|
||||
if not isinstance(batches, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set sourcepoint batches to {0} which is ' \
|
||||
'not a Python tuple/list or NumPy array'.format(batches)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('sourcepoint batches', batches, Iterable, Integral)
|
||||
for batch in batches:
|
||||
if not is_integer(batch):
|
||||
msg = 'Unable to set sourcepoint batches with non-integer ' \
|
||||
'value {0}'.format(batch)
|
||||
raise ValueError(msg)
|
||||
|
||||
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
|
||||
def sourcepoint_interval(self, interval):
|
||||
if not is_integer(interval):
|
||||
msg = 'Unable to set sourcepoint interval to non-integer ' \
|
||||
'value {0}'.format(interval)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('sourcepoint interval', interval, Integral)
|
||||
self._sourcepoint_interval = interval
|
||||
|
||||
@sourcepoint_separate.setter
|
||||
def sourcepoint_separate(self, source_separate):
|
||||
if not isinstance(source_separate, (bool, np.bool)):
|
||||
msg = 'Unable to set sourcepoint separate to non-boolean ' \
|
||||
'value {0}'.format(source_separate)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('sourcepoint separate', source_separate, bool)
|
||||
self._sourcepoint_separate = source_separate
|
||||
|
||||
@sourcepoint_write.setter
|
||||
def sourcepoint_write(self, source_write):
|
||||
if not isinstance(source_write, (bool, np.bool)):
|
||||
msg = 'Unable to set sourcepoint write to non-boolean ' \
|
||||
'value {0}'.format(source_write)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('sourcepoint write', source_write, bool)
|
||||
self._sourcepoint_write = source_write
|
||||
|
||||
@sourcepoint_overwrite.setter
|
||||
def sourcepoint_overwrite(self, source_overwrite):
|
||||
if not isinstance(source_overwrite, (bool, np.bool)):
|
||||
msg = 'Unable to set sourcepoint overwrite to non-boolean ' \
|
||||
'value {0}'.format(source_overwrite)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('sourcepoint overwrite', source_overwrite, bool)
|
||||
self._sourcepoint_overwrite = source_overwrite
|
||||
|
||||
@confidence_intervals.setter
|
||||
def confidence_intervals(self, confidence_intervals):
|
||||
if not isinstance(confidence_intervals, (bool, np.bool)):
|
||||
msg = 'Unable to set confidence interval to non-boolean ' \
|
||||
'value {0}'.format(confidence_intervals)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('confidence interval', confidence_intervals, bool)
|
||||
self._confidence_intervals = confidence_intervals
|
||||
|
||||
@cross_sections.setter
|
||||
def cross_sections(self, cross_sections):
|
||||
if not is_string(cross_sections):
|
||||
msg = 'Unable to set cross sections to non-string ' \
|
||||
'value {0}'.format(cross_sections)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('cross sections', cross_sections, basestring)
|
||||
self._cross_sections = cross_sections
|
||||
|
||||
@energy_grid.setter
|
||||
def energy_grid(self, energy_grid):
|
||||
if energy_grid not in ['nuclide', 'logarithm', 'material-union']:
|
||||
msg = 'Unable to set energy grid to {0} which is neither ' \
|
||||
'nuclide, logarithm, nor material-union'.format(energy_grid)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_value('energy grid', energy_grid,
|
||||
['nuclide', 'logarithm', 'material-union'])
|
||||
self._energy_grid = energy_grid
|
||||
|
||||
@ptables.setter
|
||||
def ptables(self, ptables):
|
||||
if not isinstance(ptables, (bool, np.bool)):
|
||||
msg = 'Unable to set ptables to non-boolean ' \
|
||||
'value {0}'.format(ptables)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('probability tables', ptables, bool)
|
||||
self._ptables = ptables
|
||||
|
||||
@run_cmfd.setter
|
||||
def run_cmfd(self, run_cmfd):
|
||||
if not isinstance(run_cmfd, (bool, np.bool)):
|
||||
msg = 'Unable to set run_cmfd to non-boolean ' \
|
||||
'value {0}'.format(run_cmfd)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('run_cmfd', run_cmfd, bool)
|
||||
self._run_cmfd = run_cmfd
|
||||
|
||||
@seed.setter
|
||||
def seed(self, seed):
|
||||
if not is_integer(seed):
|
||||
msg = 'Unable to set seed to non-integer value {0}'.format(seed)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif seed <= 0:
|
||||
msg = 'Unable to set seed to non-positive integer {0}'.format(seed)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('random number generator seed', seed, Integral)
|
||||
check_greater_than('random number generator seed', seed, 0)
|
||||
self._seed = seed
|
||||
|
||||
@survival_biasing.setter
|
||||
def survival_biasing(self, survival_biasing):
|
||||
if not isinstance(survival_biasing, (bool, np.bool)):
|
||||
msg = 'Unable to set survival biasing to non-boolean ' \
|
||||
'value {0}'.format(survival_biasing)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('survival biasing', survival_biasing, bool)
|
||||
self._survival_biasing = survival_biasing
|
||||
|
||||
@weight.setter
|
||||
def weight(self, weight):
|
||||
if not is_float(weight):
|
||||
msg = 'Unable to set weight cutoff to non-floating point ' \
|
||||
'value {0}'.format(weight)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif weight < 0.0:
|
||||
msg = 'Unable to set weight cutoff to negative ' \
|
||||
'value {0}'.format(weight)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('weight cutoff', weight, Real)
|
||||
check_greater_than('weight cutoff', weight, 0.0)
|
||||
self._weight = weight
|
||||
|
||||
@weight_avg.setter
|
||||
def weight_avg(self, weight_avg):
|
||||
if not is_float(weight_avg):
|
||||
msg = 'Unable to set weight avg. to non-floating point ' \
|
||||
'value {0}'.format(weight_avg)
|
||||
raise ValueError(msg)
|
||||
elif weight_avg < 0.0:
|
||||
msg = 'Unable to set weight avg. to negative ' \
|
||||
'value {0}'.format(weight_avg)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('average survival weight', weight_avg, Real)
|
||||
check_greater_than('average survival weight', weight_avg, 0.0)
|
||||
self._weight_avg = weight_avg
|
||||
|
||||
@entropy_dimension.setter
|
||||
def entropy_dimension(self, dimension):
|
||||
if not isinstance(dimension, (tuple, list)):
|
||||
msg = 'Unable to set entropy mesh dimension to {0} which is ' \
|
||||
'not a Python tuple or list'.format(dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(dimension) != 3:
|
||||
msg = 'Unable to set entropy mesh dimension to {0} which is ' \
|
||||
'not a set of 3 integer dimensions'.format(dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in dimension:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to set entropy mesh dimension to a ' \
|
||||
'non-integer or floating point value {0}'.format(dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('entropy mesh dimension', dimension, Iterable, Integral)
|
||||
check_length('entropy mesh dimension', dimension, 3)
|
||||
self._entropy_dimension = dimension
|
||||
|
||||
@entropy_lower_left.setter
|
||||
def entropy_lower_left(self, lower_left):
|
||||
if not isinstance(lower_left, (tuple, list)):
|
||||
msg = 'Unable to set entropy mesh lower left corner to {0} which ' \
|
||||
'is not a Python tuple or list'.format(lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(lower_left) != 3:
|
||||
msg = 'Unable to set entropy mesh lower left corner to {0} which ' \
|
||||
'is not a 3D point'.format(lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
for coord in lower_left:
|
||||
if not is_integer(coord) and not is_float(coord):
|
||||
msg = 'Unable to set entropy mesh lower left corner to a ' \
|
||||
'non-integer or floating point value {0}'.format(coord)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('entropy mesh lower left corner', lower_left,
|
||||
Iterable, Real)
|
||||
check_length('entropy mesh lower left corner', lower_left, 3)
|
||||
self._entropy_lower_left = lower_left
|
||||
|
||||
@entropy_upper_right.setter
|
||||
def entropy_upper_right(self, upper_right):
|
||||
if not isinstance(upper_right, (tuple, list)):
|
||||
msg = 'Unable to set entropy mesh upper right corner to {0} ' \
|
||||
'which is not a Python tuple or list'.format(upper_right)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(upper_right) < 3 or len(upper_right) > 3:
|
||||
msg = 'Unable to set entropy mesh upper right corner to {0} ' \
|
||||
'which is not a 3D point'.format(upper_right)
|
||||
raise ValueError(msg)
|
||||
|
||||
for coord in upper_right:
|
||||
if not is_integer(coord) and not is_float(coord):
|
||||
msg = 'Unable to set entropy mesh upper right corner to a ' \
|
||||
'non-integer or floating point value {0}'.format(coord)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('entropy mesh upper right corner', upper_right,
|
||||
Iterable, Real)
|
||||
check_length('entropy mesh upper right corner', upper_right, 3)
|
||||
self._entropy_upper_right = upper_right
|
||||
|
||||
@trigger_active.setter
|
||||
def trigger_active(self, trigger_active):
|
||||
if not isinstance(trigger_active, bool):
|
||||
msg = 'Unable to set trigger active to a ' \
|
||||
'non-boolean value {0}'.format(trigger_active)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('trigger active', trigger_active, bool)
|
||||
self._trigger_active = trigger_active
|
||||
|
||||
@trigger_max_batches.setter
|
||||
def trigger_max_batches(self, trigger_max_batches):
|
||||
if not is_integer(trigger_max_batches):
|
||||
msg = 'Unable to set trigger max batches to a non-integer ' \
|
||||
'value {0}'.format(trigger_max_batches)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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_type('trigger maximum batches', trigger_max_batches, Integral)
|
||||
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):
|
||||
if not is_integer(trigger_batch_interval):
|
||||
msg = 'Unable to set trigger batch interval to a non-integer ' \
|
||||
'value {0}'.format(trigger_batch_interval)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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_type('trigger batch interval', trigger_batch_interval, Integral)
|
||||
check_greater_than('trigger batch interval', trigger_batch_interval, 0)
|
||||
self._trigger_batch_interval = trigger_batch_interval
|
||||
|
||||
@no_reduce.setter
|
||||
def no_reduce(self, no_reduce):
|
||||
if not isinstance(no_reduce, (bool, np.bool)):
|
||||
msg = 'Unable to set the no_reduce to a non-boolean ' \
|
||||
'value {0}'.format(no_reduce)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('no reduction option', no_reduce, bool)
|
||||
self._no_reduce = no_reduce
|
||||
|
||||
@threads.setter
|
||||
def threads(self, threads):
|
||||
if not is_integer(threads):
|
||||
msg = 'Unable to set the threads to a non-integer ' \
|
||||
'value {0}'.format(threads)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif threads <= 0:
|
||||
msg = 'Unable to set the threads to a negative ' \
|
||||
'value {0}'.format(threads)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('number of threads', threads, Integral)
|
||||
check_greater_than('number of threads', threads, 0)
|
||||
self._threads = threads
|
||||
|
||||
@trace.setter
|
||||
def trace(self, trace):
|
||||
if not isinstance(trace, (list, tuple)):
|
||||
msg = 'Unable to set the trace to {0} which is not a Python ' \
|
||||
'tuple or list'.format(trace)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(trace) != 3:
|
||||
msg = 'Unable to set the trace to {0} since it does not contain ' \
|
||||
'3 elements - batch, generation, and particle'.format(trace)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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_type('trace', trace, Iterable, Integral)
|
||||
check_length('trace', trace, 3)
|
||||
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
|
||||
def track(self, track):
|
||||
if not isinstance(track, (list, tuple)):
|
||||
msg = 'Unable to set the track to {0} which is not a Python ' \
|
||||
'tuple or list'.format(track)
|
||||
check_type('track', track, Iterable, Integral)
|
||||
if len(track) % 3 != 0:
|
||||
msg = 'Unable to set the track to {0} since its length is ' \
|
||||
'not a multiple of 3'.format(track)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(track) != 3:
|
||||
msg = 'Unable to set the track to {0} since it does not contain ' \
|
||||
'3 elements - batch, generation, and particle'.format(track)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif track[0] < 1:
|
||||
msg = 'Unable to set the track batch to {0} since it must be ' \
|
||||
'greater than or equal to 1'.format(track[0])
|
||||
raise ValueError(msg)
|
||||
|
||||
elif track[1] < 1:
|
||||
msg = 'Unable to set the track generation to {0} since it must ' \
|
||||
'be greater than or equal to 1'.format(track[1])
|
||||
raise ValueError(msg)
|
||||
|
||||
elif track[2] < 1:
|
||||
msg = 'Unable to set the track particle to {0} since it must ' \
|
||||
'be greater than or equal to 1'.format(track[2])
|
||||
raise ValueError(msg)
|
||||
|
||||
for t in zip(track[::3], track[1::3], track[2::3]):
|
||||
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
|
||||
def ufs_dimension(self, dimension):
|
||||
if not isinstance(dimension, (tuple, list)):
|
||||
msg = 'Unable to set UFS mesh dimension to {0} which is ' \
|
||||
'not a Python tuple or list'.format(dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(dimension) != 3:
|
||||
msg = 'Unable to set UFS mesh dimension to {0} which is ' \
|
||||
'not a set of 3 integer dimensions'.format(dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('UFS mesh dimension', dimension, Iterable, Integral)
|
||||
check_length('UFS mesh dimension', dimension, 3)
|
||||
for dim in dimension:
|
||||
if not is_integer(dim):
|
||||
msg = 'Unable to set entropy mesh dimension to a ' \
|
||||
'non-integer {0}'.format(dim)
|
||||
raise ValueError(msg)
|
||||
elif 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
|
||||
def ufs_lower_left(self, lower_left):
|
||||
if not isinstance(lower_left, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set UFS mesh lower left corner to {0} which is ' \
|
||||
'not a Python tuple or list'.format(lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(lower_left) != 3:
|
||||
msg = 'Unable to set UFS mesh lower left corner to {0} which ' \
|
||||
'is not a 3D point'.format(lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('UFS mesh lower left corner', lower_left, Iterable, Real)
|
||||
check_length('UFS mesh lower left corner', lower_left, 3)
|
||||
self._ufs_lower_left = lower_left
|
||||
|
||||
@ufs_upper_right.setter
|
||||
def ufs_upper_right(self, upper_right):
|
||||
if not isinstance(upper_right, (tuple, list)):
|
||||
msg = 'Unable to set UFs mesh upper right corner to {0} which is ' \
|
||||
'not a Python tuple or list'.format(upper_right)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(upper_right) != 3:
|
||||
msg = 'Unable to set UFS mesh upper right corner to {0} which ' \
|
||||
'is not a 3D point'.format(upper_right)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('UFS mesh upper right corner', upper_right, Iterable, Real)
|
||||
check_length('UFS mesh upper right corner', upper_right, 3)
|
||||
self._ufs_upper_right = upper_right
|
||||
|
||||
@dd_mesh_dimension.setter
|
||||
|
|
@ -1129,15 +788,8 @@ class SettingsFile(object):
|
|||
warnings.warn('This feature is not yet implemented in a release '
|
||||
'version of openmc')
|
||||
|
||||
if not isinstance(dimension, (tuple, list)):
|
||||
msg = 'Unable to set DD mesh upper right corner to {0} which is ' \
|
||||
'not a Python tuple or list'.format(dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(dimension) != 3:
|
||||
msg = 'Unable to set DD mesh upper right corner to {0} which ' \
|
||||
'is not a 3D point'.format(dimension)
|
||||
raise ValueError(msg)
|
||||
check_type('DD mesh dimension', dimension, Iterable, Integral)
|
||||
check_length('DD mesh dimension', dimension, 3)
|
||||
|
||||
self._dd_mesh_dimension = dimension
|
||||
|
||||
|
|
@ -1147,15 +799,8 @@ class SettingsFile(object):
|
|||
warnings.warn('This feature is not yet implemented in a release '
|
||||
'version of openmc')
|
||||
|
||||
if not isinstance(lower_left, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set DD mesh lower left corner to {0} which is ' \
|
||||
'not a Python tuple or list'.format(lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(lower_left) < 3 or len(lower_left) > 3:
|
||||
msg = 'Unable to set DD mesh lower left corner to {0} which ' \
|
||||
'is not a 3D point'.format(lower_left)
|
||||
raise ValueError(msg)
|
||||
check_type('DD mesh lower left corner', lower_left, Iterable, Real)
|
||||
check_length('DD mesh lower left corner', lower_left, 3)
|
||||
|
||||
self._dd_mesh_lower_left = lower_left
|
||||
|
||||
|
|
@ -1165,16 +810,8 @@ class SettingsFile(object):
|
|||
warnings.warn('This feature is not yet implemented in a release '
|
||||
'version of openmc')
|
||||
|
||||
if not isinstance(upper_right, tuple) and \
|
||||
not isinstance(upper_right, list):
|
||||
msg = 'Unable to set DD mesh upper right corner to {0} which is ' \
|
||||
'not a Python tuple or list'.format(upper_right)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(upper_right) < 3 or len(upper_right) > 3:
|
||||
msg = 'Unable to set DD mesh upper right corner to {0} which ' \
|
||||
'is not a 3D point'.format(upper_right)
|
||||
raise ValueError(msg)
|
||||
check_type('DD mesh upper right corner', upper_right, Iterable, Real)
|
||||
check_length('DD mesh upper right corner', upper_right, 3)
|
||||
|
||||
self._dd_mesh_upper_right = upper_right
|
||||
|
||||
|
|
@ -1184,10 +821,7 @@ class SettingsFile(object):
|
|||
warnings.warn('This feature is not yet implemented in a release '
|
||||
'version of openmc')
|
||||
|
||||
if not isinstance(nodemap, (tuple, list)):
|
||||
msg = 'Unable to set DD nodemap {0} which is ' \
|
||||
'not a Python tuple or list'.format(nodemap)
|
||||
raise ValueError(msg)
|
||||
check_type('DD nodemap', nodemap, Iterable)
|
||||
|
||||
nodemap = np.array(nodemap).flatten()
|
||||
|
||||
|
|
@ -1212,10 +846,7 @@ class SettingsFile(object):
|
|||
warnings.warn('This feature is not yet implemented in a release '
|
||||
'version of openmc')
|
||||
|
||||
if not isinstance(allow, bool):
|
||||
msg = 'Unable to set DD allow_leakage {0} which is ' \
|
||||
'not a Python bool'.format(allow)
|
||||
raise ValueError(msg)
|
||||
check_type('DD allow leakage', allow, bool)
|
||||
|
||||
self._dd_allow_leakage = allow
|
||||
|
||||
|
|
@ -1226,10 +857,7 @@ class SettingsFile(object):
|
|||
warnings.warn('This feature is not yet implemented in a release '
|
||||
'version of openmc')
|
||||
|
||||
if not isinstance(interactions, bool):
|
||||
msg = 'Unable to set DD count_interactions {0} which is ' \
|
||||
'not a Python bool'.format(interactions)
|
||||
raise ValueError(msg)
|
||||
check_type('DD count interactions', interactions, bool)
|
||||
|
||||
self._dd_count_interactions = interactions
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
from abc import ABCMeta
|
||||
from numbers import Real, Integral
|
||||
from xml.etree import ElementTree as ET
|
||||
import sys
|
||||
|
||||
from openmc.checkvalue import *
|
||||
from openmc.checkvalue import check_type, check_value, check_greater_than
|
||||
from openmc.constants import BC_TYPES
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
# A static variable for auto-generated Surface IDs
|
||||
AUTO_SURFACE_ID = 10000
|
||||
|
|
@ -89,46 +93,21 @@ class Surface(object):
|
|||
global AUTO_SURFACE_ID
|
||||
self._id = AUTO_SURFACE_ID
|
||||
AUTO_SURFACE_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(surface_id):
|
||||
msg = 'Unable to set a non-integer Surface ' \
|
||||
'ID {0}'.format(surface_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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)
|
||||
|
||||
else:
|
||||
check_type('surface ID', surface_id, Integral)
|
||||
check_greater_than('surface ID', surface_id, 0)
|
||||
self._id = surface_id
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Surface ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._name = name
|
||||
check_type('surface name', name, basestring)
|
||||
self._name = name
|
||||
|
||||
@boundary_type.setter
|
||||
def boundary_type(self, boundary_type):
|
||||
if not is_string(boundary_type):
|
||||
msg = 'Unable to set boundary type for Surface ID={0} with a ' \
|
||||
'non-string value {1}'.format(self._id, boundary_type)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif boundary_type not in BC_TYPES.values():
|
||||
msg = 'Unable to set boundary type for Surface ID={0} to ' \
|
||||
'{1} which is not trasmission, vacuum or ' \
|
||||
'reflective'.format(boundary_type)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._boundary_type = boundary_type
|
||||
check_type('boundary type', boundary_type, basestring)
|
||||
check_value('boundary type', boundary_type, BC_TYPES.values())
|
||||
self._boundary_type = boundary_type
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Surface\n'
|
||||
|
|
@ -235,38 +214,22 @@ class Plane(Surface):
|
|||
|
||||
@a.setter
|
||||
def a(self, A):
|
||||
if not is_integer(A) and not is_float(A):
|
||||
msg = 'Unable to set A coefficient for Plane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, A)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('A coefficient', A, Real)
|
||||
self._coeffs['A'] = A
|
||||
|
||||
@b.setter
|
||||
def b(self, B):
|
||||
if not is_integer(B) and not is_float(B):
|
||||
msg = 'Unable to set B coefficient for Plane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, B)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('B coefficient', B, Real)
|
||||
self._coeffs['B'] = B
|
||||
|
||||
@c.setter
|
||||
def c(self, C):
|
||||
if not is_integer(C) and not is_float(C):
|
||||
msg = 'Unable to set C coefficient for Plane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, C)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('C coefficient', C, Real)
|
||||
self._coeffs['C'] = C
|
||||
|
||||
@d.setter
|
||||
def d(self, D):
|
||||
if not is_integer(D) and not is_float(D):
|
||||
msg = 'Unable to set D coefficient for Plane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, D)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('D coefficient', D, Real)
|
||||
self._coeffs['D'] = D
|
||||
|
||||
|
||||
|
|
@ -312,11 +275,7 @@ class XPlane(Plane):
|
|||
|
||||
@x0.setter
|
||||
def x0(self, x0):
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for XPlane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('x0 coefficient', x0, Real)
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
|
||||
|
|
@ -362,11 +321,7 @@ class YPlane(Plane):
|
|||
|
||||
@y0.setter
|
||||
def y0(self, y0):
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for XPlane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('y0 coefficient', y0, Real)
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
|
||||
|
|
@ -412,11 +367,7 @@ class ZPlane(Plane):
|
|||
|
||||
@z0.setter
|
||||
def z0(self, z0):
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for ZPlane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('z0 coefficient', z0, Real)
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
|
||||
|
|
@ -463,11 +414,7 @@ class Cylinder(Surface):
|
|||
|
||||
@r.setter
|
||||
def r(self, R):
|
||||
if not is_integer(R) and not is_float(R):
|
||||
msg = 'Unable to set R coefficient for Cylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, R)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('R coefficient', R, Real)
|
||||
self._coeffs['R'] = R
|
||||
|
||||
|
||||
|
|
@ -527,20 +474,12 @@ class XCylinder(Cylinder):
|
|||
|
||||
@y0.setter
|
||||
def y0(self, y0):
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for XCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('y0 coefficient', y0, Real)
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
@z0.setter
|
||||
def z0(self, z0):
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for XCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('z0 coefficient', z0, Real)
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
|
||||
|
|
@ -600,20 +539,12 @@ class YCylinder(Cylinder):
|
|||
|
||||
@x0.setter
|
||||
def x0(self, x0):
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for YCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('x0 coefficient', x0, Real)
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
@z0.setter
|
||||
def z0(self, z0):
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for YCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('z0 coefficient', z0, Real)
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
|
||||
|
|
@ -673,20 +604,12 @@ class ZCylinder(Cylinder):
|
|||
|
||||
@x0.setter
|
||||
def x0(self, x0):
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for ZCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('x0 coefficient', x0, Real)
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
@y0.setter
|
||||
def y0(self, y0):
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for ZCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('y0 coefficient', y0, Real)
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
|
||||
|
|
@ -764,38 +687,22 @@ class Sphere(Surface):
|
|||
|
||||
@x0.setter
|
||||
def x0(self, x0):
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('x0 coefficient', x0, Real)
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
@y0.setter
|
||||
def y0(self, y0):
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('y0 coefficient', y0, Real)
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
@z0.setter
|
||||
def z0(self, z0):
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('z0 coefficient', z0, Real)
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
@r.setter
|
||||
def r(self, R):
|
||||
if not is_integer(R) and not is_float(R):
|
||||
msg = 'Unable to set R coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, R)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('R coefficient', R, Real)
|
||||
self._coeffs['R'] = R
|
||||
|
||||
|
||||
|
|
@ -874,38 +781,22 @@ class Cone(Surface):
|
|||
|
||||
@x0.setter
|
||||
def x0(self, x0):
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('x0 coefficient', x0, Real)
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
@y0.setter
|
||||
def y0(self, y0):
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('y0 coefficient', y0, Real)
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
@z0.setter
|
||||
def z0(self, z0):
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('z0 coefficient', z0, Real)
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
@r2.setter
|
||||
def r2(self, R2):
|
||||
if not is_integer(R2) and not is_float(R2):
|
||||
msg = 'Unable to set R^2 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, R2)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('R^2 coefficient', R2, Real)
|
||||
self._coeffs['R2'] = R2
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,23 @@
|
|||
from collections import Iterable
|
||||
import copy
|
||||
import os
|
||||
import pickle
|
||||
import itertools
|
||||
from numbers import Integral
|
||||
from xml.etree import ElementTree as ET
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
from openmc import Mesh, Filter, Trigger, Nuclide
|
||||
from openmc.summary import Summary
|
||||
from openmc.checkvalue import check_type, check_value, check_greater_than
|
||||
from openmc.clean_xml import *
|
||||
from openmc.checkvalue import *
|
||||
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
# "Static" variable for auto-generated Tally IDs
|
||||
AUTO_TALLY_ID = 10000
|
||||
|
||||
|
|
@ -271,11 +277,7 @@ class Tally(object):
|
|||
|
||||
@estimator.setter
|
||||
def estimator(self, estimator):
|
||||
if estimator not in ['analog', 'tracklength']:
|
||||
msg = 'Unable to set the estimator for Tally ID={0} to {1} since ' \
|
||||
'it is not a valid estimator type'.format(self.id, estimator)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_value('estimator', estimator, ['analog', 'tracklength'])
|
||||
self._estimator = estimator
|
||||
|
||||
def add_trigger(self, trigger):
|
||||
|
|
@ -301,29 +303,15 @@ class Tally(object):
|
|||
global AUTO_TALLY_ID
|
||||
self._id = AUTO_TALLY_ID
|
||||
AUTO_TALLY_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(tally_id):
|
||||
msg = 'Unable to set a non-integer Tally ID {0}'.format(tally_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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)
|
||||
|
||||
else:
|
||||
check_type('tally ID', tally_id, Integral)
|
||||
check_greater_than('tally ID', tally_id, 0)
|
||||
self._id = tally_id
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Tally ID={0} with a non-string ' \
|
||||
'value "{1}"'.format(self.id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._name = name
|
||||
check_type('tally name', name, basestring)
|
||||
self._name = name
|
||||
|
||||
def add_filter(self, filter):
|
||||
"""Add a filter to the tally
|
||||
|
|
@ -335,8 +323,6 @@ class Tally(object):
|
|||
|
||||
"""
|
||||
|
||||
global filters
|
||||
|
||||
if not isinstance(filter, Filter):
|
||||
msg = 'Unable to add Filter "{0}" to Tally ID={1} since it is ' \
|
||||
'not a Filter object'.format(filter, self.id)
|
||||
|
|
@ -366,7 +352,7 @@ class Tally(object):
|
|||
|
||||
"""
|
||||
|
||||
if not is_string(score):
|
||||
if not isinstance(score, basestring):
|
||||
msg = 'Unable to add score "{0}" to Tally ID={1} since it is ' \
|
||||
'not a string'.format(score, self.id)
|
||||
raise ValueError(msg)
|
||||
|
|
@ -383,45 +369,23 @@ class Tally(object):
|
|||
|
||||
@num_realizations.setter
|
||||
def num_realizations(self, num_realizations):
|
||||
if not is_integer(num_realizations):
|
||||
msg = 'Unable to set the number of realizations to "{0}" for ' \
|
||||
'Tally ID={1} since it is not an ' \
|
||||
'integer'.format(num_realizations)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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_type('number of realizations', num_realizations, Integral)
|
||||
check_greater_than('number of realizations', num_realizations, 0, True)
|
||||
self._num_realizations = num_realizations
|
||||
|
||||
@with_summary.setter
|
||||
def with_summary(self, with_summary):
|
||||
if not isinstance(with_summary, bool):
|
||||
msg = 'Unable to set with_summary to a non-boolean ' \
|
||||
'value "{0}"'.format(with_summary)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('with_summary', with_summary, bool)
|
||||
self._with_summary = with_summary
|
||||
|
||||
@sum.setter
|
||||
def sum(self, sum):
|
||||
if not isinstance(sum, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set the sum to "{0}" for Tally ID={1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(sum, self.id)
|
||||
raise ValueError(msg)
|
||||
check_type('sum', sum, Iterable)
|
||||
self._sum = sum
|
||||
|
||||
@sum_sq.setter
|
||||
def sum_sq(self, sum_sq):
|
||||
if not isinstance(sum_sq, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set the sum to "{0}" for Tally ID={1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(sum_sq, self.id)
|
||||
raise ValueError(msg)
|
||||
check_type('sum_sq', sum_sq, Iterable)
|
||||
self._sum_sq = sum_sq
|
||||
|
||||
def remove_score(self, score):
|
||||
|
|
@ -1321,13 +1285,13 @@ class Tally(object):
|
|||
'Tally.export_results(...)'.format(self.id)
|
||||
raise KeyError(msg)
|
||||
|
||||
if not is_string(filename):
|
||||
if not isinstance(filename, basestring):
|
||||
msg = 'Unable to export the results for Tally ID={0} to ' \
|
||||
'filename="{1}" since it is not a ' \
|
||||
'string'.format(self.id, filename)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not is_string(directory):
|
||||
elif not isinstance(directory, basestring):
|
||||
msg = 'Unable to export the results for Tally ID={0} to ' \
|
||||
'directory="{1}" since it is not a ' \
|
||||
'string'.format(self.id, directory)
|
||||
|
|
@ -1338,9 +1302,9 @@ class Tally(object):
|
|||
'"{1}" since it is not supported'.format(self.id, format)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not isinstance(append, (bool, np.bool)):
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
from numbers import Real
|
||||
from xml.etree import ElementTree as ET
|
||||
import sys
|
||||
|
||||
from openmc.checkvalue import *
|
||||
from openmc.checkvalue import check_type, check_value
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
|
||||
class Trigger(object):
|
||||
|
|
@ -67,20 +72,13 @@ class Trigger(object):
|
|||
|
||||
@trigger_type.setter
|
||||
def trigger_type(self, trigger_type):
|
||||
if trigger_type not in ['variance', 'std_dev', 'rel_err']:
|
||||
msg = 'Unable to create a tally trigger with ' \
|
||||
'type "{0}"'.format(trigger_type)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_value('tally trigger type', trigger_type,
|
||||
['variance', 'std_dev', 'rel_err'])
|
||||
self._trigger_type = trigger_type
|
||||
|
||||
@threshold.setter
|
||||
def threshold(self, threshold):
|
||||
if not is_float(threshold):
|
||||
msg = 'Unable to set a tally trigger threshold with ' \
|
||||
'threshold "{0}"'.format(threshold)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('tally trigger threshold', threshold, Real)
|
||||
self._threshold = threshold
|
||||
|
||||
def add_score(self, score):
|
||||
|
|
@ -93,7 +91,7 @@ class Trigger(object):
|
|||
|
||||
"""
|
||||
|
||||
if not is_string(score):
|
||||
if not isinstance(score, basestring):
|
||||
msg = 'Unable to add score "{0}" to tally trigger since ' \
|
||||
'it is not a string'.format(score)
|
||||
raise ValueError(msg)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
import abc
|
||||
from collections import OrderedDict
|
||||
from collections import OrderedDict, Iterable
|
||||
from numbers import Real, Integral
|
||||
from xml.etree import ElementTree as ET
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
import openmc
|
||||
from openmc.checkvalue import *
|
||||
from openmc.checkvalue import check_type, check_length, check_greater_than
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
basestring = str
|
||||
|
||||
# A static variable for auto-generated Cell IDs
|
||||
AUTO_CELL_ID = 10000
|
||||
|
|
@ -104,33 +110,19 @@ class Cell(object):
|
|||
global AUTO_CELL_ID
|
||||
self._id = AUTO_CELL_ID
|
||||
AUTO_CELL_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(cell_id):
|
||||
msg = 'Unable to set a non-integer Cell ID {0}'.format(cell_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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)
|
||||
|
||||
else:
|
||||
check_type('cell ID', cell_id, Integral)
|
||||
check_greater_than('cell ID', cell_id, 0)
|
||||
self._id = cell_id
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
if not isinstance(name, str):
|
||||
msg = 'Unable to set name for Cell ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._name = name
|
||||
check_type('cell name', name, basestring)
|
||||
self._name = name
|
||||
|
||||
@fill.setter
|
||||
def fill(self, fill):
|
||||
if isinstance(fill, str):
|
||||
if isinstance(fill, basestring):
|
||||
if fill.strip().lower() == 'void':
|
||||
self._type = 'void'
|
||||
else:
|
||||
|
|
@ -156,56 +148,19 @@ class Cell(object):
|
|||
|
||||
@rotation.setter
|
||||
def rotation(self, rotation):
|
||||
if not isinstance(rotation, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to add rotation {0} to Cell ID={1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(rotation, self._id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(rotation) != 3:
|
||||
msg = 'Unable to add rotation {0} to Cell ID={1} since ' \
|
||||
'it does not contain 3 values'.format(rotation, self._id)
|
||||
raise ValueError(msg)
|
||||
|
||||
for axis in rotation:
|
||||
if not is_integer(axis) and not is_float(axis):
|
||||
msg = 'Unable to add rotation {0} to Cell ID={1} since ' \
|
||||
'it is not an integer or floating point ' \
|
||||
'value'.format(axis, self._id)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._rotation = rotation
|
||||
check_type('cell rotation', rotation, Iterable, Real)
|
||||
check_length('cell rotation', rotation, 3)
|
||||
self._rotation = rotation
|
||||
|
||||
@translation.setter
|
||||
def translation(self, translation):
|
||||
if not isinstance(translation, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to add translation {0} to Cell ID={1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(translation, self._id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(translation) != 3:
|
||||
msg = 'Unable to add translation {0} to Cell ID={1} since ' \
|
||||
'it does not contain 3 values'.format(translation, self._id)
|
||||
raise ValueError(msg)
|
||||
|
||||
for axis in translation:
|
||||
if not is_integer(axis) and not is_float(axis):
|
||||
msg = 'Unable to add translation {0} to Cell ID={1} since ' \
|
||||
'it is not an integer or floating point ' \
|
||||
'value'.format(axis, self._id)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('cell translation', translation, Iterable, Real)
|
||||
check_length('cell translation', translation, 3)
|
||||
self._translation = translation
|
||||
|
||||
@offsets.setter
|
||||
def offsets(self, offsets):
|
||||
if not isinstance(offsets, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set offsets {0} to Cell ID={1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(offsets, self._id)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('cell offsets', offsets, Iterable)
|
||||
self._offsets = offsets
|
||||
|
||||
def add_surface(self, surface, halfspace):
|
||||
|
|
@ -476,30 +431,15 @@ class Universe(object):
|
|||
global AUTO_UNIVERSE_ID
|
||||
self._id = AUTO_UNIVERSE_ID
|
||||
AUTO_UNIVERSE_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(universe_id):
|
||||
msg = 'Unable to set Universe ID to a non-integer ' \
|
||||
'{0}'.format(universe_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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)
|
||||
|
||||
else:
|
||||
check_type('universe ID', universe_id, Integral)
|
||||
check_greater_than('universe ID', universe_id, 0, True)
|
||||
self._id = universe_id
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Universe ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._name = name
|
||||
check_type('universe name', name, basestring)
|
||||
self._name = name
|
||||
|
||||
def add_cell(self, cell):
|
||||
"""Add a cell to the universe.
|
||||
|
|
@ -531,13 +471,13 @@ class Universe(object):
|
|||
|
||||
"""
|
||||
|
||||
if not isinstance(cells, (list, tuple, np.ndarray)):
|
||||
msg = 'Unable to add Cells to Universe ID={0} since {1} is not a ' \
|
||||
'Python tuple/list or NumPy array'.format(self._id, cells)
|
||||
if not isinstance(cells, Iterable):
|
||||
msg = 'Unable to add Cells to Universe ID={0} since {1} is not ' \
|
||||
'iterable'.format(self._id, cells)
|
||||
raise ValueError(msg)
|
||||
|
||||
for i in range(len(cells)):
|
||||
self.add_cell(cells[i])
|
||||
for cell in cells:
|
||||
self.add_cell(cell)
|
||||
|
||||
def remove_cell(self, cell):
|
||||
"""Remove a cell from the universe.
|
||||
|
|
@ -730,47 +670,24 @@ class Lattice(object):
|
|||
global AUTO_UNIVERSE_ID
|
||||
self._id = AUTO_UNIVERSE_ID
|
||||
AUTO_UNIVERSE_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(lattice_id):
|
||||
msg = 'Unable to set non-integer Lattice ID {0}'.format(lattice_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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)
|
||||
|
||||
else:
|
||||
check_type('lattice ID', lattice_id, Integral)
|
||||
check_greater_than('lattice ID', lattice_id, 0)
|
||||
self._id = lattice_id
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Lattice ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._name = name
|
||||
check_type('lattice name', name, basestring)
|
||||
self._name = name
|
||||
|
||||
@outer.setter
|
||||
def outer(self, outer):
|
||||
if not isinstance(outer, Universe):
|
||||
msg = 'Unable to set Lattice ID={0} outer universe to {1} ' \
|
||||
'since it is not a Universe object'.format(self._id, outer)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('outer universe', outer, Universe)
|
||||
self._outer = outer
|
||||
|
||||
@universes.setter
|
||||
def universes(self, universes):
|
||||
if not isinstance(universes, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set Lattice ID={0} universes to {1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, universes)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('lattice universes', universes, Iterable)
|
||||
self._universes = np.asarray(universes, dtype=Universe)
|
||||
|
||||
def get_unique_universes(self):
|
||||
|
|
@ -908,90 +825,29 @@ class RectLattice(Lattice):
|
|||
|
||||
@dimension.setter
|
||||
def dimension(self, dimension):
|
||||
if not isinstance(dimension, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set RectLattice ID={0} dimension to {1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(dimension) != 2 and len(dimension) != 3:
|
||||
msg = 'Unable to set RectLattice ID={0} dimension to {1} since ' \
|
||||
'it does not contain 2 or 3 ' \
|
||||
'coordinates'.format(self._id, dimension)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('lattice dimension', dimension, Iterable, Integral)
|
||||
check_length('lattice dimension', dimension, 2, 3)
|
||||
for dim in dimension:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to set RectLattice ID={0} dimension to {1} since ' \
|
||||
'it is not an integer or floating point ' \
|
||||
'value'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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
|
||||
def lower_left(self, lower_left):
|
||||
if not isinstance(lower_left, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set RectLattice ID={0} lower_left to {1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(lower_left) != 2 and len(lower_left) != 3:
|
||||
msg = 'Unable to set RectLattice ID={0} lower_left to {1} ' \
|
||||
'since it does not contain 2 or 3 ' \
|
||||
'coordinates'.format(self._id, lower_left)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in lower_left:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to set RectLattice ID={0} lower_left to {1} since ' \
|
||||
'it is is not an integer or floating point ' \
|
||||
'value'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('lattice lower left corner', lower_left, Iterable, Real)
|
||||
check_length('lattice lower left corner', lower_left, 2, 3)
|
||||
self._lower_left = lower_left
|
||||
|
||||
@offsets.setter
|
||||
def offsets(self, offsets):
|
||||
if not isinstance(offsets, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set Lattice ID={0} offsets to {1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, offsets)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('lattice offsets', offsets, Iterable)
|
||||
self._offsets = offsets
|
||||
|
||||
@Lattice.pitch.setter
|
||||
def pitch(self, pitch):
|
||||
if not isinstance(pitch, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set Lattice ID={0} pitch to {1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, pitch)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(pitch) != 2 and len(pitch) != 3:
|
||||
msg = 'Unable to set Lattice ID={0} pitch to {1} since it does ' \
|
||||
'not contain 2 or 3 coordinates'.format(self._id, pitch)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('lattice pitch', pitch, Iterable, Real)
|
||||
check_length('lattice pitch', pitch, 2, 3)
|
||||
for dim in pitch:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to set Lattice ID={0} pitch to {1} since ' \
|
||||
'it is not an an integer or floating point ' \
|
||||
'value'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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):
|
||||
|
|
@ -1184,71 +1040,28 @@ class HexLattice(Lattice):
|
|||
|
||||
@num_rings.setter
|
||||
def num_rings(self, num_rings):
|
||||
|
||||
if not is_integer(num_rings) 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 is_integer(num_axial) 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
|
||||
def center(self, center):
|
||||
if not isinstance(center, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set HexLattice ID={0} dimension to {1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, center)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(center) != 2 and len(center) != 3:
|
||||
msg = 'Unable to set HexLattice ID={0} center to {1} since ' \
|
||||
'it does not contain 2 or 3 ' \
|
||||
'coordinates'.format(self._id, center)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in center:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to set HexLattice ID={0} center to {1} since ' \
|
||||
'it is not an integer or floating point ' \
|
||||
'value'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('lattice center', center, Iterable, Real)
|
||||
check_length('lattice center', center, 2, 3)
|
||||
self._center = center
|
||||
|
||||
@Lattice.pitch.setter
|
||||
def pitch(self, pitch):
|
||||
if not isinstance(pitch, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to set Lattice ID={0} pitch to {1} since ' \
|
||||
'it is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, pitch)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(pitch) != 2 and len(pitch) != 3:
|
||||
msg = 'Unable to set Lattice ID={0} pitch to {1} since it does ' \
|
||||
'not contain 2 or 3 coordinates'.format(self._id, pitch)
|
||||
raise ValueError(msg)
|
||||
|
||||
check_type('lattice pitch', pitch, Iterable, Real)
|
||||
check_length('lattice pitch', pitch, 2, 3)
|
||||
for dim in pitch:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to set Lattice ID={0} pitch to {1} since ' \
|
||||
'it is not an an integer or floating point ' \
|
||||
'value'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue