mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Now only store StatePoint filename string in Tally class
This commit is contained in:
parent
32946edecb
commit
50e006dea9
2 changed files with 22 additions and 9 deletions
|
|
@ -358,7 +358,7 @@ class StatePoint(object):
|
|||
|
||||
# Create Tally object and assign basic properties
|
||||
tally = openmc.Tally(tally_id=tally_key)
|
||||
tally._statepoint = self
|
||||
tally._sp_filename = self._f.filename
|
||||
tally.estimator = self._f['{0}{1}/estimator'.format(
|
||||
base, tally_key)].value.decode()
|
||||
tally.num_realizations = n_realizations
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from xml.etree import ElementTree as ET
|
|||
import sys
|
||||
|
||||
import numpy as np
|
||||
import h5py
|
||||
|
||||
from openmc import Mesh, Filter, Trigger, Nuclide
|
||||
from openmc.cross import CrossScore, CrossNuclide, CrossFilter
|
||||
|
|
@ -103,7 +104,7 @@ class Tally(object):
|
|||
self._with_batch_statistics = False
|
||||
self._derived = False
|
||||
|
||||
self._statepoint = None
|
||||
self._sp_filename = None
|
||||
self._results_read = False
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
|
|
@ -124,7 +125,7 @@ class Tally(object):
|
|||
clone._with_summary = self.with_summary
|
||||
clone._with_batch_statistics = self.with_batch_statistics
|
||||
clone._derived = self.derived
|
||||
clone._statepoint = self._statepoint
|
||||
clone._sp_filename = self._sp_filename
|
||||
clone._results_read = self._results_read
|
||||
|
||||
clone._filters = []
|
||||
|
|
@ -264,12 +265,16 @@ class Tally(object):
|
|||
|
||||
@property
|
||||
def sum(self):
|
||||
if not self._statepoint:
|
||||
if not self._sp_filename:
|
||||
return None
|
||||
|
||||
if not self._results_read:
|
||||
|
||||
# Open the HDF5 statepoint file
|
||||
f = h5py.File(self._sp_filename, 'r')
|
||||
|
||||
# Extract Tally data from the file
|
||||
data = self._statepoint._f['tallies/tally {0}/results'.format(
|
||||
data = f['tallies/tally {0}/results'.format(
|
||||
self.id)].value
|
||||
sum = data['sum']
|
||||
sum_sq = data['sum_sq']
|
||||
|
|
@ -293,11 +298,14 @@ class Tally(object):
|
|||
# Indicate that Tally results have been read
|
||||
self._results_read = True
|
||||
|
||||
# Close the HDF5 statepoint file
|
||||
f.close()
|
||||
|
||||
return self._sum
|
||||
|
||||
@property
|
||||
def sum_sq(self):
|
||||
if not self._statepoint:
|
||||
if not self._sp_filename:
|
||||
return None
|
||||
|
||||
if not self._results_read:
|
||||
|
|
@ -309,7 +317,7 @@ class Tally(object):
|
|||
@property
|
||||
def mean(self):
|
||||
if self._mean is None:
|
||||
if not self._statepoint:
|
||||
if not self._sp_filename:
|
||||
return None
|
||||
|
||||
self._mean = self.sum / self.num_realizations
|
||||
|
|
@ -318,7 +326,7 @@ class Tally(object):
|
|||
@property
|
||||
def std_dev(self):
|
||||
if self._std_dev is None:
|
||||
if not self._statepoint:
|
||||
if not self._sp_filename:
|
||||
return None
|
||||
|
||||
n = self.num_realizations
|
||||
|
|
@ -426,8 +434,13 @@ class Tally(object):
|
|||
# If the score is already in the Tally, don't add it again
|
||||
if score in self.scores:
|
||||
return
|
||||
else:
|
||||
|
||||
# Normal score strings
|
||||
if isinstance(score, basestring):
|
||||
self._scores.append(score.strip())
|
||||
# CrossScores
|
||||
else:
|
||||
self._scores.append(score)
|
||||
|
||||
@num_score_bins.setter
|
||||
def num_score_bins(self, num_score_bins):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue