Simply MeshFilter.__init__

This commit is contained in:
Sterling Harper 2016-09-30 00:01:10 -04:00
parent e464e22690
commit 52c9898128
19 changed files with 209 additions and 183 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -338,7 +338,7 @@
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6AgMAAAD1grKuAAAABGdBTUEAALGPC/xhBQAAACBjSFJN\nAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAADFBMVEX///9yEhLpgJFNv8Tq\nQYT7AAAAAWJLR0QAiAUdSAAAAAd0SU1FB+AJFRQqB1pnJtkAAALKSURBVGje7dpLcqQwDAbgHHE2\nYeEj+D4cwQucBUfo+3CEXoSp8OhuhF70T4qpKXmdr21LogK2Pj7A8QmNP+HDhw8fPnz48Kf6VH9G\n+66vy+je8k19jnf8C5dXIPv86ms56lPdjvaYbyodx3ze+XLE76cXFiD4zPji99z0/AJ4n1lfvJ6f\nnl0A6x+578efMSg1wPr172/jPO5yFXM+Ef78gdblM+WPHyguP//t1/g6pA0wfln+ho/fwgYYn19C\n/xwDvwHGc9OvC+hs37DTrwuwfWanXxdQTC9Mvyygs3wjTL8uwPJpn/tNDbSGz7T0SBEWw4vLXzbQ\n6b6RoveIoO6TvPxlA63qs7z8ZQPF9F+SH22vbX8OQKf5Rtv+EgDNJ3X58wZaxWd1+fMGiuFvir8b\nvjp8J/tGy/6jAmRvhW8fwL3vVT+o3grfPoB7r/IpALI3tz8FoJN84/NV873hB8UnM3xzANtf8nb4\ndwmg3grfFEDJO8JPE0i9Ff4pAYL3pI8mkHor/HMCeO9JH00g9SafEsh7T/ppARBvp48UwJnelT5S\nACd7O31TAlnvKx9SQCd7B58KgPO+8iMFuPWe9E8F8BveWX7bAjzX9y4//Jve+fhsH6Ctv7n8PTzj\nvY/v9gEOHz58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QKf5Rtv+EgDNJ3X58wZaxWd1+fMGiuFvir8b\nvjp8J/tGy/6jAmRvhW8fwL3vVT+o3grfPoB7r/IpALI3tz8FoJN84/NV873hB8UnM3xzANtf8nb4\ndwmg3grfFEDJO8JPE0i9Ff4pAYL3pI8mkHor/HMCeO9JH00g9SafEsh7T/ppARBvp48UwJnelT5S\nACd7O31TAlnvKx9SQCd7B58KgPO+8iMFuPWe9E8F8BveWX7bAjzX9y4//Jve+fhsH6Ctv7n8PTzj\nvY/v9gEOHz58+PBX+6v/f/wPvnd54f3j6venE/yl769Xv7+j3x/o98/V32/o9+fl389Xnx+g5x/o\n+Qt6/oOeP6HnX+j5G3z+h54/ouefV5/foufP6Pk3ev4On/+j9w/o/Qd6/4Le/6D3T/D9V67Y/ZsV\nQBq+s+8f0ftP+P41axXguP9NWgDuu/Cdfv+N3r/D9/9TAID+A7T/Ae2/gPs/0P4TtP8F7r9J3AIO\n9P+g/Udw/9Oygbf7r9D+L7j/DO1/Q/vv4P4/tP8Q7n9E+y/h/k+0/xTuf4X7b+H+X7T/+BPuf3aM\n8OHDhw8fPnz4w/4vzcvgeY10sY0AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTYtMDktMjlUMjM6NTg6\nNTItMDQ6MDBn7ClZAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE2LTA5LTI5VDIzOjU4OjUyLTA0OjAw\nFrGR5QAAAABJRU5ErkJggg==\n",
"text/plain": [
"<IPython.core.display.Image object>"
]
@ -417,8 +417,7 @@
"mesh.dimension = [1, 1, 1]\n",
"mesh.lower_left = [-0.63, -0.63, -100.]\n",
"mesh.width = [1.26, 1.26, 200.]\n",
"mesh_filter = openmc.MeshFilter(mesh.id)\n",
"mesh_filter.mesh = mesh\n",
"mesh_filter = openmc.MeshFilter(mesh)\n",
"\n",
"# Instantiate thermal, fast, and total leakage tallies\n",
"leak = openmc.Tally(name='leakage')\n",
@ -579,8 +578,8 @@
" Copyright | 2011-2016 Massachusetts Institute of Technology\n",
" License | http://openmc.readthedocs.io/en/latest/license.html\n",
" Version | 0.8.0\n",
" Git SHA1 | 57371d217a270b4013af4e33ca20b0053654b190\n",
" Date/Time | 2016-09-21 16:42:14\n",
" Git SHA1 | b02fa21928a37a2254bec13c9802ff8173b6aefd\n",
" Date/Time | 2016-09-29 23:59:21\n",
" MPI Processes | 1\n",
"\n",
" ===========================================================================\n",
@ -637,20 +636,20 @@
"\n",
" =======================> TIMING STATISTICS <=======================\n",
"\n",
" Total time for initialization = 2.8800E-01 seconds\n",
" Reading cross sections = 1.6900E-01 seconds\n",
" Total time in simulation = 1.5410E+01 seconds\n",
" Time in transport only = 1.5395E+01 seconds\n",
" Time in inactive batches = 2.3750E+00 seconds\n",
" Time in active batches = 1.3035E+01 seconds\n",
" Time synchronizing fission bank = 4.0000E-03 seconds\n",
" Sampling source sites = 2.0000E-03 seconds\n",
" SEND/RECV source sites = 2.0000E-03 seconds\n",
" Time accumulating tallies = 1.0000E-03 seconds\n",
" Total time for finalization = 3.0000E-03 seconds\n",
" Total time elapsed = 1.5718E+01 seconds\n",
" Calculation Rate (inactive) = 5263.16 neutrons/second\n",
" Calculation Rate (active) = 2876.87 neutrons/second\n",
" Total time for initialization = 2.9900E-01 seconds\n",
" Reading cross sections = 1.8000E-01 seconds\n",
" Total time in simulation = 1.6156E+01 seconds\n",
" Time in transport only = 1.6145E+01 seconds\n",
" Time in inactive batches = 2.3940E+00 seconds\n",
" Time in active batches = 1.3762E+01 seconds\n",
" Time synchronizing fission bank = 1.0000E-03 seconds\n",
" Sampling source sites = 1.0000E-03 seconds\n",
" SEND/RECV source sites = 0.0000E+00 seconds\n",
" Time accumulating tallies = 0.0000E+00 seconds\n",
" Total time for finalization = 1.0000E-03 seconds\n",
" Total time elapsed = 1.6476E+01 seconds\n",
" Calculation Rate (inactive) = 5221.39 neutrons/second\n",
" Calculation Rate (active) = 2724.89 neutrons/second\n",
"\n",
" ============================> RESULTS <============================\n",
"\n",

View file

@ -162,8 +162,7 @@ mesh.lower_left = [-2, -2]
mesh.width = [1, 1]
# Instantiate tally Filter
mesh_filter = openmc.MeshFilter(mesh.id)
mesh_filter.mesh = mesh
mesh_filter = openmc.MeshFilter(mesh)
# Instantiate the Tally
tally = openmc.Tally(tally_id=1)

View file

@ -155,8 +155,7 @@ mesh.lower_left = [-2, -2]
mesh.width = [1, 1]
# Instantiate tally Filter
mesh_filter = openmc.MeshFilter(mesh.id)
mesh_filter.mesh = mesh
mesh_filter = openmc.MeshFilter(mesh)
# Instantiate tally Trigger
trigger = openmc.Trigger(trigger_type='rel_err', threshold=1E-2)

View file

@ -186,8 +186,7 @@ mesh.upper_right = [0.62992, 0.62992, 1.e50]
# Instantiate some tally Filters
energy_filter = openmc.EnergyFilter([0., 4.e-6, 20.])
mesh_filter = openmc.MeshFilter(mesh.id)
mesh_filter.mesh = mesh
mesh_filter = openmc.MeshFilter(mesh)
# Instantiate the Tally
tally = openmc.Tally(tally_id=1, name='tally 1')

View file

@ -155,8 +155,7 @@ mesh.upper_right = [0.63, 0.63, 1.e50]
# Instantiate some tally Filters
energy_filter = openmc.EnergyFilter([1E-11, 0.0635E-6, 10.0E-6, 1.0E-4, 1.0E-3,
0.5, 1.0, 20.0])
mesh_filter = openmc.MeshFilter(mesh.id)
mesh_filter.mesh = mesh
mesh_filter = openmc.MeshFilter(mesh)
# Instantiate the Tally
tally = openmc.Tally(tally_id=1, name='tally 1')

View file

@ -38,7 +38,7 @@ class FilterMeta(ABCMeta):
class Filter(with_metaclass(FilterMeta, object)):
"""A constraint on transport events that can score a tally.
"""Tally modifier that describes phase-space and other characteristics.
Parameters
----------
@ -107,7 +107,7 @@ class Filter(with_metaclass(FilterMeta, object)):
return subs + subsubs
@classmethod
def from_hdf5(cls, group):
def from_hdf5(cls, group, **kwargs):
"""Construct a new Filter instance from HDF5 data.
Parameters
@ -115,16 +115,26 @@ class Filter(with_metaclass(FilterMeta, object)):
group : h5py.Group
HDF5 group to read from
Keyword arguments
-----------------
meshes : dict
Dictionary mapping integer IDs to openmc.Mesh objects. Only used
for openmc.MeshFilter objects.
"""
# If the HDF5 'type' variable matches this class's short_name, then
# there is no overriden from_hdf5 method. Pass the bins to __init__.
if group['type'].value.decode() == cls.short_name.lower():
out = cls(group['bins'].value)
out.num_bins = group['n_bins'].value
return out
# Search through all subclasses and find the one matching the HDF5
# 'type'. Call that class's from_hdf5 method.
for subclass in cls.recursive_subclasses():
if group['type'].value.decode() == subclass.short_name.lower():
return subclass.from_hdf5(group)
return subclass.from_hdf5(group, **kwargs)
raise ValueError("Unrecognized Filter class: '"
+ group['type'].value.decode() + "'")
@ -447,9 +457,48 @@ class SurfaceFilter(IntegralFilter):
class MeshFilter(Filter):
def __init__(self, bins):
self._mesh = None
super(MeshFilter, self).__init__(bins)
"""Bins tally event locations onto a regular, rectangular mesh.
Parameters
----------
mesh : openmc.Mesh
The Mesh object that events will be tallied onto
Attributes
----------
bins : Integral
The Mesh ID
mesh : openmc.Mesh
The Mesh object that events will be tallied onto
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
def __init__(self, mesh):
self.mesh = mesh
super(MeshFilter, self).__init__(mesh.id)
@classmethod
def from_hdf5(cls, group, **kwargs):
if group['type'].value.decode() != cls.short_name.lower():
raise ValueError("Expected HDF5 data for filter type '"
+ cls.short_name.lower() + "' but got '"
+ group['type'].value.decode() + " instead")
if not 'meshes' in kwargs:
raise ValueError(cls.__name__ + " requires a 'meshes' keyword "
"argument.")
mesh_id = group['bins'].value
mesh_obj = kwargs['meshes'][mesh_id]
out = cls(mesh_obj)
out.num_bins = group['n_bins'].value
return out
@property
def mesh(self):
@ -706,7 +755,7 @@ class DistribcellFilter(Filter):
super(DistribcellFilter, self).__init__(bins)
@classmethod
def from_hdf5(cls, group):
def from_hdf5(cls, group, **kwargs):
if group['type'].value.decode() != cls.short_name.lower():
raise ValueError("Expected HDF5 data for filter type '"
+ cls.short_name.lower() + "' but got '"

View file

@ -271,11 +271,10 @@ class MGXS(object):
# Create a domain Filter object
filter_type = _DOMAIN_TO_FILTER[self.domain_type]
domain_filter = filter_type(self.domain.id)
# If a mesh domain, give the mesh to the domain filter
if self.domain_type == 'mesh':
domain_filter.mesh = self.domain
domain_filter = filter_type(self.domain)
else:
domain_filter = filter_type(self.domain.id)
# Create each Tally needed to compute the multi group cross section
tally_metadata = zip(self.scores, self.tally_keys, self.filters)

View file

@ -408,12 +408,8 @@ class StatePoint(object):
# Read all filters
for j in range(1, n_filters+1):
subsubbase = '{0}{1}'.format(subbase, j)
new_filter = openmc.Filter.from_hdf5(self._f[subsubbase])
if isinstance(new_filter, openmc.MeshFilter):
mesh_ids = self._f['tallies/meshes/ids'].value
mesh_keys = self._f['tallies/meshes/keys'].value
key = mesh_keys[mesh_ids == new_filter.bins[0]][0]
new_filter.mesh = self.meshes[key]
new_filter = openmc.Filter.from_hdf5(self._f[subsubbase],
meshes=self.meshes)
tally.filters.append(new_filter)
# Read Nuclide bins

View file

@ -418,7 +418,7 @@ contains
call write_dataset(filter_group, "type", "mesh")
call write_dataset(filter_group, "n_bins", this % n_bins)
call write_dataset(filter_group, "bins", this % mesh )
call write_dataset(filter_group, "bins", meshes(this % mesh) % id)
end subroutine to_statepoint_mesh
function text_label_mesh(this, bin) result(label)

View file

@ -38,12 +38,9 @@ class FilterMeshTestHarness(HashedPyAPITestHarness):
mesh_3d.upper_right = [182.07, 182.07, 183.00]
# Initialize the filters
mesh_1d_filter = openmc.MeshFilter(mesh_1d.id)
mesh_2d_filter = openmc.MeshFilter(mesh_2d.id)
mesh_3d_filter = openmc.MeshFilter(mesh_3d.id)
mesh_1d_filter.mesh = mesh_1d
mesh_2d_filter.mesh = mesh_2d
mesh_3d_filter.mesh = mesh_3d
mesh_1d_filter = openmc.MeshFilter(mesh_1d)
mesh_2d_filter = openmc.MeshFilter(mesh_2d)
mesh_3d_filter = openmc.MeshFilter(mesh_3d)
# Initialized the tallies
tally = openmc.Tally(name='tally 1')

View file

@ -19,8 +19,7 @@ class MGTalliesTestHarness(PyAPITestHarness):
# Instantiate some tally filters
energy_filter = openmc.EnergyFilter([0.0, 20.0])
energyout_filter = openmc.EnergyoutFilter([0.0, 20.0])
mesh_filter = openmc.MeshFilter(mesh.id)
mesh_filter.mesh = mesh
mesh_filter = openmc.MeshFilter(mesh)
mat_filter = openmc.MaterialFilter([1,2,3])

View file

@ -43,8 +43,7 @@ class TalliesTestHarness(PyAPITestHarness):
mesh_2x2.lower_left = [-182.07, -182.07]
mesh_2x2.upper_right = [182.07, 182.07]
mesh_2x2.dimension = [2, 2]
mesh_filter = MeshFilter(mesh_2x2.id)
mesh_filter.mesh = mesh_2x2
mesh_filter = MeshFilter(mesh_2x2)
azimuthal_tally4 = Tally()
azimuthal_tally4.filters = [azimuthal_filter2, mesh_filter]
azimuthal_tally4.scores = ['flux']

View file

@ -34,8 +34,7 @@ class TallyArithmeticTestHarness(PyAPITestHarness):
energy_filter = openmc.EnergyFilter((0.0, 0.253e-6, 1.0e-3, 1.0, 20.0))
material_filter = openmc.MaterialFilter((1, 3))
distrib_filter = openmc.DistribcellFilter(60)
mesh_filter = openmc.MeshFilter(mesh.id)
mesh_filter.mesh = mesh
mesh_filter = openmc.MeshFilter(mesh)
# Initialized the tallies
tally = openmc.Tally(name='tally 1')

View file

@ -40,8 +40,7 @@ class TallySliceMergeTestHarness(PyAPITestHarness):
mesh.dimension = [2, 2]
mesh.lower_left = [-50., -50.]
mesh.upper_right = [+50., +50.]
mesh_filter = openmc.MeshFilter(mesh.id)
mesh_filter.mesh = mesh
mesh_filter = openmc.MeshFilter(mesh)
self.cell_filters = [cell_21, cell_27]
self.energy_filters = [low_energy, high_energy]