Address more comments on pull request #556.

This commit is contained in:
Paul Romano 2016-01-15 06:29:41 -06:00
parent 66f1d7b840
commit 148e01eec0
20 changed files with 86 additions and 181 deletions

View file

@ -147,7 +147,7 @@
"import openmc\n",
"import openmc.mgxs as mgxs\n",
"from openmc.source import Source\n",
"from openmc.stats import SpatialBox\n",
"from openmc.stats import Box\n",
"\n",
"%matplotlib inline"
]
@ -343,7 +343,7 @@
"settings_file.particles = particles\n",
"settings_file.output = {'tallies': True, 'summary': True}\n",
"bounds = [-0.63, -0.63, -0.63, 0.63, 0.63, 0.63]\n",
"settings_file.source = Source(space=SpatialBox(\n",
"settings_file.source = Source(space=Box(\n",
" bounds[:3], bounds[3:], only_fissionable=True))\n",
"\n",
"# Export to \"settings.xml\"\n",

View file

@ -53,7 +53,7 @@
"import openmc\n",
"import openmc.mgxs as mgxs\n",
"from openmc.source import Source\n",
"from openmc.stats import SpatialBox\n",
"from openmc.stats import Box\n",
"import openmoc\n",
"from openmoc.compatible import get_openmoc_geometry\n",
"import pyne.ace\n",
@ -288,7 +288,7 @@
"settings_file.particles = particles\n",
"settings_file.output = {'tallies': True, 'summary': True}\n",
"bounds = [-0.63, -0.63, -0.63, 0.63, 0.63, 0.63]\n",
"settings_file.source = Source(space=SpatialBox(\n",
"settings_file.source = Source(space=Box(\n",
" bounds[:3], bounds[3:], only_fissionable=True))\n",
"\n",
"# Activate tally precision triggers\n",

View file

@ -53,7 +53,7 @@
"from openmc.statepoint import StatePoint\n",
"from openmc.summary import Summary\n",
"from openmc.source import Source\n",
"from openmc.stats import SpatialBox\n",
"from openmc.stats import Box\n",
"\n",
"import openmoc\n",
"import openmoc.process\n",
@ -394,7 +394,7 @@
"settings_file.particles = particles\n",
"settings_file.output = {'tallies': False, 'summary': True}\n",
"source_bounds = [-10.71, -10.71, -10, 10.71, 10.71, 10.]\n",
"settings_file.source = Source(SpatialBox(\n",
"settings_file.source = Source(Box(\n",
" source_bounds[:3], source_bounds[3:], only_fissionable=True))\n",
"\n",
"# Export to \"settings.xml\"\n",

View file

@ -27,7 +27,7 @@
"from openmc.statepoint import StatePoint\n",
"from openmc.summary import Summary\n",
"from openmc.source import Source\n",
"from openmc.stats import SpatialBox\n",
"from openmc.stats import Box\n",
"\n",
"%matplotlib inline"
]
@ -306,7 +306,7 @@
"settings_file.trigger_active = True\n",
"settings_file.trigger_max_batches = max_batches\n",
"source_bounds = [-10.71, -10.71, -10, 10.71, 10.71, 10.]\n",
"settings_file.source = Source(space=SpatialBox(\n",
"settings_file.source = Source(space=Box(\n",
" source_bounds[:3], source_bounds[3:]))\n",
"\n",
"# Export to \"settings.xml\"\n",

View file

@ -22,7 +22,7 @@
"import openmc\n",
"from openmc.statepoint import StatePoint\n",
"from openmc.source import Source\n",
"from openmc.stats import SpatialBox\n",
"from openmc.stats import Box\n",
"\n",
"%matplotlib inline"
]
@ -274,7 +274,7 @@
"settings_file.inactive = inactive\n",
"settings_file.particles = particles\n",
"source_bounds = [-0.63, -0.63, -0.63, 0.63, 0.63, 0.63]\n",
"settings_file.source = Source(space=SpatialBox(\n",
"settings_file.source = Source(space=Box(\n",
" source_bounds[:3], source_bounds[3:]))\n",
"\n",
"# Export to \"settings.xml\"\n",

View file

@ -37,7 +37,7 @@
"from openmc.statepoint import StatePoint\n",
"from openmc.summary import Summary\n",
"from openmc.source import Source\n",
"from openmc.stats import SpatialBox\n",
"from openmc.stats import Box\n",
"\n",
"%matplotlib inline"
]
@ -290,7 +290,7 @@
"settings_file.particles = particles\n",
"settings_file.output = {'tallies': True, 'summary': True}\n",
"source_bounds = [-0.63, -0.63, -0.63, 0.63, 0.63, 0.63]\n",
"settings_file.source = Source(space=SpatialBox(\n",
"settings_file.source = Source(space=Box(\n",
" source_bounds[:3], source_bounds[3:]))\n",
"\n",
"# Export to \"settings.xml\"\n",

View file

@ -469,7 +469,7 @@ attributes/sub-elements:
three real numbers which specify the (x,y,z) location of an isotropic
point source.
For an "independent" distributoin, no parameters are specified. Instead,
For an "independent" distribution, no parameters are specified. Instead,
the ``x``, ``y``, and ``z`` elements must be specified.
*Default*: None

View file

@ -1,6 +1,6 @@
import openmc
from openmc.source import Source
from openmc.stats import SpatialBox
from openmc.stats import Box
###############################################################################
# Simulation Input File Parameters
@ -94,7 +94,7 @@ settings_file = openmc.SettingsFile()
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.source = Source(space=SpatialBox([-4, -4, -4], [4, 4, 4]))
settings_file.source = Source(space=Box([-4, -4, -4], [4, 4, 4]))
settings_file.export_to_xml()

View file

@ -2,7 +2,7 @@ import numpy as np
import openmc
from openmc.source import Source
from openmc.stats import SpatialBox
from openmc.stats import Box
###############################################################################
# Simulation Input File Parameters
@ -119,7 +119,7 @@ settings_file = openmc.SettingsFile()
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.source = Source(space=SpatialBox(*outer_cube.bounding_box))
settings_file.source = Source(space=Box(*outer_cube.bounding_box))
settings_file.export_to_xml()
###############################################################################

View file

@ -1,6 +1,6 @@
import openmc
from openmc.source import Source
from openmc.stats import SpatialBox
from openmc.stats import Box
###############################################################################
# Simulation Input File Parameters
@ -126,7 +126,7 @@ settings_file = openmc.SettingsFile()
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.source = Source(space=SpatialBox(
settings_file.source = Source(space=Box(
[-1, -1, -1], [1, 1, 1]))
settings_file.keff_trigger = {'type' : 'std_dev', 'threshold' : 5E-4}
settings_file.trigger_active = True

View file

@ -1,6 +1,6 @@
import openmc
from openmc.source import Source
from openmc.stats import SpatialBox
from openmc.stats import Box
###############################################################################
# Simulation Input File Parameters
@ -137,7 +137,7 @@ settings_file = openmc.SettingsFile()
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.source = Source(space=SpatialBox(
settings_file.source = Source(space=Box(
[-1, -1, -1], [1, 1, 1]))
settings_file.export_to_xml()

View file

@ -1,6 +1,6 @@
import openmc
from openmc.source import Source
from openmc.stats import SpatialBox
from openmc.stats import Box
###############################################################################
# Simulation Input File Parameters
@ -127,7 +127,7 @@ settings_file = openmc.SettingsFile()
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.source = Source(space=SpatialBox(
settings_file.source = Source(space=Box(
[-1, -1, -1], [1, 1, 1]))
settings_file.trigger_active = True
settings_file.trigger_max_batches = 100

View file

@ -1,6 +1,6 @@
import openmc
from openmc.source import Source
from openmc.stats import SpatialBox
from openmc.stats import Box
###############################################################################
# Simulation Input File Parameters
@ -170,7 +170,7 @@ settings_file = openmc.SettingsFile()
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.source = Source(space=SpatialBox(
settings_file.source = Source(space=Box(
[-0.62992, -0.62992, -1], [0.62992, 0.62992, 1]))
settings_file.entropy_lower_left = [-0.39218, -0.39218, -1.e50]
settings_file.entropy_upper_right = [0.39218, 0.39218, 1.e50]

View file

@ -1,7 +1,7 @@
import numpy as np
import openmc
from openmc.stats import SpatialBox
from openmc.stats import Box
from openmc.source import Source
###############################################################################
@ -86,5 +86,5 @@ settings_file = openmc.SettingsFile()
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.source = Source(space=SpatialBox(*cell.region.bounding_box))
settings_file.source = Source(space=Box(*cell.region.bounding_box))
settings_file.export_to_xml()

View file

@ -95,8 +95,6 @@ class Source(object):
@energy.setter
def energy(self, energy):
cv.check_type('energy distribution', energy, Univariate)
if energy.name is None:
energy.name = 'energy'
self._energy = energy
@strength.setter
@ -115,5 +113,5 @@ class Source(object):
if self.angle is not None:
element.append(self.angle.to_xml())
if self.energy is not None:
element.append(self.energy.to_xml())
element.append(self.energy.to_xml('energy'))
return element

View file

@ -23,15 +23,11 @@ class UnitSphere(object):
Parameters
----------
name : str
Name of the distribution
reference_uvw : Iterable of Real
Direction from which polar angle is measured
Attributes
----------
name : str
Name of the distribution
reference_uvw : Iterable of Real
Direction from which polar angle is measured
@ -39,25 +35,15 @@ class UnitSphere(object):
__metaclass__ = ABCMeta
def __init__(self, name, reference_uvw=None):
self.name = name
def __init__(self, reference_uvw=None):
self._reference_uvw = None
if reference_uvw is not None:
self.reference_uvw = reference_uvw
@property
def name(self):
return self._name
@property
def reference_uvw(self):
return self._reference_uvw
@name.setter
def name(self, name):
cv.check_type('name', name, basestring)
self._name = name
@reference_uvw.setter
def reference_uvw(self, uvw):
cv.check_type('reference direction', uvw, Iterable, Real)
@ -81,8 +67,6 @@ class PolarAzimuthal(UnitSphere):
Distribution of the cosine of the polar angle
phi : openmc.stats.Univariate
Distribution of the azimuthal angle in radians
name : str, optional
Name of the distribution. Defaults to 'angle'.
reference_uvw : Iterable of Real
Direction from which polar angle is measured. Defaults to the positive
z-direction.
@ -96,9 +80,8 @@ class PolarAzimuthal(UnitSphere):
"""
def __init__(self, mu=None, phi=None, name='angle',
reference_uvw=[0., 0., 1.]):
super(PolarAzimuthal, self).__init__(name, reference_uvw)
def __init__(self, mu=None, phi=None, reference_uvw=[0., 0., 1.]):
super(PolarAzimuthal, self).__init__(reference_uvw)
if mu is not None:
self.mu = mu
else:
@ -120,42 +103,33 @@ class PolarAzimuthal(UnitSphere):
@mu.setter
def mu(self, mu):
cv.check_type('cosine of polar angle', mu, Univariate)
if mu.name is None:
mu.name = 'mu'
self._mu = mu
@phi.setter
def phi(self, phi):
cv.check_type('azimuthal angle', phi, Univariate)
if phi.name is None:
phi.name = 'phi'
self._phi = phi
def to_xml(self):
element = ET.Element(self.name)
element = ET.Element('angle')
element.set("type", "mu-phi")
if self.reference_uvw is not None:
element.set("reference_uvw", ' '.join(map(str, self.reference_uvw)))
element.append(self.mu.to_xml())
element.append(self.phi.to_xml())
element.append(self.mu.to_xml('mu'))
element.append(self.phi.to_xml('phi'))
return element
class Isotropic(UnitSphere):
"""Isotropic angular distribution.
Parameters
----------
name : str, optional
Name of the distribution. Defaults to 'angle'.
"""
def __init__(self, name='angle'):
super(Isotropic, self).__init__(name)
def __init__(self):
super(Isotropic, self).__init__()
def to_xml(self):
element = ET.Element(self.name)
element = ET.Element('angle')
element.set("type", "isotropic")
return element
@ -169,8 +143,6 @@ class Monodirectional(UnitSphere):
Parameters
----------
name : str, optional
Name of the distribution. Defaults to 'angle'.
reference_uvw : Iterable of Real
Direction from which polar angle is measured. Defaults to the positive
x-direction.
@ -178,11 +150,11 @@ class Monodirectional(UnitSphere):
"""
def __init__(self, name='angle', reference_uvw=[1., 0., 0.]):
super(Monodirectional, self).__init__(name, reference_uvw)
def __init__(self, reference_uvw=[1., 0., 0.]):
super(Monodirectional, self).__init__(reference_uvw)
def to_xml(self):
element = ET.Element(self.name)
element = ET.Element('angle')
element.set("type", "monodirectional")
if self.reference_uvw is not None:
element.set("reference_uvw", ' '.join(map(str, self.reference_uvw)))
@ -195,38 +167,19 @@ class Spatial(object):
Classes derived from this abstract class can be used for spatial
distributions of source sites.
Parameters
----------
name : str
Name of the distribution
Attributes
----------
name : str
Name of the distribution
"""
__metaclass__ = ABCMeta
def __init__(self, name):
self.name = name
@property
def name(self):
return self._name
@name.setter
def name(self, name):
cv.check_type('name', name, basestring)
self._name = name
def __init__(self):
pass
@abstractmethod
def to_xml(self):
return ''
class SpatialIndependent(Spatial):
class CartesianIndependent(Spatial):
"""Spatial distribution with independent x, y, and z distributions.
This distribution allows one to specify a coordinates whose x-, y-, and z-
@ -240,8 +193,6 @@ class SpatialIndependent(Spatial):
Distribution of y-coordinates
z : openmc.stats.Univariate
Distribution of z-coordinates
name : str
Name of the distribution
Attributes
----------
@ -255,8 +206,8 @@ class SpatialIndependent(Spatial):
"""
def __init__(self, x, y, z, name='space'):
super(SpatialIndependent, self).__init__(name)
def __init__(self, x, y, z):
super(CartesianIndependent, self).__init__()
self.x = x
self.y = y
self.z = z
@ -276,34 +227,28 @@ class SpatialIndependent(Spatial):
@x.setter
def x(self, x):
cv.check_type('x coordinate', x, Univariate)
if x.name is None:
x.name = 'x'
self._x = x
@y.setter
def y(self, y):
cv.check_type('y coordinate', y, Univariate)
if y.name is None:
y.name = 'y'
self._y = y
@z.setter
def z(self, z):
cv.check_type('z coordinate', z, Univariate)
if z.name is None:
z.name = 'z'
self._z = z
def to_xml(self):
element = ET.Element(self.name)
element = ET.Element('space')
element.set("type", "independent")
element.append(self.x.to_xml())
element.append(self.y.to_xml())
element.append(self.z.to_xml())
element.append(self.x.to_xml('x'))
element.append(self.y.to_xml('y'))
element.append(self.z.to_xml('z'))
return element
class SpatialBox(Spatial):
class Box(Spatial):
"""Uniform distribution of coordinates in a rectangular cuboid.
Parameters
@ -312,8 +257,6 @@ class SpatialBox(Spatial):
Lower-left coordinates of cuboid
upper_right : Iterable of Real
Upper-right coordinates of cuboid
name : str, optional
Name of the distribution
only_fissionable : bool, optional
Whether spatial sites should only be accepted if they occur in
fissionable materials
@ -331,8 +274,8 @@ class SpatialBox(Spatial):
"""
def __init__(self, lower_left, upper_right, name='space', only_fissionable=False):
super(SpatialBox, self).__init__(name)
def __init__(self, lower_left, upper_right, only_fissionable=False):
super(Box, self).__init__()
self.lower_left = lower_left
self.upper_right = upper_right
self.only_fissionable = only_fissionable
@ -367,7 +310,7 @@ class SpatialBox(Spatial):
self._only_fissionable = only_fissionable
def to_xml(self):
element = ET.Element(self.name)
element = ET.Element('space')
if self.only_fissionable:
element.set("type", "fission")
else:
@ -378,7 +321,7 @@ class SpatialBox(Spatial):
return element
class SpatialPoint(Spatial):
class Point(Spatial):
"""Delta function in three dimensions.
This spatial distribution can be used for a point source where sites are
@ -388,8 +331,6 @@ class SpatialPoint(Spatial):
----------
xyz : Iterable of Real
Cartesian coordinates of location
name : str, optional
Name of the distribution
Attributes
----------
@ -398,8 +339,8 @@ class SpatialPoint(Spatial):
"""
def __init__(self, xyz, name='space'):
super(SpatialPoint, self).__init__(name)
def __init__(self, xyz):
super(Point, self).__init__()
self.xyz = xyz
@property
@ -413,7 +354,7 @@ class SpatialPoint(Spatial):
self._xyz = xyz
def to_xml(self):
element = ET.Element(self.name)
element = ET.Element('space')
element.set("type", "point")
params = ET.SubElement(element, "parameters")
params.text = ' '.join(map(str, self.xyz))

View file

@ -16,33 +16,12 @@ class Univariate(object):
The Univariate class is an abstract class that can be derived to implement a
specific probability distribution.
Parameters
----------
name : str
Name of the distribution
Attributes
----------
name : str
Name of the distributions
"""
__metaclass__ = ABCMeta
def __init__(self, name=None):
self._name = None
if name is not None:
self.name = name
@property
def name(self):
return self._name
@name.setter
def name(self, name):
cv.check_type('name', name, basestring)
self._name = name
def __init__(self):
pass
@abstractmethod
def to_xml(self):
@ -72,8 +51,8 @@ class Discrete(Univariate):
"""
def __init__(self, x, p, name=None):
super(Discrete, self).__init__(name)
def __init__(self, x, p):
super(Discrete, self).__init__()
self.x = x
self.p = p
@ -101,11 +80,8 @@ class Discrete(Univariate):
cv.check_greater_than('discrete probability', pk, 0.0, True)
self._p = p
def to_xml(self):
if self.name is not None:
element = ET.Element(self.name)
else:
element = ET.Element('distribution')
def to_xml(self, element_name):
element = ET.Element(element_name)
element.set("type", "discrete")
params = ET.SubElement(element, "parameters")
@ -133,8 +109,8 @@ class Uniform(Univariate):
"""
def __init__(self, a=0.0, b=1.0, name=None):
super(Uniform, self).__init__(name)
def __init__(self, a=0.0, b=1.0):
super(Uniform, self).__init__()
self.a = a
self.b = b
@ -156,11 +132,8 @@ class Uniform(Univariate):
cv.check_type('Uniform b', b, Real)
self._b = b
def to_xml(self):
if self.name is not None:
element = ET.Element(self.name)
else:
element = ET.Element('distribution')
def to_xml(self, element_name):
element = ET.Element(element_name)
element.set("type", "uniform")
element.set("parameters", '{} {}'.format(self.a, self.b))
return element
@ -185,8 +158,8 @@ class Maxwell(Univariate):
"""
def __init__(self, theta, name='energy'):
super(Maxwell, self).__init__(name)
def __init__(self, theta):
super(Maxwell, self).__init__()
self.theta = theta
@property
@ -199,8 +172,8 @@ class Maxwell(Univariate):
cv.check_greater_than('Maxwell temperature', theta, 0.0)
self._theta = theta
def to_xml(self):
element = ET.Element(self.name)
def to_xml(self, element_name):
element = ET.Element(element_name)
element.set("type", "maxwell")
element.set("parameters", str(self.theta))
return element
@ -219,8 +192,6 @@ class Watt(Univariate):
First parameter of distribution
b : float
Second parameter of distribution
name : str, optional
Name of the distribution. Defaults to 'energy'.
Attributes
----------
@ -231,8 +202,8 @@ class Watt(Univariate):
"""
def __init__(self, a=0.988, b=2.249, name='energy'):
super(Watt, self).__init__(name)
def __init__(self, a=0.988, b=2.249):
super(Watt, self).__init__()
self.a = a
self.b = b
@ -256,8 +227,8 @@ class Watt(Univariate):
cv.check_greater_than('Watt b', b, 0.0)
self._b = b
def to_xml(self):
element = ET.Element(self.name)
def to_xml(self, element_name):
element = ET.Element(element_name)
element.set("type", "watt")
element.set("parameters", '{} {}'.format(self.a, self.b))
return element
@ -272,8 +243,6 @@ class Tabular(Univariate):
Parameters
----------
name : str
Name of the distribution
x : Iterable of Real
Tabulated values of the random variable
p : Iterable of Real
@ -294,8 +263,8 @@ class Tabular(Univariate):
"""
def __init__(self, x, p, interpolation='linear-linear', name=None):
super(Tabular, self).__init__(name)
def __init__(self, x, p, interpolation='linear-linear'):
super(Tabular, self).__init__()
self.x = x
self.p = p
self.interpolation = interpolation
@ -330,11 +299,8 @@ class Tabular(Univariate):
['linear-linear', 'histogram'])
self._interpolation = interpolation
def to_xml(self):
if self.name is not None:
element = ET.Element(self.name)
else:
element = ET.Element('distribution')
def to_xml(self, element_name):
element = ET.Element(element_name)
element.set("type", "tabular")
element.set("interpolation", self.interpolation)

View file

@ -1,6 +1,6 @@
import openmc
from openmc.source import Source
from openmc.stats import SpatialBox
from openmc.stats import Box
class InputSet(object):
@ -560,7 +560,7 @@ class InputSet(object):
self.settings.batches = 10
self.settings.inactive = 5
self.settings.particles = 100
self.settings.source = Source(space=SpatialBox(
self.settings.source = Source(space=Box(
[-160, -160, -183], [160, 160, 183]))
def build_defualt_plots(self):

View file

@ -5,7 +5,7 @@ import sys
sys.path.insert(0, os.pardir)
from testing_harness import TestHarness, PyAPITestHarness
import openmc
from openmc.stats import SpatialBox
from openmc.stats import Box
from openmc.source import Source
@ -87,7 +87,7 @@ class DistribmatTestHarness(PyAPITestHarness):
sets_file.batches = 5
sets_file.inactive = 0
sets_file.particles = 1000
sets_file.source = Source(space=SpatialBox([-1, -1, -1], [1, 1, 1]))
sets_file.source = Source(space=Box([-1, -1, -1], [1, 1, 1]))
sets_file.output = {'summary': True}
sets_file.export_to_xml()

View file

@ -39,9 +39,9 @@ class SourceTestHarness(PyAPITestHarness):
x_dist = openmc.stats.Uniform(-3., 3.)
y_dist = openmc.stats.Discrete([-4., -1., 3.], [0.2, 0.3, 0.5])
z_dist = openmc.stats.Tabular([-2., 0., 2.], [0.2, 0.3, 0.2])
spatial1 = openmc.stats.SpatialIndependent(x_dist, y_dist, z_dist)
spatial2 = openmc.stats.SpatialBox([-4., -4., -4.], [4., 4., 4.])
spatial3 = openmc.stats.SpatialPoint([1.2, -2.3, 0.781])
spatial1 = openmc.stats.CartesianIndependent(x_dist, y_dist, z_dist)
spatial2 = openmc.stats.Box([-4., -4., -4.], [4., 4., 4.])
spatial3 = openmc.stats.Point([1.2, -2.3, 0.781])
mu_dist = openmc.stats.Discrete([-1., 0., 1.], [0.5, 0.25, 0.25])
phi_dist = openmc.stats.Uniform(0., 6.28318530718)